Pierre Palatin's corner

Random posts about some stuff I’ve been doing.

Booting on a virtio disk with qemu

Posted at — Jan 1, 2006

Recent versions of Qemu, like version 0.10.1, are able to use virtio disks if your guest kernel support it. While kvm has an option boot=on for -drive descriptions, qemu doesn’t have it yet, and so is not able to boot from virtio disks by default.

To overcome this limitation, I’m using the same disk image both as a virtio disk and as a regular hda:

qemu -drive file=vm.img,snapshot=on -drive file=vm.img,if=virtio -boot c [...]

I add snapshot=on to the “fake” drive. Theorically, as the linux guest is configured to boot on /dev/vda1, it should never try to modify /dev/hda. However, this trick is prone to mistakes, and having the same image written for 2 different drives would probably be really bad.

So, qemu will boot on drive @hda@, the boot loader (grub in my case) will load the kernel from it too, but then, because I give root=/dev/vda1 to the kernel, it will properly use virtio disk, while avoiding complicated setups with a dedicated boot partition.