Qemu ARM64

How to run QEMU with various ARM64 images. Not covering full blown support of each distribution. Goal is just to get to Linux shell and no more further at this stage.

Run Ubuntu Image

1
wget -c https://cdimage.ubuntu.com/releases/22.04/release/ubuntu-22.04.3-live-server-arm64.iso

Run Debian Image

1
2
wget -c http://http.us.debian.org/debian/dists/bookworm/main/installer-arm64/current/images/netboot/debian-installer/arm64/initrd.gz
wget -c http://http.us.debian.org/debian/dists/bookworm/main/installer-arm64/current/images/netboot/debian-installer/arm64/linux

Prepare qemu empty hdd image

1
qemu-img create -f qcow2 hda.qcow2 5G

Boot image and follow installation steps. That will install Debian ARM64 distribution

1
2
3
4
5
6
7
8
qemu-system-aarch64 -M virt -m 1024 -cpu cortex-a53 \
  -kernel linux \
  -initrd initrd.gz \
  -drive if=none,file=hda.qcow2,format=qcow2,id=hd \
  -device virtio-blk-pci,drive=hd \
  -netdev user,id=mynet \
  -device virtio-net-pci,netdev=mynet \
  -nographic -no-reboot

get guestfs-tools to make below commands work https://libguestfs.org/

find vmlinuz and initrd names in /boot directory

virt-ls -a hda.qcow2 /boot
virt-copy-out -a hda.qcow2 /boot/vmlinuz-6.1.0-12-arm64 /boot/initrd.img-6.1.0-12-arm64 .

Boot qemu with installed debian arm64 image

qemu-system-aarch64 -M virt -m 1024 -cpu cortex-a53 \
  -kernel vmlinuz-6.1.0-12-arm64 \
  -initrd initrd.img-6.1.0-12-arm64 \
  -append 'root=/dev/vda2' \
  -drive if=none,file=hda.qcow2,format=qcow2,id=hd \
  -device virtio-blk-pci,drive=hd \
  -netdev user,id=mynet \
  -device virtio-net-pci,netdev=mynet \
  -nographic

Run virt

Qemu contains configuration to run physicaly non existant ARM64 board called virt that suppose to be run with virtual machines and contains generic configuration.

Basic examples how to boot into the busy box shell is. Build busy boxwith mount,ash,exec and echo. Create init script that will set the pathes and create some dev,proc and sys mount points and switch to busybox shell.

1
2
3
4
5
6
7
8
9
#!/sh
/busybox echo "Boom" > /dev/kmsg
export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/
/busybox mount -t proc none /proc
/busybox mount -t sysfs none /sys
/buysbox mount -t devtmpfs -o nosuid,mode=0755 udev /dev
/busybox mount /dev/pts
/busybox mount -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts || true
exec /busybox sh

Create initrd files with init file and busybox utilities

1
find . | cpio -o -c -R root:root | gzip -9 > ../initrd-arm64.img

Boot into the just created initrd

1
2
3
4
5
6
qemu-system-aarch64 \
    -machine virt -m 1024M -cpu cortex-a53  \
    -kernel bootfs-arm64/Image.gz \
    -initrd initrd-out.gz \
    -append "root=/dev/ram0  console=ttyAMA0 debug " \
    -nographic

Under ArchLinux

Install all qemu packages with

1
pacman -S qemu-full

Links

  1. /writeup/qemu_usage.md
  2. https://www.qemu.org/docs/master/system/target-arm.html
  3. https://futurewei-cloud.github.io/ARM-Datacenter/qemu/how-to-launch-aarch64-vm/
  4. https://wiki.debian.org/Arm64Qemu
  5. https://gist.github.com/oznu/ac9efae7c24fd1f37f1d933254587aa4
  6. https://medium.com/@kiky.tokamuro/creating-initramfs-5cca9b524b5a
  7. https://translatedcode.wordpress.com/2017/07/24/installing-debian-on-qemus-64-bit-arm-virt-board/
  8. https://archlinuxarm.org/platforms/armv8/generic
  9. https://github.com/niw/TinyLinux
  10. https://cs4118.github.io/dev-guides/debian-kernel-compilation.html
  11. https://developer.ibm.com/articles/l-initrd/
  12. https://wiki.archlinux.org/title/mkinitcpio
  13. https://www.ibm.com/docs/en/zos/2.4.0?topic=codes-exit-status-usrsbininit
  14. https://access.redhat.com/solutions/24029
  15. http://phwl.org/2022/qemu-aarch64-debian/
  16. http://git.main.lv/cgit.cgi/os201.git/tree/create_installroot