Virtualising Linux machines

user-pic
Vote 0 Votes
Now for something a bit different.  I've been spending a happy day virtualising Linux machines on to VMWare - a process known as P2V (physical to virtual) conversion.  Here's the recipie, in the hope that it'll help someone else achieve the same thing.  The instructions below assume you've everything in one partition on the original machine; you'll have to repeat the dump and restore steps for each partition if not.  In my case, the partition with everything in on the physical machines was /dev/hda1 - the instructions below assume that to be the case, and that Grub's the boot-loader of choice.

  1. Dump the contents of the physical machine's hard drive to the box hosting the VMs.  To do this, stop as much stuff on the physical machine that you can, remove any extreanous cruft (e.g. vast log files from last year) and then:
    dump -b 256 -0uf - / | ssh -c blowfish root@vmware.host.machine dd of=/var/dump-identifier

  2. Create a new VM on your host.  Have it boot from a Knoppix LiveCD, and make sure it's got a big enough virtual disk attached for the data you'll be restoring.  If your original machine had an IDE drive, then configure your VM with one: you'll thank yourself later.

  3. Start your VM - type 'knoppix 2' at the Knoppix boot screen, and it'll boot in to text mode.

  4. fdisk /dev/hda and create two partitions.  Partition 1 for your data, set it to partition type 83, and make it bootable; partition 2 for your swap, set it to type 82.

  5. mke2fs /dev/hda1
    will create an ext3 filesystem on hda1.

  6. mount /dev/hda1
    mounts it.

  7. cd /media/hda1

  8. ifconfig eth0 inet <an IP address on the same subnet as the host>
    - if it complains that it can't assign the requested IP, ask again.

  9. ssh -x root@host "dd if=/var/dump-identifier" | /sbin/restore -rvf -
    copies the dump file from the host, and restores it in to the current directory, which is the root of /dev/hda1.

  10. grub
    we need to install Grub on the new disk.

  11. find /boot/grub/stage1
    will tell us where Grub thinks its first-stage boot doobrie lives - (hd0,0) in my case.

  12. root (hd0,0)
    setup (hd0)
    writes a new master boot record on the disk.

  13. Exit Grub.  We're nearly there; we just need to
    e2label /dev/hda1 /
    to tell Linux where to mount the partition, and
    tune2fs -j /dev/hda1
    to add a journal to it.

  14. Reboot, and, if you've got it right, you'll have a clone of your physical machine running under VMWare.

No TrackBacks

TrackBack URL: http://blog.softivr.com/cgi-bin/mt/mt-tb.cgi/13

Leave a comment

About this Entry

This page contains a single entry by David Knell published on December 20, 2008 6:27 PM.

Following me around was the previous entry in this blog.

SoftIVR and SQL is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.