Showing posts with label p2v. Show all posts
Showing posts with label p2v. Show all posts

2011-12-06

P2V RedHat 6

While virtualizing a RedHat RHEL 6.2 machine, I've made a pleasent discovery: after cloning the disk, the VM booted without any initrd rebuild.
The source was an HP BL460 G7 and the target VM was created with the VSphere wizard using a typical Red Hat 6 x64 configuration: version 7 vm, paravirtual scsi, vmxnet3 networking.
The VMDK was created as big as the source physical disk.
I've followed the procedure for RedHat 5 P2V, with one notable exception: the internal disk on RedHat 6 is called /dev/sda even if it's really a SmartArray RAID drive.
After the ssh command:

# ssh root@P "cat /dev/sda | gzip -1 | cat" | gzip -d >/dev/sda

I've simply rebooted the VM and it came up on the first try.

2011-12-01

Live Linux P2V

Here's how to clone a live, powered-on machine to a VMWare VM.

The test case scenario is a conversion from an HP BL460 to a Version 4 ESX VM, with LSI Logic parallel virtual SCSI controller and one e1000 vnic.
Linux version is Red Hat 5.5 x64
UPDATE: I've made some encouraging experiments with 6.2 also

Important: this method does not guarantee data consistency, as the disk will be copied while active, but it's usually good enought to bring up a bootable copy of the source machine where you can later restore a consistent backup.
On the other hand, this procedure gives way less downtime than a cold clone, and you can test the cloning process without halting the source machine.

Onward I will call the source machine "P" and the destination machine "V".

Take note of the P disk configuration

# fdisk -l /dev/cciss/c0d0

Disk /dev/cciss/c0d0: 146.7 GB, 146778685440 bytes
255 heads, 32 sectors/track, 35132 cylinders
Units = cylinders of 8160 * 512 = 4177920 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d0p1               1          25      101984   83  Linux
/dev/cciss/c0d0p2              26       23961    97658880   8e  Linux LVM

This is an HP machine with a SmartArray controller.

Create a new VM, called V, with a disk at least as big a the P one: in this case I've created a 147GB vmdk.
Boot the V VM into rescue mode.

boot: linux rescue

Start the network interface and assign an IP enabled for SSH with the P machine.
Skip searching for existing installations.
All the following commands are to be executed on the V machine.
Now dump the P hard drive to the V vmdk:

# ssh root@P "cat /dev/cciss/c0d0 | gzip -1 | cat" | gzip -d >/dev/sda

note that this compresses the data over the wire, as this usually leads to faster transfers, even more if the disk has many empty sectors.

After completion, an fdisk should display the same partition table of the P machine on the V machine

# fdisk -l /dev/sda

Disk /dev/sda: 157.8 GB, 157840048128 bytes
255 heads, 32 sectors/track, 37779 cylinders
Units = cylinders of 8160 * 512 = 4177920 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          25      101984   83  Linux
/dev/sda2              26       23961    97658880   8e  Linux LVM


Reboot V into rescue mode again

boot: linux rescue

This time choose to search for existing installations, as it should find the new disk content.

# chroot /mnt/sysimage

Make sure the LVM has seen the new disk

# pvscan

PV /dev/sda2       VG VolGroup00   lvm2 [93.13 GB / 59.13 GB free]

If you don't see the PV, check /etc/lvm/lvm.conf for any filter other than the default one.

Modify the boot modules list taking as an example those of another identically configured VM.
This is the modprobe.conf of a tipical ESX VM.

# vi /etc/modprobe.conf

alias eth0 e1000
alias scsi_hostadapter mptbase
alias scsi_hostadapter1 mptspi
alias scsi_hostadapter2 ata_piix

Rebuild the initial ram disk, as referenced in the grub.conf

# mkinitrd -v -f /boot/initrd-2.6.18-194.el5.img 2.6.18-194.el5

Reinstall grub, just to be safe (it should be already there from the disk cloning process).

# grub-install /dev/sda

Now note that, after reboot, the V machine will start with the same IP address of the original P one.
If it doesn't suit your need, change the IP address in /etc/sysconfig/network-scripts/ifcfg-eth0
Now you can reboot the V machine.

If the M machine was at runlevel 5, the V machine may start with corrupted graphics because of the different video driver of the VM.
Switch to runlevel 3 and reconfigure X with

# system-config-display --reconfig

Now you can proceed with vmware-tools installation as usual on VMs.

2011-08-17

Linux V2P

Virtualization may be the best thing since the microprocessor itself, but sometimes you may have to backtrack your own footsteps.
Here are the steps to convert a Red Hat 5.5 linux vm running on an ESX to a physical box:

Using a disk imaging tool, dump the vmdk of the vm to the internal disk of the target machine.Boot the physical box with the Red Hat CD in rescue mode
Do not mount any partitions, but select "continue" to jump into the shell.

Mount the restored partition:

#chroot /mnt/sysimage

edit the modules list and put every driver the physical machine needs.
you can see which drivers are needed by looking at modprobe.conf from another machine that has the same hw as the one you are V2P-ing.
if you don't have another machine, you can use the same target machine: just before imaging it with the source vmdk, install it from scratch with the Red Hat CD and take note of the resulting modprobe.conf

#vi /etc/modprobe.conf

here is the one i used as a reference (an HP machine)

options bnx2x disable_tpa=1
alias eth0 bnx2
alias eth1 bnx2
alias eth2 tg3
alias eth3 tg3
alias scsi_hostadapter cciss
alias scsi_hostadapter1 lpfc
alias scsi_hostadapter2 usb-storage

then you will have to rebuild the initrd image to include the needed drivers.
note that kernel version number must match the one used on your vm.

/sbin/mkinitrd -v -f /boot/initrd-2.6.18-164.el5.img 2.6.18-164.el5

and reboot.
at boot time you will probably get some errors on X initialization because the graphic card has changed: just answer yes at the reconfigure option and select 800x600 as default resolution.

Update: if you are looking for P2V instead, look at this post.