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:
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'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 -ivdmI 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:
$ ssh user@host 'cat tmp/foo/root.cpio.gz'|zcat|cpio -ivdm
$ ssh user@host 'cat tmp/foo/boot.cpio.gz'|zcat|cpio -ivdmMaking 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.
chroot /mnt/sysimage
kudzuThis 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 mptscsihI 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 /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
grub-install /dev/sdaIf 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.
Finishing 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!
FriendFeed Updates
Attaching files to nodes programmatically in Drupal 6- From delicious, posted Tuesday, June 23, 2009 - 10:13pm.
Deltatrax - Broadcast Automation System- From delicious, posted Friday, June 19, 2009 - 10:21am.
Marantz PMD660 Internal Mic Test Recording- From chacadwa.com - Technical blog and writings by Micah Webner., posted Sunday, June 14, 2009 - 7:21pm.
Marantz PMD660 Internal Mic Test Recording- From FriendFeed, posted Sunday, June 14, 2009 - 7:42pm.
5-Step Drupal Distributions | Lullabot- From delicious, posted Friday, June 5, 2009 - 12:13pm.
Ugly Mug Coffee Co. - Coffee Care- From delicious, posted Monday, June 1, 2009 - 12:27pm.
Drupal Modules | Drupal Implementation at UD- From delicious, posted Monday, June 1, 2009 - 11:32am.
UDrupal | UD Web content management services- From delicious, posted Monday, June 1, 2009 - 10:30am.



Comments
--exclude
--exclude is useful to excude directories
cd /
tar -jcf redhat4.7_64bit.tar.bz --exclude redhat4.7_64bit.tar.bz --exclude proc --exclude tmp --exclude var/tmp --exclude boot --exclude u01 *
True for tar, but cpio?
That's true for tar, but since this is using cpio, I didn't utilize that approach.
I've also found --exclude for tar to be the most frustrating command line options I've ever used, so I tend to avoid it when I can.