ryankurte / docker-rpi-emu

QEMU and helper scripts in a docker container for emulating a raspberry pi environment
MIT License
109 stars 34 forks source link

Failed to launch the emulated environment: chroot: failed to run command 'bin/bash': Exec format error #6

Closed andreacortis closed 8 years ago

andreacortis commented 8 years ago

I am having an issue with launching the emulated CLI. Could you please advise?

Thanks

Andrea

C02PW287G8WP:docker-rpi-emu andreacortis$ ls -al
total 64
drwxr-xr-x  13 andreacortis  staff   442 Aug 29 10:34 .
drwxr-xr-x  22 andreacortis  staff   748 Aug 29 09:33 ..
-rw-r--r--   1 andreacortis  staff    13 Aug 29 09:33 .dockerignore
drwxr-xr-x  13 andreacortis  staff   442 Aug 29 09:33 .git
-rw-r--r--   1 andreacortis  staff    18 Aug 29 09:33 .gitignore
-rw-r--r--   1 andreacortis  staff   205 Aug 29 09:33 .travis.yml
-rw-r--r--   1 andreacortis  staff   499 Aug 29 09:33 Dockerfile
-rw-r--r--   1 andreacortis  staff  1075 Aug 29 09:33 LICENSE.md
-rw-r--r--   1 andreacortis  staff  1920 Aug 29 09:33 Makefile
-rw-r--r--   1 andreacortis  staff  2182 Aug 29 09:33 Makefile.example
-rw-r--r--   1 andreacortis  staff  3958 Aug 29 09:33 README.md
drwxr-xr-x   4 andreacortis  staff   136 Aug 29 09:47 images
drwxr-xr-x   9 andreacortis  staff   306 Aug 29 09:33 scripts

C02PW287G8WP:docker-rpi-emu andreacortis$ make run-emu
Building base docker image
Sending build context to Docker daemon 452.6 kB
Step 1 : FROM ubuntu
 ---> bd3d4369aebc
Step 2 : MAINTAINER Ryan Kurte <ryankurte@gmail.com>
 ---> Using cache
 ---> 0197a892a4eb
Step 3 : LABEL Description "Qemu based emulation for raspberry pi using loopback images"
 ---> Using cache
 ---> 81e0d0be7787
Step 4 : RUN apt-get update
 ---> Using cache
 ---> 529db456397e
Step 5 : RUN apt-get install -y --allow-unauthenticated     qemu     qemu-user-static     binfmt-support     parted     vim
 ---> Using cache
 ---> eddbf8a1ee24
Step 6 : RUN apt-get clean
 ---> Using cache
 ---> 1f21c2566d2d
Step 7 : RUN rm -rf /var/lib/apt
 ---> Using cache
 ---> 900cff98a367
Step 8 : RUN mkdir -p /usr/rpi
 ---> Using cache
 ---> f872305d93d6
Step 9 : WORKDIR /usr/rpi
 ---> Using cache
 ---> 14ddc705be33
