QEMU arm64 (raspi image) core20 on amd64 Host

Hey,

it is possible to emulate a core20 arm64 device on a amd64 host, like Raspi3 image or so?

I tried several configs and boot options with qemu-system-aarch64 but I get a blank screen or it cannot boot and stuck in the efi bootloader.

I tried with the OOMVF and with AAVMF folders from /usr/share, nothing helps.

Did someone knows the trick?

Greets Tony

there is an arm64 build of the pc-kernel snap (which essentially contains the linux-generic distro kernel) … if you build an image utilizing that kernel you should technically be able to boot it in an arm64 qemu VM … (you would have to craft your own gadget though with an arm64 grub binary and proper uefi setup that you will need to craft yourself)

the raspberry Pi is completely proprietary, as long as:

  • the bootloader is not open source and
  • there is no reliable/usable qemu emulation of that hardware,

you will not be able to boot it in a VM.

@ogra thx for that information, I will check the kernel out and will build a gadget for that.

Actually, it is possible to build an arm64 uefi image using pc gadget and pc-kernel. You could use https://github.com/snapcore/models/blob/master/ubuntu-core-22-arm64-edge.model as model or create your own.

1 Like

Hey @abeato for this, I created an image from the model assertion, I tried with:

sudo qemu-system-aarch64 \
 -smp 2 \
 -m 2048 \
 -machine virt \
 -cpu cortex-a57 \
 -net nic,model=virtio \
 -drive file=/usr/share/AAVMF/AAVMF_CODE.fd,if=pflash,format=raw,unit=0,readonly=on \
 -drive file=/usr/share/AAVMF/AAVMF_VARS.fd,if=pflash,format=raw,unit=1 \
 -drive "file=pc.img",if=none,format=raw,id=disk1 \
 -device virtio-blk-pci,drive=disk1,bootindex=1 \
 -serial mon:stdio \
 -nographic 

but it says “ubuntu-boot” not found, did I missing something?

I can see the boot menu but nothing happens, see below:

                     GNU GRUB  version 2.06

 /----------------------------------------------------------------------------\
 | Recover using 20230504                                                     |
 |*Install using 20230504                                                     |
 | Factory reset using 20230504                                               |
 | UEFI Firmware Settings                                                     |
 |                                                                            |
 |                                                                            |
 |                                                                            |
 |                                                                            |
 |                                                                            |
 |                                                                            |
 |                                                                            |
 |                                                                            |
 |                                                                            |
 \----------------------------------------------------------------------------/

  Use the ^ and v keys to select which entry is highlighted.
  Press enter to boot the selected OS, `e' to edit the commands
  before booting or `c' for a command-line.

error: device name already exists.
error: file `/kernel.efi' not found.

Try with something like:

qemu-system-aarch64 -machine virt -cpu cortex-a57 -smp 2 -m 4096 \
                        -bios /usr/share/AAVMF/AAVMF_CODE.fd \
                        -netdev user,id=net0,hostfwd=tcp::8022-:22 \
                        -device virtio-net-pci,netdev=net0 \
                        -drive if=virtio,file="$image",format=raw \
                        -device virtio-gpu-pci \
                        -device virtio-keyboard \
                        -device virtio-mouse \
                        -serial mon:stdio

I tried but got the same error as above.

Hi,

The first QEMU command you posted above should work, and does for me. It may of been an issue with the image you created ?

You should be able to eliminate an image issue by using testing with the Canonical provided image. Also, note that you don’t have to sudo that command, and shouldn’t write to to the VARS file in the system installed location in any case [ you are better of keeping that file pristine ].

You should be able to do the following:

# Grab the reference image
wget https://cdimage.ubuntu.com/ubuntu-core/22/stable/current/ubuntu-core-22-arm64.img.xz
# keep the downloaded image for futer tests from scratch
xzcat ubuntu-core-22-arm64.img.xz > ubuntu-core-22-arm64.img
# Copy the VARS file locally for use with this particaulr VM instance
cp /usr/share/AAVMF/AAVMF_VARS.fd .
# run it
qemu-system-aarch64 \
 -smp 2 \
 -m 2048 \
 -machine virt \
 -cpu cortex-a57 \
 -net nic,model=virtio \
 -drive file=/usr/share/AAVMF/AAVMF_CODE.fd,if=pflash,format=raw,unit=0,readonly=on \
 -drive file=AAVMF_VARS.fd,if=pflash,format=raw,unit=1 \
 -drive "file=ubuntu-core-22-arm64.img",if=none,format=raw,id=disk1 \
 -device virtio-blk-pci,drive=disk1,bootindex=1 \
 -serial mon:stdio \
 -nographic

One more thing to note. Performance without KVM is pretty bad, so you can expect the UC bootstrap process to take a while, it will vary depending on hardware but could easily could be 20 mins plus.

If you have ARM hardware available, running on that with the following will help speed things up a lot:

qemu-system-aarch64 -machine virt,accel=kvm -cpu host

Cheers, Just

Hey, that works like a charm with core22, but its possible to have it on core20 base on arm64? I could not found a pre default image for download.

Sorry, arm64 generic images using pc-kernel need UC22.