QEMU can build an environment that identical to the target device at the hardware level, and it is a good alternative to cross-compilation. This article shows how to run an ARM64 Linux (Debian 12 here) on an x64 Windows 11. The image format in this article is *.qcow2, but raw format (i.e. *.img) also works fine.

Preparation

Booting virtual machine needs three files as follows.

  • *.qcow2: Linux image.
  • QEMU_EFI.fd: UEFI firmware (similar to BIOS).
  • user-data.img: Cloud-init Configuration data used during the first boot to set up the system.

Here is how to get them.

1. Download the Debian Image

Download the cloud Debian image from this link.

2. Get the UEFI Firmware

Download from this link.

3. Create the Configuration File

First, create user-data with the following content:

#cloud-config
password: 114514
chpasswd: { expire: False }
ssh_pwauth: True
hostname: qemu
  • password: Password for root or the default user.
  • chpasswd: { expire: False }: Password should not expire
  • ssh_pwauth: True: Allows SSH password authentication.
  • hostname: Hostname for your virtual machine.

You can also define additional users, install basic packages, and more in this file.

Then, generate user-data.img using cloud-localds (on Linux).

cloud-localds user-data.img user-data

Or you can just download my user-data.img created from the above configuration: user-data.img.

Booting the VM

Once the three files are ready, you can boot the VM.

1. Set the VM Storage Size

qemu-img resize debian-12-genericcloud-arm64.qcow2 30G

You can adjust the image size later with this command if the storage is too little or too much.

2. Launch

qemu-system-aarch64 `
  -m 4096 `
  -cpu cortex-a53 `
  -smp 4 `
  -M virt `
  -nographic `
  -bios QEMU_EFI.fd `
  -drive if=none,file=debian-12-genericcloud-arm64.qcow2,id=hd0,format=qcow2 `
  -device virtio-blk-device,drive=hd0 `
  -drive file=user-data.img,format=raw `
  -device virtio-net-device,netdev=net0 `
  -netdev user,hostfwd=tcp:127.0.0.1:4096-:22,id=net0
  • CPU: cortex-a53
  • Cores: 4
  • RAM: 4GiB
  • Port: 4096

Modify format=qcow2 to format=raw if image format is *.img.

After the system boots up, log in using the password defined in user-data. The default username is debian.

Log in via SSH:

ssh debian@localhost -p 4096

Use SCP to transfer files:

scp -P 4096 debian@localhost:/opt/opencv_qemu.tar.gz .\Downloads\

If you need to share files frequently, making a shared folder is suggested.

Demo

Enjoy your time!

References

https://gist.github.com/billti/d904fd6124bf6f10ba2c1e3736f0f0f7

https://stackoverflow.com/questions/29137679/login-credentials-of-ubuntu-cloud-server-image/53373376#53373376

https://qemu.weilnetz.de/w64/

Outline