Navigation Menu



In my original post KVM Virtualization 101 and my second post KVM Virtualization 102, I explained some basic commands that are necessary to get on using KVM and some features for tuning KVM. In this article I move on to some of the more advanced problems when converting existing Linux machines from a physical machine to a virtual machine. This is called P2V conversion.

When converting, there are a couple of things that often change. I will outline the major pitfalls below. These techniques have been used to successfully convert RHEL4, RHEL5 and even ES/AS 2.1 machines.


Lab Tools

Rescue Disk

Personally, I use two main rescue disks, the Red Hat rescue disk and Puppy Linux, but any live CD will do. The Gentoo live CD/DVD and Knoppix are also very good.

Just get one you are comfortable with and use it, but always have a rescue disk on hand from the Linux distribution for which you are working on, especially if it is older. When I work on a Red Hat system, I always use a Red Hat rescue CD because the kernel versions, file system utilities, etc will be the same version as what is on the file system and everything works together.

The main reason to fall back to a different Live CD/DVD than your Linux vendor is when you need other network utilities or security tools, not when converting virtual machines.


Change Root (chroot)

This command is critical to have access to when you are converting virtual machines by hand and is available on almost any live CD ever produced. It usually works best with your vendor specific disk. Many of the live CD/DVDs help you by automatically mounting /dev, /sys, and /proc. Others, you will have to do this manually, so your millage may vary

The Gentoo Manual provides an excellent primer on using chroot manually


Grub Installer (grub-install)

Grub comes with an installer utility and you will need to use it. The installer utility writes the stage1 file to the MBR of the disk for which you are working on. This is true in virtual machines and host machines. Grub installer automatically detects some parameters for you based on your fstab, file, and grub.conf file.


Common Pitfalls

The following commands are all ran from within the chroot environment

FIle System Table (/etc/fstab)

When converting a machine, the first thing to look at is the File System Table file also called fstab. As of his writing KVM only supports ATA devices which are also are identified as /dev/hda or /dev/hdb in Linux.

First, always back up the current file

Then change the fstab to match the new KVM devices. Notice, we are converting from a Compaq Raid Array

Change to:


Grub Device Map (/boot/grub/

Again, backup the file, then change from the Compaq Raid array to the new ATA device. This file is what maps the grub name to the Linux Kernel name.

Chang to


Grub Configuration File (/boot/grub/grub.conf)

There are several caveats to the grub configuration file below. In our example, we are moving from a Linux system which had swap & boot located on separate raid volumes, so our root file system was located on what grub considered device 0, partition 0. With the new KVM disk, it was easier to specify the Swap partition as 2048MB and let the /root filesystem have the rest of the space. This has the byproduct of forcing us to change the grub.conf file

The grub device (hd0,0) becomes (hd0,1). Also, notice that since we had a separate boot partition that the kernel and initrd image were both addressed from /, this changes in our virtual environment. Since everything will now reside together on the same partition, we must readdress the path to begin with /boot.


Change to:


Install Grub Stage 1 (grub, grub-install)

Grub can be installed manually with the grub command or automatically with the grub-install command.

To install grub automatically for the above configuration, use the command below. Notice the disk which is specified. Note: this must be done from inside of a chroot environment. Also note that this is the disk name and not the partition because we want the stage1 installed in the MBR.

This is one of the cases where using the vendor supplied rescue disk can come in handy. I tried to use Puppy Linux while converting a RHEL 4 box and realized that puppy linux recognized ATA drives as /dev/sdx, while Red Hat recognizes them as /dev/hdx. You can also work around this by changing fstab & grub.conf temporarily

To install manually for the above configuration, use the following command

The Gentoo Manual also provides an excellent primer on installing grub’s stage1 file.


Other Caveats

Sometimes directories like /tmp are not backed up, so you might need to manually create some of them when using a backup copy as the basis of virtual machine conversion. The temp directory /tmp can be tricky because of special permissions.

Create /tmp directory


  1. Great web site. Lots of helpful info here. I am sending it to some buddies ans additionally sharing in delicious. And obviously, thank you to your effort

Post a Reply

Your email address will not be published.