dimanche 10 juillet 2016

damn you prolog, I mean damn you university

Everybody should learn prolog. It's such a wonderful piece of idea.

If you express a graph as:

transition(S, a, T)
transition(S, b, U)
transition(T, 0, V)
transition(U, 0, K)
transition(T, c, K)
transition(U, a, U)

mark a special node as an accepting state

accept(c, K)

then validating input is only:

validate(S, [I|IS]) :-
validate(S, [I|IS]) :-

how daming is that.

dimanche 22 mai 2016

Programmation par l'exemple en Caml par Louis Gacôgne - 25 euros merveilleusements depenses

Pour ceux qui ont deja des bases en programmation, et en programmation fonctionnelle, ce petit manuel est une mine d'exercises aussi concis que generaux.

arbres, reines, graphes, hasard, lambda calcul, derivation symbolique, jamais trop de details, jamais pompeux ni trop succint... genial


mardi 3 mai 2016

local ssh neighbors ?

A little bash function leveraging nmap .. mostly naive and fragile.
Until I learn how to do tcp|ip discovery.

neigh_ssh ()
    sudo nmap -v -p 22 --open --host-timeout 1 \
  | grep --color=auto -E -o "open port 22.*[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" \
  | grep --color=auto -E -o "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" \
  | sort \
  | uniq

dimanche 1 mai 2016

systemd-nspawn and noexec flag

Trying to create customized archlinux iso (archiso, releng) I hit a lot of issues, most of them 'execv? failed, permission denied'.

Later on, just trying to run a systemd-nspawn container, again, execv permission. Boot fails.

Googling didn't get me very far, except to broaden the scope from systemd-nspawn to something more general. I try to run a binary (ls) from the container subtree. Permission denied. I md5sum container/.../ls and get the same md5 as the main linux install I'm running. I thought it could be the wrong architecture or a different binary. So if two binaries refuse to run .. maybe they're treated differently from the host OS. I then realize that my container and custom archiso were on a mounted drive.

mount | grep <mountpoint> -&gt; mount .... (...,noexec, ...)


udevil mounts this drive with a lot of protective flags. udevil unmount <mountpoint>; sudo mount <device> /mnt; <container>/ ... /ls works.

systemd-nspawn -b -D <container> works.

Thanks to #archlinux for nothing (beside rubber ducking ;)</container></container></device></mountpoint></mountpoint>

vendredi 22 avril 2016

mtp under [arch]linux: mtpfs vs gvfs-mtp [mount update]

Wanted to copy some file from a Moto G to my laptop. Installed mtpfs. Mounting took minutes and failed. As a last hope I tried gvfs-mtp. I don't know how to use the gvfs-* CLI though. But it's supposed to work out of the box in GTK apps. So Chromium + Ctrl-O. I can see the smartphone listed. Walk through the phone FS. It's instantaneous, snappy as I like it. But what about the CLI ?

Well gvfs-info says nothing. There's gvfs-mount, which says nothing. gvfs-mount --list outputs the mounted drives on this machine. And the last one is mtp://[usb:005,009]/ ... Hmm maybe gvfs-ls takes an URI ?

$ gvfs-ls mtp:/// # Error: The specified location is not mounted
$ gvfs-ls mtp://  # Error: The specified location is not mounted
$ gvfs-ls mtp:///sdcard # same as above

could the [usb:...] be mandatory ? odd syntax but alas

$ gvfs-ls mtp://[usb:005,009]/
Internal Storage # yay

$ gvfs-tree mtp://[usb:005,009]/ | head -n 32
`-- Internal Storage
    |-- .CM_Cloud
    |   |-- cm
    |   |   |-- cm_cloud_sdk_expand.db
    |   |   `-- cm_cloud_sdk_expand.db-journal
    |   `-- cmqp
    |       |-- cm_cloud_sdk_expand.db
    |       `-- cm_cloud_sdk_expand.db-journal
    |-- .DataStorage
    |   `-- ContextData.xml
    |-- .UTSystemConfig
    |   `-- Global
    |       `-- Alvin2.xml
    |-- .com.zwsoft.zwcad
    |   |-- local_Thumb
    |   |   |-- Fonts
    |   |   `-- Sample Drawings
    |   |       |-- Villa.dwg.png
    |   |       |-- ar_house_2.dwg.png
    |   |       |-- crane.dwg.png
    |   |       `-- l_1a.dwg.png
    |   |-- resources
    |   |   |-- adinit.dat
    |   |   |-- arialuni.ttf
    |   |   |-- plotstyle
    |   |   |   |-- Icad.ctb
    |   |   |   |-- Monochrome.ctb
    |   |   |   |-- zwcad-Color.stb
    |   |   |   |-- zwcad.ctb
    |   |   |   `-- zwcad.stb
    |   |   |-- zwcad.dwt

