Constructing Cross-Platform Ubuntu Root Filesystems with QEMU Emulation
Download the appropriate Ubuntu Base tarball for your target architecture from the official Ubuntu CD image repository. Available variants include amd64, armhf, arm64, i386, powerpc, and ppc64el. This example demonstrates configuring an ARM64 (aarch64) environment using a 16.04 LTS release archive.
Prepare the build workspace and extract the minimal root filesystem:
mkdir -p /var/build/arm64-env
cd /var/build
tar -xpf ubuntu-base-16.04.6-base-arm64.tar.gz -C arm64-env/
For cross-architecture chroot operations on an x86_64 host, install the QEMU user-mode emulation layer:
apt install qemu-user-static
Copy the architecture-specific static binary into the target rootfs to enable transparent execution of foreign binaries:
# For 32-bit ARM targets:
# cp /usr/bin/qemu-arm-static /var/build/arm64-env/usr/bin/
# For 64-bit ARM (AArch64) targets:
cp /usr/bin/qemu-aarch64-static /var/build/arm64-env/usr/bin/
Configure network resolution and package management. Copy the host's DNS configuration and define appropriate repository mirrors:
cp /etc/resolv.conf /var/build/arm64-env/etc/resolv.conf
Edit /var/build/arm64-env/etc/apt/sources.list to include regional mirror entries:
deb http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted universe multiverse
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted universe multiverse
Create virtualizasion wrappers to bind kernel interfaces into the chroot environment. The initialization script mounts pseudo-filesystems and activates the emulated shell:
#!/bin/bash
# launch-chroot.sh
rootfs_path=/var/build/arm64-env
mount -t proc proc ${rootfs_path}/proc
mount -t sysfs sys ${rootfs_path}/sys
mount --bind /dev ${rootfs_path}/dev
mount --bind /dev/pts ${rootfs_path}/dev/pts
chroot ${rootfs_path} /bin/bash
The corresponding teardown script unmounts virtual filesystems upon exit:
#!/bin/bash
# teardown-chroot.sh
rootfs_path=/var/build/arm64-env
umount ${rootfs_path}/proc
umount ${rootfs_path}/sys
umount ${rootfs_path}/dev/pts
umount ${rootfs_path}/dev
Grant execution permissions and invoke the environment:
chmod +x launch-chroot.sh teardown-chroot.sh
./launch-chroot.sh
Inside the emulated environment, update the package index and install essential administration utilities:
apt update
apt install -y sudo vim kmod net-tools ethtool ifupdown language-pack-en-base rsyslog htop iproute2
Common Configuration Issues
If entering the chroot fails with chroot: failed to run command '/bin/bash': No such file or directory, the dynamic linker or shared librareis are missing from the target rootfs. Verify library dependencies using ldd on the host system against the target's bash binary, then copy the required shared objects into the appropriate library paths.
When encountering bash: /usr/bin/groups: No such file or directory, verify that the correct QEMU static binary matches the target architecture. ARM64 (aarch64) targets require qemu-aarch64-static, while 32-bit ARM targets require qemu-arm-static. Mismatched emulation binaries cause execution failures for dynamically linked applications.