User-mode QEMU translates the instructions and the system calls. To run a
static executable, you may wrap the command line with
For example, you may wrap an ARM64 static executable with
$ qemu-aarch64 /path/to/static-executable
However, running a dynamically linked executable requires more efforts. To run a dynamically linked executable, a complete user space environment (including dynamic linker, shared libraries, etc) must be set up.
qemu-debootstrap can help us set up an Ubuntu (or Debian)
user space environment. In this post, the instructions to set up an ARM64
Ubuntu environment will be presented.
Three packages are required for this post:
- debootstrap is a Debian (or Ubuntu) bootstrap tool. It will download several deb packages and set up a minimal Debian (or Ubuntu) user space.
- qemu-user-static is the deb package for user-mode QEMU static executables.
Don't confuse this package with qemu-user. The static version must be
installed because these QEMU executables will be copied into chroot
environments. This package also includes
qemu-debootstrap, which is a wrapper for cross-architecture debootstrap.
- schroot is a chroot wrapper. Besides changing the root directory, schroot will run several hooks before entering and after leaving the chroot so that many functionalities, including network, can work without problems.
Run the command below to install these prerequisites:
$ sudo apt-get install debootstrap qemu-user-static schroot
Create an Environment
To create an Ubuntu 16.04 (Xenial Xerus) ARM64 user space in the
arm64-ubuntu directory, run the following command :
$ sudo qemu-debootstrap --arch=arm64 xenial arm64-ubuntu
And then, create a schroot configuration at
$ echo "[arm64-ubuntu] description=Ubuntu 16.04 Xenial (arm64) directory=$(pwd)/arm64-ubuntu root-users=$(whoami) users=$(whoami) type=directory" | sudo tee /etc/schroot/chroot.d/arm64-ubuntu
Finally, enter the schroot with:
$ schroot -c arm64-ubuntu
Now, we are in an environment that can run ARM 64-bit binaries. For example, we can check the architecture with:
> uname -m aarch64
BTW, to be a root user in the chroot, you may pass
$ schroot -c arm64-ubuntu -u root
And then, you may install packages with
apt-get. For example:
> apt-get install vim
In this post, I have covered
schroot. These tools significantly boosted my productivity on
cross-architecture development. I hope this article is helpful. Thanks for
|||By default, |