My First Linux P2V
I just completed my first physical to virtual (p2v) migration of a Linux server. I used cpio, ssh and a rescue CD to migrate an aging server to VMware. Here's how I did it. (I'll try to leave out the steps that didn't work!)
We recently identified several servers that could be migrated to VMware Server, and the first Linux box to be moved is an old Fedora Core 2 box that runs as an instructional Oracle database server. According to the logs, it hasn't been used for student work since last May, so we may be retiring it, anyway.
I've found a number of documents on Linux p2v. The one that helped me the most was from Phil Windley's Technometria. That one told me what I'd need to do to make my new VM boot, and those instructions helped me decide how to proceed. I also relied heavily on the Understanding CPIO article from ONLamp.com.
I can't recall when or why I decided I was going to use cpio when I tried this, but it worked out great. Most of the instructions I've found for migrating Linux boxes involve booting the source machine from CD and doing a cold migration. For a variety of reasons, I wanted to try this as a hot clone.
Copying Data from the Old Server
I shut down the Oracle database and all unnecessary services while copying from my source machine. The original server had only root and boot file systems. I wanted to split the Oracle install into different backups from the rest of root, so I ended up creating four archives:
[code]find /boot -mount -depth | sed "s|^/||g"| cpio -ova -H crc| gzip | ssh user@host 'cat>tmp/foo/boot.cpio.gz'
find / -mount -depth |egrep -v "^/u0"| sed "s|^/||g"| cpio -ova -H crc| gzip | ssh user@host 'cat>tmp/foo/root.cpio.gz'
find /u01 -mount -depth | sed "s|^/||g"| cpio -ova -H crc| gzip | ssh user@host 'cat>tmp/foo/u01.cpio.gz'
find /u02 -mount -depth | sed "s|^/||g"| cpio -ova -H crc| gzip | ssh user@host 'cat>tmp/foo/u02.cpio.gz'[/code]
Note that the egrep command is used to eliminate the Oracle directories /u01 and /u02 from the root copy. This would not normally be needed.
Preparing the Target VM
I created a new VM, and used the Fedora Core 2 Rescue CD ISO file as my CD-ROM drive. I booted the VM from the CD image and dropped to a prompt. I created partitions for root, boot and swap, then created file systems on those. This would probably be a little tricky if I tried to use LVM, but the old box was static partitions, and that should work well enough in this case.
Next, I mounted those file systems and changed directory, then unpacked my cpio archives across the network.
$ mkdir /mnt/sysimage
$ mount /dev/sda3 /mnt/sysimage
$ mkdir /mnt/sysimage/boot
$ mount /dev/sda1 /mnt/sysimage/boot
$ cd /mnt/sysimage
$ ssh user@host 'zcat tmp/foo/root.cpio.gz'|cpio -ivdm
$ ssh user@host 'zcat tmp/foo/boot.cpio.gz'|cpio -ivdm
I didn't bring over my /u01 and /u02 images yet, because I wanted to make sure the machine was running first. When I did, I realized that I should transfer the data and then decompress, so I did those a little differently:
Making the VM Bootable
I probably should have rebooted at this point and let the rescue CD find my installed OS. That may have gone better. I think I also had problems because I didn't have the original FC2 kernel on the box any more. In any event, I needed to fix some things, and a lot of it was by trial and error.
This removed a bunch of drivers for hardware that no longer existed, but didn't help find the new ones I needed. I finally just stuffed the ones I needed into /etc/modprobe.conf:
alias eth0 pcnet32
alias scsi_hostadapter mptbase
alias scsi_hostadapter1 mptscsih
I noticed that the SCSI drivers tend to be different in later versions of Fedora. I figured these out from modprobe.
I edited /etc/fstab and /etc/mtab to match the rearranging I'd done in my partitions, and also had to edit /etc/grub.conf because I'd moved my /boot partition from /dev/sda3 to /dev/sda1. If you're coming from IDE and now using SCSI, you'll have to change hda to sda everywhere, too.
Finally I was ready to make my new initial RAM disk and install grub.
$ mv /boot/initrd-2.6.10-2.3.legacy_FC2.img /boot/initrd-2.6.10-2.3.legacy_FC2.old
mkinitrd -v /boot/initrd-2.6.10-2.3.legacy_FC2.img 2.6.10-2.3.legacy_FC2
If all goes well, that will pretty much do it for making the machine bootable. Try it by pressing Ctrl+D twice. My VM didn't actually boot until about the fourth try, but I finally figured out everything I'd done wrong, so just don't give up.
Next up, I had to use netconfig to configure my network card because the original settings had been eaten by kudzu. After that I simply installed the VMwareTools rpm and installed kernel-source using yum. Then I ran vmware-config-tools.pl to build and configure all of the driver and daemon pieces. Another reboot to make sure that everything is ok, and it was.
So now this VM is ready to move to the correct subnet and I can restore the Oracle backups, and I should be in business!