Didn't try to copy anything yet, I guess it won't be worse than doing a full http roundtrip over wifi as I did before.

ps: there was a side effect of trying gvfs through GTK file open dialog. It mounted the volume on click. Thus the ability to use gvfs-* afterwards.

So there's a few things to do in cli beforehand.

source: http://stackoverflow.com/questions/483460/how-to-mount-from-command-line-like-the-nautilus-does

$ gvfs-mount --list
Volume(0): XT1032
  Type: GProxyVolume (GProxyVolumeMonitorMTP)

This shows XT1032 (Moto G) is detected but not mounted. What we want is the following:

$ gvfs-mount --list
Volume(0): XT1032
  Type: GProxyVolume (GProxyVolumeMonitorMTP)
  Mount(0): XT1032 -&gt; mtp://[usb:005,013]/
    Type: GProxyShadowMount (GProxyVolumeMonitorMTP)
Mount(1): mtp -&gt; mtp://[usb:005,013]/
  Type: GDaemonMount

Usually to mount a 'storage' device, one uses /dev/sd*. But there's no sd* node for the XT1032.
gvfs-mount --list --info lists a bit more info (sic) (errata: --list -i)

$ Volume(0): XT1032
  Type: GProxyVolume (GProxyVolumeMonitorMTP)
   unix-device: '/dev/bus/usb/005/013'
  themed icons:  [phone]
  symbolic themed icons:  [phone-symbolic]  [phone]

And trying with the /dev/bus/... path

$ gvfs-mount -d /dev/bus/usb/005/013
Mounted /dev/bus/usb/005/013 at /run/user/1000/gvfs/mtp:host=%5Busb%3A005%2C013%5D

$ gvfs-ls mtp://[usb:005,013]/                                                                                                                  
Internal Storage

# yay

mercredi 20 avril 2016

usb key replicate

* usb key duplicate

* partition table

  manual cgdisk

* rsync partitions

  rsync -auv --progress <source></source> <target>

* rsync caveat : hard links, sparse file

  warning: some sparse files may have huge virtual size
    rsync, will attempt to expand them fully
    i.e: docker devicemapper (60MB on disk, virtually 100G)

  warning: some programs have one fat binary with hard links
    rsync, will attempt to copy them fully
    i.e: git, which has 114 hard links with different names

* BIOS boot (ef02) partition

  dd if=/dev/sdX1 of=/dev/sdY1 bs=1M # simply

* grub

  sudo grub-install --target=i386-pc --debug --boot-directory=/<root-mountpoint>/boot/ /dev/sdY

  warning: do not mess the device names and mountpoint names as it may modify your host system grub config

* grub UUID

  grub menuentry refers to source key UUID

* adjust root UUIDs
  /etc/fstab still refers to source key UUID

  blkid /dev/sdX? &gt;&gt; /etc/fstab
  vi /etc/fstab

  (some sed-fu would be nice)</root-mountpoint></target>

mardi 5 avril 2016

nixos 16.03 live iso boot "directly" from grub

I hate extracting iso images. I prefer to run them through grub loopback. Nixos 16.03 release is a few days old, I couldn't resist. Alas, booting it this way drops me in a rescue shell.

The initrd is set up to only have one layer of virtual fs. So it assumes the squashfs nix-store would be in /mnt-root/iso and complains since it is not.

So after trying to MITM myself and mount the desired FS where they should be, I replicate the final steps of the nixos initrd init script. Kernel panic.

I'm dumbfounded, I need to be more thorough. The init scripts reads a fsinfo file (fstab-like in a different format say) to prepare the new root for the real stage 2 kernel.

btw, my mistake was to simply mount the nix-store squashfs file in /mnt-root/nix/.ro-store and then symlink /mnt-root/nix/store to it. It works only partially as the stage2 kernel find its init and proceed to run systemd but hangs after a few services doing nothing. Only option: CTRL-ALT-DEL. (I even tried to instrument stage2 systemd into booting the rescue target, hoping for a rescue shell to investigate the hang .. no luck). Then I realize that the fsinfo mounts the squashfs in nix/.ro-store BUT, also prepares a unionfs in nix/store ! Maybe stage2 is waiting for a unionfs mount in nix/store and my symlink is confusing things up.

So I insert the missing layer in there. And just sh /init. It fails horribly saying 'cannot stop udev/queue' then 'Killed'. Not thrilled.

I extract the final steps of the init script (populate /mnt-root with proc,sys,run,dev; kill a few things; restore the path for `modprobe` in the new /proc/sys/kernel/modprobe value). And then exec switch_root ...

I can now enjoy nixos 16.03 live booting directly from grub. If you allow directly to allow user intervention .. heh.