website stat

Convert a physical Linux to VMWare

I recently decided to convert a Linux installed on a physical machine to be run inside VMware, hosted on a much more powerful machine. Two reasons for this: 1) the host machine is quite powerful (2x Quad Core Xeon, 4GB RAM); 2) the Linux image was lightweight enough.

The process was quite simple. I started by installing the same version of Ubuntu (Ubuntu server 7.10) that I had previously installed on the physical machine. I could just use dd to make a full copy of the / partition and pray that the devices get correctly re-detected but this way was cleaner and safer. The Ubuntu installer detected all the virtual hardware and configured correctly.

Now it was time to make a raw copy of key directories like /var, /usr, /etc/, ... You can't copy the files while the target Linux is running so I just popped in a Ubuntu Live CD and mounted the target disk. To make things easier, I installed openssh-server on the Live CD Linux instance, mounted the target disk in /media/disk and issued the following command:

CODE:
  1. $ tar -zcvpf - --exclude=/proc/* --exclude=/dev/* --exclude=/media/* --exclude=/boot/* --exclude=/tmp/* --exclude=/var/cache/apt-get --exclude=/sys / | ssh root@new_host "cat> a.tar.gz | tar -xvvf a.tar.gz /media/disk"

The aforementioned command will tar gunzip all the relevant system directories, excluding device files and other system-specific settings.

When finished, you're almost done. The only thing left will be fixing the UUIDs that identify the partition blocks. Just issue a $ sudo vol_id --uuid /dev/sdaX for each partition and replace /etc/fstab and /etc/mtab accordingly.

And you're probably done. This is a very brief tutorial as this is directed for experts. You can fill in the gaps.


6 Responses to “Convert a physical Linux to VMWare”

  1. Hugo Nunes
    Published at March 4th, 2008 at 11:11 am

    You should check the February08 Linux Journal article ‘Virtualize a Server with Minimal Downtime’ at http://www.linuxjournal.com/article/9942

    With a Knoppix CD, rsyncs and some customization at the modprobe.conf and the initrd Kyle Rankin explain howto obtain a P2V with only 2 small downtimes.

  2. mlopes
    Published at March 4th, 2008 at 11:21 am

    Great insight Hugo, thanks!

    This machine is pre-production so I didn’t worry that much with the uptime ;-)

  3. Sérgio Carvalho
    Published at March 5th, 2008 at 12:43 am

    Small trick: You can copy the filesystem using the OS installed there, by issuing init=/bin/sh as a boot parameter to the kernel, and then manually configuring the network service. When init starts, the root filesystem is mounted read-only, so it’s safe to copy.

    Another option is to stop every daemon running on the machine and remount the root filesystem read-only (mount -o remount,ro /).

  4. mlopes
    Published at March 5th, 2008 at 12:44 am

    Thanks for the tips Sérgio.

  5. tony
    Published at March 17th, 2008 at 9:57 pm

    If I’m understanding the purpose of your comments about fixing the UUID’s, would an alternative be simply to add “–exclude /etc/fstab –exclude /etc/mtab” to the tar command, thus leaving in place the fstab and mtab created by the target’s OS install?

  6. mlopes
    Published at March 17th, 2008 at 11:28 pm

    tony,

    Yes, you understood correctly. I explained how to generate the UUID numbers for those that forget to backup those files (actually I didn’t forget to backup them, I just made the mistake of keeping the copy on /tmp/ and then restarting the machine :-).

    But you got a point, that keeps you safe from harm.