Step 10 : COPY scripts/* /usr/rpi/
 ---> Using cache
 ---> f3e80969b2dc
Successfully built f3e80969b2dc
Launching interactive emulated session
Attempting to mount images/2016-05-27-raspbian-jessie-lite.img to /media/rpi
Attached base loopback at: /dev/loop0
Located partitions: p1 (/boot) at 8192 and p2 (/) at 137216
Closed loopback /dev/loop0
Mounted to /media/rpi and /media/rpi/boot
Bootstrapping Qemu
chroot: failed to run command 'bin/bash': Exec format error
make: *** [run-emu] Error 126
ryankurte commented 8 years ago

Hey, do you have qemu and qemu-user-static installed on your host? I haven't worked out why it is required yet, but that is the same error that I get without.

andreacortis commented 8 years ago

My host is:

Darwin C02PW287G8WP 15.6.0 Darwin Kernel Version 15.6.0: Thu Jun 23 18:25:34 PDT 2016; root:xnu-3248.60.10~1/RELEASE_X86_64 x86_64

I have installed qemu and now I can run the run-emu script, but I cannot find qemu-static-user:

C02PW287G8WP:docker-rpi-emu andreacortis$  brew search qemu
qemu ✔

so now I get errors when I am actually inside the emulated environment:

C02PW287G8WP:docker-rpi-emu andreacortis$ make run-emu
[....]
Launching interactive emulated session
Attempting to mount images/2016-05-27-raspbian-jessie-lite.img to /media/rpi
Attached base loopback at: /dev/loop2
Located partitions: p1 (/boot) at 8192 and p2 (/) at 137216
Closed loopback /dev/loop2
Mounted to /media/rpi and /media/rpi/boot
Bootstrapping Qemu
root@50758288b86d:/# ls
bash: /bin/ls: cannot execute binary file: Exec format error
root@50758288b86d:/# 

Assuming that this is my problem, any suggestions on how to install qemu-user-static on osx?

ryankurte commented 8 years ago

Hmm, are you running Docker for Mac or using Kitematic (or some other approach)?

On 30 August 2016 at 10:46, Andrea Cortis notifications@github.com wrote:

My host is:

Darwin C02PW287G8WP 15.6.0 Darwin Kernel Version 15.6.0: Thu Jun 23 18:25:34 PDT 2016; root:xnu-3248.60.10~1/RELEASE_X86_64 x86_64

I have installed qemu and now I can run the run-emu script, but I cannot find qemu-static-user:

C02PW287G8WP:docker-rpi-emu andreacortis$ brew search qemu qemu ✔

so now I get errors when I am actually inside the emulated environment:

C02PW287G8WP:docker-rpi-emu andreacortis$ make run-emu [....] Launching interactive emulated session Attempting to mount images/2016-05-27-raspbian-jessie-lite.img to /media/rpi Attached base loopback at: /dev/loop2 Located partitions: p1 (/boot) at 8192 and p2 (/) at 137216 Closed loopback /dev/loop2 Mounted to /media/rpi and /media/rpi/boot Bootstrapping Qemu root@50758288b86d:/# ls bash: /bin/ls: cannot execute binary file: Exec format error root@50758288b86d:/#

Assuming that this is my problem, any suggestions on how to install qemu-user-static on osx?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ryankurte/docker-rpi-emu/issues/6#issuecomment-243280787, or mute the thread https://github.com/notifications/unsubscribe-auth/AA0hzDcbHawH8QsZ58wAwktXK_oaVED9ks5qk2FWgaJpZM4Jvmvu .

andreacortis commented 8 years ago

I am running docker for Mac

C02PW287G8WP:~ andreacortis$ docker -v
Docker version 1.12.0, build 8eab29e

Running the daemon

C02PW287G8WP:~ andreacortis$ docker-machine restart default
Restarting "default"...
(default) Check network to re-create if needed...
(default) Waiting for an IP...
Waiting for SSH to be available...
Detecting the provisioner...
Restarted machines may have new IP addresses. You may need to re-run the `docker-machine env` command.
C02PW287G8WP:~ andreacortis$ docker-machine env
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/andreacortis/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell: 
# eval $(docker-machine env)
C02PW287G8WP:~ andreacortis$ eval $(docker-machine env)
C02PW287G8WP:~ andreacortis$ 
ryankurte commented 8 years ago

So the problem might be that docker runs in another host on OSX. I don't think qemu is required on the OSX machine, but it is required on whatever is running the docker environment.

With the Docker for Mac application I don't think you should have to (or be able to) use docker-machine to control the docker host, and the instance they spin up works with qemu on the couple of OSX machines I have tested.

It might be worth checking what is going on there (docker icon in top bar, definitely running, nothing running in docker-machine docker-machine ls). Other options are to try installing qemu-user-static in the docker-machine (not sure what the os is, but docker-machine ssh should get you in, or to mod the scripts to run from OSX.

andreacortis commented 8 years ago

I have reinstalled Docker with Docker for Mac. And now the issue I originally reported is resolved.

There is however still something that I do not understand (please tell me if you want me to open another issue). I cannot get an IP address in the emulated session (see below). Is that normal?

C02PW287G8WP:docker-rpi-emu andreacortis$ make run
[...]
root@41f78f4b8763:/usr/rpi# hostname -I
172.17.0.2 
C02PW287G8WP:docker-rpi-emu andreacortis$ make run-emu
[...]
root@52ae8506b401:/# hostname -I
hostname: Address family not supported by protocol
ryankurte commented 8 years ago

Good good ^_^

That is normal. Qemu isn't actually running the whole OS, only interpreting the binaries you call in the container. If you want to connect to it (ie. you are running a web server in the emulated environment) use the address of the docker host as above, and outbound things should /just work/ via the container.