Poor man’s P2V

(P2V = physical to virtual, taking a physical machine and converting it into a virtual machine)

What happens when you have an old server sitting in the corner — the hardware is flaky and you need to set up a virtual equivalent ASAP, but no one can remember how that old server is configured? People will sell you very expensive software to solve this problem for you.

But if you have some time and patience you can do P2V conversions by hand for free, and it’s not too hard. Here’s how.

First of all, grab a bootable Linux rescue CD. A Fedora CD in rescue mode will do just fine, but choose any Linux CD that you’re happy with.

Now you boot your machine from the CD, so that we are in a modern, Linux-based OS. From the Linux command line you will see the physical disks in the machine like /dev/sda or /dev/hda (check /sys/block).

All you do is take each physical disk in turn and copy it complete over to your virtualization host. Just do:

dd if=/dev/sda | ssh root@virthost 'cat > /var/lib/libvirt/images/guest.img'

That makes a block-for-block identical copy of the hard disk, and it usually takes several minutes to an hour to copy everything across, depending how fast the old server and the network is.

Now over to your virtualization host, how do you boot this?

With very recent versions of virt-install there is a virt-install --import option that you can use to import disk images directly.

Alternately, write a libvirt XML configuration file for the virtual machine. It’s usually best to start off with an existing XML configuration, so just pick another guest at random and do virsh dumpxml foo. Take that output, modify it suitably, make sure it’s full virt (“hvm”), and boot using:

virsh define guest.xml

Now at this point it may not in fact boot. You might need to edit a few things inside the virtual machine disk image, typically /etc/fstab, maybe install a new kernel, perhaps edit the network configuration.

Step forward: guestfish and virt-edit.

$ guestfish -i guest.img
$ virt-edit guest.img /etc/fstab

(Note: I am the author of virt-p2v which is currently in a big version 2.0 rewrite).

About these ads

15 Comments

Filed under Uncategorized

15 responses to “Poor man’s P2V

  1. Pingback: Harish Pillay (harishpillay) 's status on Tuesday, 27-Oct-09 15:19:38 UTC - Identi.ca

  2. Pingback: Roy Ong (royongbg) 's status on Wednesday, 28-Oct-09 02:23:15 UTC - Identi.ca

  3. John L Magee

    Will this migrate a Windows XP system?

    • rich

      John, I don’t know — please try it and let us know.

      One thing I do know is that Windows gets very annoyed when the hardware suddenly changes from under it. At the very least this will require reactivation.

    • Ken Barber

      I tried it; didn’t work.

      Specifics: the “P” system was already XP / RHEL dual boot, so it has grub instead of the Win bootloader.

      Grub comes up, gives its menu. Choose Windows, it echos grub’s “chainloader” command, and then hangs.

      I don’t have the XP install CD (company laptop) so I don’t have a way of issuing “fdisk /mbr” to see what would happen.

  4. Just did a P2V like this for a Windows 2003 server. Works like a charm :)

  5. Miles

    Is there a schedule when the virt-p2v 2.0 release?
    And does it has a tool can do the live p2v on redhat Linux?

  6. Daniel Beckman

    Could this process be applied in migrating to a RHEV 2.2 environment that is using fiber channel SAN?

  7. Pingback: Migrating CentOS5 VMWare images to KVM | Screwtape's Blog

  8. I’ve had considerable success using fsarchiver to replicate linux installations from physical machines to virtual disk images. The advantage is that, unlike dd, it does not perform a block but rather a file system copy, so that, e.g. unused space is not copied — so it is entirely possible to copy to a smaller disk (physical or virtual) than the original. It also supports various compression levels, and archive splitting on the fly. Whatever method used to make the copy to vdi, you can mount the disk image from another, running virtual machine to perform various editing chores, including rewrite the mbr, and reinstall a bootloader.

  9. Thanks! worked like a charm first time. The vm did complain about driver blah blah missing but it booted. the virt-foo tools did not work for me somehow.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s