qemu-user-static is an important tool for cross-architecture developers.
It allows developers to create a chroot environment and run the
cross-compiled programs. For example, a developer may run an AArch64
executable without the overhead of system-level emulation.
I usually install the
qemu-user-static binaries from Ubuntu apt
repository. However, I encountered some bugs that have been fixed in the QEMU
upstream but the fixes haven't been back ported to the Ubuntu deb package.
Thus, I decided to build qemu-user-static from source code.
Install the QEMU build dependencies with:
$ sudo apt-get build-dep qemu
Download QEMU source code with:
$ git clone git://git.qemu.org/qemu.git $ cd qemu $ git submodule update --init --recursive
Configure QEMU with
$ ./configure \ --prefix=$(cd ..; pwd)/qemu-user-static \ --static \ --disable-system \ --enable-linux-user
--disable-system disables softmmu targets. It is a known
issue that softmmu targets rely on some shared libraries. Those softmmu
targets will cause link error if
--static is specified.
Build and install QEMU with:
$ make -j8 $ make install
-static suffix to executables so that
pick up these executables:
$ cd ../qemu-user-static/bin $ for i in *; do cp $i $i-static; done