CentOS convert hda to vda for virtualisation / grub problems & root panic
When virtualising a server, it sometimes become necessary to convert an old centos version from using hda as it’s root device, to be referenced by vda for virtio. Here’s a howto for people who already know what they’re kinda doing:
First thing is to make sure you’re running on the latest kernel for your OS before doing anything to make sure you’ve got the appropriate drivers:
yum update kernel
Step to is to edit some files on there. If you’ve already got it booted then great, otherwise you can boot it using ide virtualisation options in your virtualisation software, or you can use a boot/live cd (lots of options here! If you’re stuck, just use a centos LIVE CD)
Once in there, you’ll need to mount your image’s partitions in order to get into your image’s /boot/grub (or equivalent thereof – if your lost here then this howto really isn’t for you sorry!)
edit device.map and change
(hd0) /dev/hda
to
(hd0) /dev/vda
Next step is to edit your /etc/modprobe.conf and add/update the corresponding virtio modules:
alias eth0 virtio_net
alias scsi_hostadapter1 virtio_blk
(Remember if you’re using a boot cd, make sure you’re editing your image’s files – not your live cd’s temp files!)
Then you need to recreate the initrd file to have the virtio drivers (no redhat won’t put them in by default if they weren’t already there)
mkinitrd -f –with=virtio_blk –with=virtio_pci –builtin=xenblk /boot/initrd-2.6.18-custom.img 2.6.18-308.16.1.el5
Where 2.6.18-308.16.1.el5 is your kernel version (you can get it by looking at your files in /boot
Now you have the choice of altering your /boot/grub/menu.lst to use this new initrd-2.6.18-custom.img file (or you can just reboot, hit a key at grub boot time, use the e key to edit the initrd line – you can use tab to auto-complete to make it easy).
You might also need to update the root= part to be your /dev/vda3 (or whatever your root drive is). Mine was using labels so it didnt need to be changed.
Once booted, you now want to reinstall the stock centos initrd / kernel (it’s always scary to run on your own customisations!)…..so you’ll want to run:
rpm –erase –nodeps kernel-2.6.18-308.16.1.el5
(Or whatever your kernel version is)
yum install kernel
then reboot and if everything went according to plan, you should be sitting in a stock standard centos kernel, with your drives running on virtio / /dev/vda. Woo!