How to boot with BIOS instead of EFI?

I’m migrating some existing KVM virtual machines to LXD. Since they already have a filesystem image, I just copy the raw filesystem device as it is. This works well, but booting the virtual machine fails, because it does not have an EFI partition. These are regular BIOS bootable instances. This shouldn’t be a problem since Qemu supports booting both BIOS and EFI. But I can’t find a way to convince LXD to use BIOS boot.

I tried to add the -bios parameter:

lxc config set testvm raw.qemu='-bios /usr/share/seabios/bios-256k.bin'

With ps I can see that the extra qemu parameter was added, but the instance still tries to boot in EFI mode.

Qemu by default uses BIOS boot, and the EFI mode seems to be becaues in /var/snap/lxd/common/lxd/logs/testvm/qemu.conf there is a pflash drive added which uses file /snap/lxd/current/share/qemu/OVMF_CODE.fd. So tried to override that:

lxc config set testvm raw.qemu='-drive if=pflash,format=raw,unit=0'

But lxc start testvm fails:

qemu-system-x86_64: -drive if=pflash,format=raw,unit=0: drive with bus=0, unit=0 (index=-1) exists

Looking at the code at lxd/driver_qemu.go at master · lxc/lxd · GitHub and lxd/driver_qemu_templates.go at master · lxc/lxd · GitHub there seems to be no way to disable this. At this point I’m stuck.

What would be a good way to migrate existing BIOS instances to LXD?

1 Like

I still don’t know how to boot virtual machines in BIOS mode, but I worked around the problem by using distrobuilder to rebuild the BIOS virtual machine into EFI virtual machines.
It was easy for me to get the tar-ed rootfs with gnt-backup export and then I used

distrobuilder pack-lxd image.yaml rootfs --vm -o targets.lxd.vm.size=$image_size

Where image.yaml is based on lxc-ci/ubuntu.yaml at master · lxc/lxc-ci · GitHub and $image_size is the size of the disk image in bytes.
This generates lxd.tar.xz and disk.qcow2 which can be imported with lxc image import lxd.tar.xz disk.qcow2, which then can be used to launch instances.
(I made it more complicated for myself by creating a tar file which can be imported with lxc import (instead of lxc image import)).
So problem solved, and now the instances are running as EFI.