Building a Debian Buster QEMU image for AARCH64
Based on this article on building a Debian Stretch QEMU image for AARCH64.
Get base files (Debian Buster network installer image):
wget http://ftp.debian.org/debian/dists/buster/main/installer-arm64/current/images/netboot/debian-installer/arm64/initrd.gz
wget http://ftp.debian.org/debian/dists/buster/main/installer-arm64/current/images/netboot/debian-installer/arm64/linux
Create a disk:
qemu-img create -f qcow2 disk.qcow2 20G
Install Debian:
qemu-system-aarch64 -smp 2 -M virt -cpu cortex-a57 -m 1G \
-initrd initrd.gz -kernel linux \
-append "root=/dev/ram console=ttyAMA0" \
-device virtio-scsi-device \
-blockdev qcow2,node-name=hd0,file.driver=file,file.filename=disk.qcow2 \
-device scsi-hd,drive=hd0 \
-netdev user,id=unet -device virtio-net-device,netdev=unet \
-nographic
You need to extract the initrd.img and vmlinuz files from the qcow2 disk file. The easiest way to do this is to use nbd
in a Linux environment, e.g. a Virtual Machine that has access to the qcow2 disk file:
sudo apt install nbd-client qemu qemu-utils
sudo modprobe nbd max_part=8
sudo qemu-nbd --connect=/dev/nbd0 disk.qcow2
sudo mount /dev/nbd0p1 /media/qcow
sudo cp initrd.img-4.19.0-16-arm64 vmlinuz-4.19.0-16-arm64 ../qemu/.
sync
sudo umount /dev/nbd0p1
sudo nbd-client -d /dev/nbd0
Then:
qemu-system-aarch64 -smp 2 -M virt -cpu cortex-a57 -m 1G \
-initrd initrd.img-4.19.0-16-arm64 \
-kernel vmlinuz-4.19.0-16-arm64 \
-append "root=/dev/sda2 console=ttyAMA0" \
-device virtio-scsi-device \
-blockdev qcow2,node-name=hd0,file.driver=file,file.filename=disk.qcow2 \
-device scsi-hd,drive=hd0 \
-netdev user,id=unet -device virtio-net-device,netdev=unet \
-nographic
With additional resources allocated (8 cores and 4GB RAM):
qemu-system-aarch64 -smp 8 -M virt -cpu cortex-a57 -m 4G \
-initrd initrd.img-4.19.0-16-arm64 \
-kernel vmlinuz-4.19.0-16-arm64 \
-append "root=/dev/sda2 console=ttyAMA0" \
-device virtio-scsi-device \
-blockdev qcow2,node-name=hd0,file.driver=file,file.filename=disk.qcow2 \
-device scsi-hd,drive=hd0 \
-netdev user,id=unet -device virtio-net-device,netdev=unet \
-nographic
Login and setup sudo:
su - -c "apt -y install sudo"
su - -c "usermod -aG sudo matt"
exit
Login again:
sudo apt update && sudo apt -y upgrade
sudo echo "%sudo ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/01_sudo-nopassword
Install some basic utilities and disable the graphical desktop:
sudo apt -y install curl gcc make unzip zip vim git build-essential libz-dev zlib1g-dev
sudo systemctl set-default multi-user.target
Kernel Version
Install a newer kernel version in Debian Buster.
Links and References
- Building a Debian Stretch QEMU Image for AArch64
- Raspberry Development Environment on MacOSX with QEMU
- QEMU with ARM on Mac OSX