Posts tagged virtualization
Sorry, this entry is only available in Català.
This is the P2V method that we used to convert a physical Linux server to a virtual machine running on KVM. It is a quick virtualization method that dumps the entire disk over the network to a new host machine. Ideally the origin server should be stopped in order to boot in rescue mode, thus making the copy with unmounted file systems. In our scenario it was not possible to halt the physical server, and this procedure did the trick.
Copy the disc
At the origin server use dd to dump its disk. It is then compressed and sent to the netcat at port 43333 waiting with the command above. Gzip compresses the stream and reduces the amount of data to be transferred over the net. Our disk was 72 GB and took 4 hours to 10 Mbps, via the Internet.
Note: The syntax of nc depends on the package you have installed. In this example it is netcat-openbsd.
Review the file systems
Now you have a disk image named disk.raw in the desination server. But the origin server was accessing its filesystems while dd was reading: you should run an fsck of them. If you are lucky the filesystem should not be badly damaged.
In Linux you can configure a file to be treated as a device assigning it to a loop device. We check the next free loop device.
Assign disk.raw to loop0 and it can be accessed using /dev/loop0
Now read loop0 partitions and create appropriate devices to access it, we use kpartx.
The partitions are accessible via /dev/mapper/loop0p[n]. Do an fsck.
fsck.ext3 -f /dev/mapper/loop0p2
At this point you can mount the partitions to verify that the files are indeed there and maybe fix the device names in /etc/fstab.
Before starting the virtual machine, you need to undo this process to prevent damage to the filesystem.
losetup -d /dev/loop0
Create the virtual machine
Create a KVM virtual machine with disk.raw attached and try booting.
It may not boot because the device name of the disc may have changed and the kernel does not find the root filesystem. Using the KVM console you will have to fix the line in GRUB or LILO, correcting the root = option in the kernel line. When it finally boots remember to fix the boot loader and /etc/fstab.
In our case the physical device /dev/cciss/c0d0p[n] became /dev/hda[n] in the VM.
You must configure the new virtual network interface and verify that the services work properly.
During the virtualization the data on the original physical server has been updated and it must be synchronized before any real server change. So stop the service within a maintenance window, sync the data and then you can change DNS zones or whatever. Downtime has been minimized.