CentOS 7 grub virtio error migrating to KVM
When migrating CentOS7 from physical servers or vmware / hyperv, it typically does not have virtio drivers built into it. This will often give grub or initramfs errors.
Once the image has been migrated, you have three choices:
- Boot using Rescue mode from a latest CentOS or RockyOS (v8+), and choose to mount the existing machine (option 1). Version 8+ has the virtio drivers built in, so will see the drive no problem.
- Boot using recovery mode. This is usually a grub menu option. We find this typically has virtio built in
- Change emulation for the drive to IDE and boot as normal
Once booted into the os (or mounted via rescue cd and chroot /mnt/sysimage), change to root user if you aren’t already.
Run the following command to rebuild the initramfs:
mkinitrd -f --allow-missing --with=virtio_blk --preload=virtio_blk --with=virtio_net --preload=virtio_net --with=virtio_console --preload=virtio_console /boot/initramfs-$(uname -r).img $(uname -r)
Then just shut down the VM and boot it back up. new initramfs will now have the virtio drivers and be able to see the disk.