Boot an ARM64 Linux Kernel and Root Filesystem in QEMU

Boot an arm64 Linux kernel and a BusyBox root filesystem in QEMU with qemu-system-aarch64 on the virt board, then confirm aarch64 inside the guest.

Embedded Published 4 min read

Contents

You can boot an arm64 Linux kernel in QEMU on an x86 PC with qemu-system-aarch64, no board required. This guide downloads a prebuilt arm64 kernel and a static BusyBox, packs them into a root filesystem, boots them, and checks from inside the guest that it reports aarch64.

Pick a machine and a CPU

QEMU’s Arm documentation says you must choose a board with -M; there is no default. For running Linux it recommends the virt board, which does not match real hardware and is designed for virtual machines. The virt page also says the default CPU is a 32-bit cortex-a15, so for an AArch64 guest you must pass -cpu. It lists models such as cortex-a53 and cortex-a72, and notes that max gives the best possible emulation under TCG, QEMU’s software emulation mode. The board provides PL011 serial ports; this guide uses ttyAMA0 as the console, and the boot test below confirms it works.

Get an arm64 Linux kernel and BusyBox

This guide is tested on Debian. Rather than cross-compiling a kernel, we enable the arm64 architecture in dpkg, download two arm64 packages, and unpack them without installing. The host stays x86.

✓ tested · debian
apt-get update
apt-get install -y qemu-system-arm cpio file gzip
dpkg --add-architecture arm64
apt-get update
mkdir -p /tmp/arm64/debs /tmp/arm64/pkg
cd /tmp/arm64/debs
apt-get download linux-image-arm64 busybox-static:arm64
apt-get download "$(apt-cache depends linux-image-arm64 | awk '/Depends:/ {print $2; exit}')"
ls -l

linux-image-arm64 is a metapackage that depends on the versioned kernel package, so the last download fetches the real one. Now unpack the kernel package and BusyBox.

✓ tested · debian
cd /tmp/arm64/debs
for deb in linux-image-*-arm64*_arm64.deb busybox-static_*_arm64.deb; do
  case "$deb" in linux-image-arm64_*) continue ;; esac
  dpkg-deb -x "$deb" /tmp/arm64/pkg
done
ls /tmp/arm64/pkg/boot
BUSYBOX=$(find /tmp/arm64/pkg -path '*/bin/busybox' | head -n 1)
echo "$BUSYBOX"
file "$BUSYBOX"

The file output should describe an ARM aarch64 executable, statically linked. That is the check that we really have an arm64 userland.

Build the root filesystem

The simplest root filesystem here is an initramfs: the kernel extracts a gzipped cpio archive into rootfs at boot and runs /init from it, as the kernel documentation describes. The initramfs guide explains this in more depth for x86.

✓ tested · debian
mkdir -p /tmp/arm64/root/bin /tmp/arm64/root/proc /tmp/arm64/root/sys /tmp/arm64/root/dev
cd /tmp/arm64/root
cp "$(find /tmp/arm64/pkg -path '*/bin/busybox' | head -n 1)" bin/busybox
for tool in sh mount echo cat uname poweroff; do
  ln -s busybox bin/$tool
done
cat > init <<'EOF'
#!/bin/busybox sh
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devtmpfs devtmpfs /dev
echo "Hello from arm64 userspace"
echo "uname -m: $(uname -m)"
cat /proc/cmdline
poweroff -f
EOF
chmod +x init
find . | cpio -o -H newc | gzip > /tmp/arm64/rootfs.cpio.gz
ls -l /tmp/arm64/rootfs.cpio.gz

Boot with qemu-system-aarch64

The options are: -M virt for the board, -cpu max for the CPU, -kernel and -initrd to load the files directly, and -append for the kernel command line. -nographic sends the serial port to your terminal, and console=ttyAMA0 sets the kernel console. -no-reboot makes QEMU exit instead of rebooting.

✓ tested · debian
KERNEL=$(ls /tmp/arm64/pkg/boot/vmlinuz-* | sort | tail -n 1)
timeout 600 qemu-system-aarch64 -M virt -cpu max -m 1024 -nographic -no-reboot \
  -kernel "$KERNEL" \
  -initrd /tmp/arm64/rootfs.cpio.gz \
  -append "console=ttyAMA0 panic=-1" < /dev/null > /tmp/arm64/boot.log 2>&1
grep -a "Hello from arm64 userspace" /tmp/arm64/boot.log
grep -a "uname -m: aarch64" /tmp/arm64/boot.log

On an x86 host this runs under software emulation (TCG). You should see the kernel messages followed by the lines from the init script:

Hello from arm64 userspace
uname -m: aarch64
console=ttyAMA0 panic=-1

The line uname -m: aarch64 is the confirmation: the kernel and BusyBox inside the guest are running as 64-bit Arm code. If you see nothing, check that you passed -cpu and that the console argument matches the board’s serial port.

Get an interactive shell

For a shell instead of an automatic poweroff, boot with rdinit=/bin/sh, the initramfs counterpart of init=/bin/sh. This needs a terminal, so it is not part of the tests. Run poweroff -f to leave QEMU.

qemu-system-aarch64 -M virt -cpu max -m 1024 -nographic -no-reboot \
  -kernel /tmp/arm64/pkg/boot/vmlinuz-* \
  -initrd /tmp/arm64/rootfs.cpio.gz \
  -append "console=ttyAMA0 rdinit=/bin/sh"

Where to go next

To run single arm64 programs without booting a kernel, see the QEMU user-mode guide. For a full kernel and root filesystem built from source, the Buildroot guide is the next step. To see how the board’s hardware is described to the kernel, read Device Tree Basics.

Sources

  1. QEMU documentation: Arm Emulation
  2. QEMU documentation: Generic Virtual Platform (virt)
  3. Ramfs, rootfs and initramfs (Linux kernel documentation)

#Qemu #Arm64 #Aarch64 #Embedded #Kernel

This article was drafted with AI assistance, fact-checked against the sources listed above and reviewed by a human editor before publication. Spotted an error? See our corrections policy.