djmaze / armhf-ubuntu-docker

Ubuntu-Core images for armhf (ARMv7+) devices
59 stars 16 forks source link

Can't run on boot2docker #3

Closed DanLipsitt closed 9 years ago

DanLipsitt commented 9 years ago

This might not be a bug in the armhf-ubuntu-docker image, but maybe you will have some insight into what is going wrong.

Error

I'm running boot2docker 1.4.1 on MacOS. I installed qemu-arm in the boot2docker VM (procedure below). I am able to run a static arm binary, but not armhf docker images. Here's the error I get:

$ docker run --rm -ti mazzolino/armhf-ubuntu bash
exec format errorFATA[0000] Error response from daemon: Cannot start container a3e8c5fc2193125a928f469227637cc465c387ce3d6652f0341fc24591b011ed: exec format error

boot2docker VM Setup

Install qemu arm:

tce-load -wi qemu-arm

Mount the binfmt_misc pseudofilesystem:

sudo mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc

Register the arm binary format:

echo ":arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-arm:" > /proc/sys/fs/binfmt_misc/register

After this I am able to run a random arm static binary I downloaded (netkitty) inside the VM, so it seems like binfmt_misc is working.

djmaze commented 9 years ago

Just tried running ldd /usr/local/bin/qemu-arm inside a B2D VM after installing the package. The qemu-arm binary is not statically compiled and needs additional libraries to be available inside the container.

You should use the qemu-arm-static binary instead. I just created a Docker image so you can just run the following to get the executable in your B2D VM:

docker run --rm mazzolino/qemu-arm-static >/usr/local/bin/qemu-arm-static
chmod u+x /usr/local/bin/qemu-arm-static
DanLipsitt commented 9 years ago

Hi, I'm back to playing with this again after working on some other stuff. Here's what's happening now:

$ docker run -ti --name arm mazzolino/armhf-ubuntu bash
no such file or directoryFATA[0000] Error response from daemon: Cannot start container 710ea8baa1aef0706bd027d2f239cd52eb5793e01197a3f3e70046653859fe71: no such file or directory 
$ docker ps -l
CONTAINER ID        IMAGE                          COMMAND             CREATED             STATUS              PORTS               NAMES
710ea8baa1ae        mazzolino/armhf-ubuntu:14.04   "bash"              8 seconds ago                                               arm                 
$ docker start arm
Error response from daemon: Cannot start container arm: no such file or directory
FATA[0000] Error: failed to start one or more containers 
$ docker start 710ea8baa1ae
Error response from daemon: Cannot start container 710ea8baa1ae: no such file or directory
FATA[0000] Error: failed to start one or more containers 

So it seems to create a container and then immediately not be able to find it. Weird, huh?

djmaze commented 9 years ago

Ok, I mixed it up. The qemu-arm-static binary is only needed inside the container, so you need not install it in the VM separately. The path given in the binfmt register call must match the path to the binary inside the container. So it must to be set to /usr/bin/qemu-arm-static:

sudo sh -c 'echo ":arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:" >/proc/sys/fs/binfmt_misc/register'

Does it work for you if you change that? (Run sudo sh -c 'echo -1 >/sys/fs/binfmt_misc/arm' to remove the old configuration first.)

DanLipsitt commented 9 years ago

Looks like it's working. Thanks! The command to remove the old config was missing a directory. It should be

sudo sh -c 'echo -1 > /proc/sys/fs/binfmt_misc/arm'