|
Size: 4723
Comment: added category emdebian
|
Size: 5316
Comment: Updated with latest patches
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 3: | Line 3: |
| This page describes how to setup and use QEMU user emulation in a "transparent" fashion, allowing to run non-native target executables just like native ones ({{{./program}}}). | This page describes how to setup and use QEMU user emulation in a "transparent" fashion, allowing execution of non-native target executables just like native ones (i.e. {{{./program}}}). |
| Line 7: | Line 7: |
| '''Note:''' this text depends on features that are not available in official Debian qemu package as of 2006-03-07. See [http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=306637 this bug report] for details. | '''Note:''' this text depends on features that are not available in official Debian qemu package as of 2006-10-29. Here is the current summary of the bugs related to this feature: |
| Line 9: | Line 9: |
| '''Note''' this setup is incompatible with Scratchbox (both use the binfmt_misc module to register the same binaries), so it's recommended to remove [http://www.scratchbox.org Scratchbox] (or stop its init script) before continuing. | || '''Bug #''' || '''Description''' ||'''Status''' || || [http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=384338 #384338] || Add "qemu-user-static" package || patch available || || [http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=306637 #306637] || Add "qemu-binfmt" package || patch available || |
| Line 11: | Line 13: |
| === Requirements === | '''Note''' this setup is incompatible with [http://www.scratchbox.org Scratchbox] (both use the binfmt_misc module to register the same formats), so it's recommended to remove it (or stop its init script) before continuing. |
| Line 13: | Line 15: |
| You need the following packages to use transparent QEMU user emulation: | === Building qemu === |
| Line 15: | Line 17: |
| * binfmt-support * qemu (0.8.0-2 + patch from bug report above) * qemu-user-static (if you want to chroot into target filesystems) * dpkg-cross (>= 1.26) |
1. Download and unpack qemu sources: {{{ apt-get source qemu dpkg-source -x *.dsc }}} |
| Line 20: | Line 22: |
| === Installing binfmt-support === | 1. Apply the following patches to the source, in order: * [http://bugs.debian.org/cgi-bin/bugreport.cgi/qemu_0.8.2-1_clean_build.patch?bug=390166;msg=5;att=1 qemu_0.8.2-1_clean_build.patch] * [http://bugs.debian.org/cgi-bin/bugreport.cgi/qemu_0.8.2-1_binfmt-5.patch?bug=306637;msg=66;att=1 qemu_0.8.2-1_binfmt-5.patch] * [http://bugs.debian.org/cgi-bin/bugreport.cgi/qemu_0.8.2-1_user_static.patch?bug=384338;msg=10;att=1 qemu_0.8.2-1_user_static.patch] 1. Build the package as usual: {{{ dpkg-buildpackage -rfakeroot }}} This will generate 3 packages: qemu, qemu-binfmt and qemu-user-static. The latter is only required if you want to chroot into non-native root file systems (see "Appendix: chrooting into target filesystems" below). === Installing packages === |
| Line 24: | Line 37: |
| 1. Install the binfmt-support package (used by qemu to register the supported binary formats): {{{ # apt-get install binfmt-support |
1. Install qemu, binfmt-support and qemu-binfmt: {{{ # apt-get install qemu binfmt-support # dpkg -i qemu-binfmt*.deb |
| Line 32: | Line 46: |
| The last command should print entries for each supported target user emulator, except for the host system. === Installing QEMU === Finally, install the qemu package: {{{ # apt-get install qemu }}} There is also a qemu-user-static package that contains statically linked versions of the user mode emulators. Install it if you want to chroot into target filesystems (see Appendix below). |
This command should print entries for each supported target user emulator, except for the host system. |
| Line 44: | Line 50: |
| With the instructions above, you should be able to run statically linked target executables. To be able to run dynamically linked binaries, QEMU needs to have access to the target ELF interpreter. For convenience, the default search path for the ELF interpreter was setup to the same directory used by dpkg-cross for installing converted target packages for cross-compilation. | With the instructions above, you should be able to run statically linked target executables. To be able to run dynamically linked binaries, QEMU needs to have access to the target ELF interpreter. |
| Line 57: | Line 63: |
| # wget http://ftp.debian.org/debian/pool/main/g/glibc/libc6_2.3.6-2_arm.deb # dpkg-cross -i -a arm libc6_2.3.6-2_arm.deb |
# dpkg-cross -i -a arm libc6_<version>_arm.deb }}} Alternatively, you can install the libc6-dev-arm-cross package from [http://www.emdebian.org/ EmDebian]: {{{ # wget http://www.emdebian.org/debian/pool/cross-unstable/g/glibc/libc6-dev-arm-cross_2.3.6.ds1-6_all.deb # dpkg -i libc6-dev-arm-cross_2.3.6.ds1-6_all.deb |
| Line 65: | Line 75: |
| 1. Download the hello package (e.g. from http://http.us.debian.org/debian/pool/main/h/hello/hello_2.1.1-4_arm.deb). |
1. Download the hello package (e.g. from http://http.us.debian.org/debian/pool/main/h/hello/hello_2.1.1-5_arm.deb) |
| Line 69: | Line 78: |
| $ dpkg -x hello_2.1.1-4_arm.deb /tmp/hello_arm | $ dpkg -x hello_2.1.1-5_arm.deb /tmp/hello_arm |
| Line 80: | Line 89: |
| === Appendix: chrooting into target filesystems === | === Appendix: chrooting into target file systems === |
| Line 82: | Line 91: |
| To be able to chroot into a target filesystem, the qemu emulator for the target CPU needs to be accessible from inside the chroot jail. For this to work, you need first to install the qemu-user-static package: {{{ # apt-get install qemu-user-static |
To be able to chroot into a target file system, the qemu emulator for the target CPU needs to be accessible from inside the chroot jail. For this to work, you need first to install the qemu-user-static package (compiled above): {{{ # dpkg -i qemu-user-static*.deb |
| Line 88: | Line 97: |
| '''Note:''' you still need to install "qemu", as it registers the binfmt formats with the kernel. Next, copy the the relevant emulator to the ''same path as registered by binfmt-support''. For example, for an ARM target filesystem, you need to do the following:{{{ # cp /usr/bin/qemu-arm-static /target_fs/usr/bin/qemu-arm |
Next, copy the emulator for the target architecture to the path registered by binfmt-support. For example, for an ARM target file system, you need to do the following:{{{ # mkdir -p /target_fs/usr/lib/qemu-binfmt # cp /usr/bin/qemu-arm-static /target_fs/usr/lib/qemu-binfmt/arm |
| Line 94: | Line 102: |
| Now you are able to chroot into the filesystem: {{{ | You should now be able to chroot into the file system: {{{ |
| Line 104: | Line 112: |
| * Modify Scratchbox to take advantage of the new qemu packages, instead of using its own internal qemu. | * Modify Scratchbox to take advantage of the new qemu packages, instead of using its own internal qemu (possible?). |
QEMU User Emulation
This page describes how to setup and use QEMU user emulation in a "transparent" fashion, allowing execution of non-native target executables just like native ones (i.e. ./program).
In this text, "target" means the system being emulated, and "host" means the system where QEMU is running.
Note: this text depends on features that are not available in official Debian qemu package as of 2006-10-29. Here is the current summary of the bugs related to this feature:
Bug # |
Description |
Status |
[http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=384338 #384338] |
Add "qemu-user-static" package |
patch available |
[http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=306637 #306637] |
Add "qemu-binfmt" package |
patch available |
Note this setup is incompatible with [http://www.scratchbox.org Scratchbox] (both use the binfmt_misc module to register the same formats), so it's recommended to remove it (or stop its init script) before continuing.
Building qemu
Download and unpack qemu sources:
apt-get source qemu dpkg-source -x *.dsc
- Apply the following patches to the source, in order:
[http://bugs.debian.org/cgi-bin/bugreport.cgi/qemu_0.8.2-1_clean_build.patch?bug=390166;msg=5;att=1 qemu_0.8.2-1_clean_build.patch]
[http://bugs.debian.org/cgi-bin/bugreport.cgi/qemu_0.8.2-1_binfmt-5.patch?bug=306637;msg=66;att=1 qemu_0.8.2-1_binfmt-5.patch]
[http://bugs.debian.org/cgi-bin/bugreport.cgi/qemu_0.8.2-1_user_static.patch?bug=384338;msg=10;att=1 qemu_0.8.2-1_user_static.patch]
Build the package as usual:
dpkg-buildpackage -rfakeroot
This will generate 3 packages: qemu, qemu-binfmt and qemu-user-static. The latter is only required if you want to chroot into non-native root file systems (see "Appendix: chrooting into target filesystems" below).
Installing packages
The binfmt-support package contains a helper script to easily register/unregister binary formats with the kernel using the [http://www.tat.physik.uni-tuebingen.de/~rguenth/linux/binfmt_misc.html binfmt_misc] module.
Install qemu, binfmt-support and qemu-binfmt:
# apt-get install qemu binfmt-support # dpkg -i qemu-binfmt*.deb
Check whether the binfmt entries were successfully registered:
# update-binfmts --display
This command should print entries for each supported target user emulator, except for the host system.
Running dynamically linked executables
With the instructions above, you should be able to run statically linked target executables. To be able to run dynamically linked binaries, QEMU needs to have access to the target ELF interpreter.
Installing the target C libraries with dpkg-cross
The libc6 package contains the target's ELF interpreter used by QEMU. The target Debian package cannot be installed directly on the host, so we need to use [http://packages.debian.org/unstable/utils/dpkg-cross dpkg-cross] to "cross-install" the package.
For example purposes, let's assume the target system is "arm".
Install the dpkg-cross package:
# apt-get install dpkg-cross
Now download the target libc6 package from one of the Debian mirrors and install it using dpkg-cross:
# dpkg-cross -i -a arm libc6_<version>_arm.deb
Alternatively, you can install the libc6-dev-arm-cross package from [http://www.emdebian.org/ EmDebian]:
# wget http://www.emdebian.org/debian/pool/cross-unstable/g/glibc/libc6-dev-arm-cross_2.3.6.ds1-6_all.deb # dpkg -i libc6-dev-arm-cross_2.3.6.ds1-6_all.deb
Testing the emulation environment
We will use the "hello" ARM Debian package to test the new environment.
Download the hello package (e.g. from http://http.us.debian.org/debian/pool/main/h/hello/hello_2.1.1-5_arm.deb)
Unpack it with the command:
$ dpkg -x hello_2.1.1-5_arm.deb /tmp/hello_arm
Finally, run the hello executable with:
$ /tmp/hello_arm/usr/bin/hello
It should print "Hello, world!".
That's it! You can now run non-native executables transparently, as long as QEMU supports the system calls used by it.
Appendix: chrooting into target file systems
To be able to chroot into a target file system, the qemu emulator for the target CPU needs to be accessible from inside the chroot jail. For this to work, you need first to install the qemu-user-static package (compiled above):
# dpkg -i qemu-user-static*.deb
You cannot use the dynamically linked qemu because the host libraries will not be accessible from inside the chroot.
Next, copy the emulator for the target architecture to the path registered by binfmt-support. For example, for an ARM target file system, you need to do the following:
# mkdir -p /target_fs/usr/lib/qemu-binfmt # cp /usr/bin/qemu-arm-static /target_fs/usr/lib/qemu-binfmt/arm
You should now be able to chroot into the file system:
# chroot /target_fs/
See Also
EmDebian/CrossDebootstrap, ["Embedded Debian"]
TODO
- Modify Scratchbox to take advantage of the new qemu packages, instead of using its own internal qemu (possible?).
