Enabling virtio on older GNU/Linux installations

Last night I had to migrate a physical GNU/Linux installation to a virtual GNU/Linux installation based on KVM.
Usually the Linux kernel or its initrd enables virtio by default and everything works as expected and vda1 is used as the root filesystem.
However this was not the case yesterday. I got a message similar to:
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
which complained about vda1 not being found.

After struggling a little bit I found out how to workaround it. It seems you can enforce some modules to be loaded at initrd. That way when initrd tries to look for the virtio’s vda1 device it will find it. I also added the network driver but I’m not sure it was needed at this point.
So what I did was to edit:
/etc/initramfs-tools/modules
file
so that it read:
virtio
virtio_blk
virtio_net

and finally I run (inside a chroot where I had mount-binded: sys, proc and dev):
update-initramfs -u
Next time I rebooted the root filesystem was found and our GNU/Linux came back to live again but in a virtual machine.
So if a kernel refuses to find your virtio device as a filesystem root (even if you see in the Virtio KVM page that you kernel supports it because its version is higher than 2.6.25) be sure to try these steps before trying to use a newer kernel or trying to rebuild it with bultin virtio support.

Deja un comentario