Running OpenWrt under QEMU/KVM (aarch64)

Hello everyone!

I recently purchased a Raspberry Pi 4 model B. Unfortunately, I'm not ready to commit the entire device to running OpenWrt, but I have a fully functional QEMU/KVM platform on which I'd like to run OpenWrt whilst also being able to run other services.

I have tried a variation of OpenWrt images and virt-install options but to no avail. None of them even booted, leaving me in the EFI shell. I even tried to use an Alpine Linux ISO to amend OpenWrt's boot entry, but it was beyond me.

After some intense searching, I came across this guide (https://openwrt.org/docs/guide-user/virtualization/qemu#openwrt_in_qemu_aarch64). In order to test it, I ran a truncated version of the first command with the latest release files, the command being:

$ qemu-system-aarch64 -m 1024 -smp 2 -cpu cortex-a57 -M virt -nographic  \
-kernel openwrt-22.03.5-armvirt-64-Image-initramfs

This worked, but it's not being managed by libvirt, so it's not exactly useful to me. In my attempts to translate this command into something virt-install could understand, I tried all of the following and more (which were just variations on these excluded for brevity):

$ virt-install -n OpenWrt --description "Router VM" --osinfo=linux2022 --ram=512 --vcpus=1 --disk path=/home/noroot/openwrt-22.03.5-armvirt-64-rootfs-ext4.img --graphics none --install kernel=/home/noroot/openwrt-22.03.5-armvirt-64-Image,initrd=/home/noroot/openwrt-22.03.5-armvirt-64-Image-initramfs

$ virt-install -n OpenWrt --description "Router VM" --osinfo=linux2022 --ram=512 --vcpus=1 --disk path=/home/noroot/openwrt-22.03.5-armvirt-64-rootfs-ext4.img --graphics none --import --boot kernel=/home/noroot/openwrt-22.03.5-armvirt-64-Image,initrd=/home/noroot/openwrt-22.03.5-armvirt-64-Image-initramfs

$ virt-install -n OpenWrt --description "Router VM" --osinfo=linux2022 --ram=512 --vcpus=1 --graphics none --import --boot kernel=/home/noroot/openwrt-22.03.5-armvirt-64-Image-initramfs

The issue is that the -kernel argument to QEMU doesn't exactly translate to virt-install. Scouting the manpage of virt-install reveals that there are two ways in which one could pass a kernel, that is, during the installation process only (using --install), or permanently (using --boot). The last command listed would logically seem to be the closest to the QEMU command, since we are skipping the installation process and booting directly into the initramfs, as is done in the QEMU command, but the following error occurs:

ERROR    unsupported configuration: ACPI requires UEFI on this architecture

I was wondering if anyone could assist me in formulating a virt-install command such that OpenWrt at least boots.

Thanks in advance,
quickmanjump

The error at the end seems to be residual of our replacement of UEFI boot with direct kernel boot. Perhaps booting into the ext4 tarball using a supporting ISO and installing a bootloader may be the course of action.

Very bad idea, BTW aarch64 does not support 'classic' virtualization.

Have you got any other ideas?

Install OpenWRT on entire device.

That's not really a solution to my question. I stated that I did not want to install OpenWrt directly because the Pi's specs are simply overkill, and potential processing power would just go to waste. If it is possible to do, which it is as has been demonstrated in the documentations that I linked, then simply ignoring my constraints and telling me to dedicate the whole Pi to OpenWrt isn't a valid response.

Have you seen this:

In fact, there's a few threads with example commands, see:

https://forum.openwrt.org/search?q=qemu-system-aarch64

Hope this helps.

Thanks, but I'm looking to create the virtual machine using virt-install rather than QEMU directly

I was offering the links because:

  • we technically don't support the host OS - you may wish to ask them
  • not a single forum search produces that
  • as far as I can tell from the manual - you're using some incorrect/invalid syntax

If you insist on being the trailblazer - please note your progress; and see:

I hope this helps.

Create a guest from an existing disk image 'mydisk.img' using defaults for the rest of the options.
# virt-install \
     --name demo
     --ram 512
     --disk /home/user/VMs/mydisk.img
     --import