Can you believe that in the post virtualization era that some people are still deploying application servers on physical systems? Anyways, here is my p2v method for moving Win2008 R2 systems to XenServer/XCP using all free software
Requirements
This P2V method I think is one of the most flexible I’ve used. It’s not an online method though, meaning you’ll need some down time for the server you are going to migrate. Here is what you’ll need:
- Console access to the source computer
- A server running DBRL based on Debian Squeeze
- A CIFS or NFS share with enough storage to hold your images
- A VM with sufficient storage storage equivalent to the used space on the source
- A copy of the Windows 2008 R2 installation media
Essentially this method uses DRBL (more about DRBL here) to reboot both the target and source into a diskless Linux environment. Once in the environment we:
- Mount the external storage
- Backup the data
- Resize the source filesystem(s) and partition(s) (optional)
- Dump the partition layout
- Backup the data again (only if you’ve resized)
- Restore the partition layout, data and mbr to the target
After that, the data is there but the target is not yet bootable. We will need to reboot the target system into the Windows recovery environment to resolve that problem. Lets begin!
Step 1: Install DRBL on a Debian Squeeze VM
If you aren’t familiar with DRBL, then please allow me to introduce you to the equivalent of a swiss army knife for the infrastructures I manage. A full DRBL howto is out of scope for this how to, but I use it for so many things, including running my SCST images for providing storage. It’s really REALLY powerful.
I’ve tried DRBL on other distros besides Debian/Ubuntu and I think that it works best on Debian. The reason being that Debian and Ubuntu seem to have a greater variety of tools available and they actually work (e.g don’t segfault)!
Install Debian Squeeze any way you’d like and be sure to also install qemu-img
, screen
and testdisk
. Then mosey over to the DRBL site and follow the installation instructions for Debian. Its easy and painless but you’ll have to READ lol.
Note: DRBL installs dhcp server related packages on your system. If you have an existing dhcp-server in your environment, after you’ve installed drbl and run drblsrv -i
then feel free to remove those packages. You’ll need to execute a few extra steps which include configuring your existing DHCP server’s option 66 and 67 parameters, telling DRBL to not care about the dhcp server’s name by running /opt/drbl/sbin/mknic-nbi -c n
and properly setting the starting IP address and number when running /opt/drbl/sbin/drblpush -i
.
One other thing is to pay careful attention to the DRBL option that asks about using swap space on server. Ensure you select “no”. As a matter of fact, just pay attention to questions asked when running drblpush
. Let me know if I can help with anything here.
Step 2: PXEboot your source Windows 2008 R2 VM and do “stuff”
Change your BIOS settings so that the server boots from the network. Once the system is up, log in and mount your external storage. Once its mounted, take a backup using ntfsclone
. Here is an example of the syntax required: ntfsclone -s -o /media/sda1_backup.img /dev/sda1
. Now here is the fork in the road.. do you need to resize your ntfs filesystem?.
Servers today have massive GB storage options from the vendor. The minimal SATA HDD size offerings today are between 250GB and 500GB, and in many cases, on simple application servers, you’ll only use 10 – 20 percent of that storage. Virtualization is about efficiency and reducing costs and only giving systems what they need to get their jobs done. It seems silly to allocate 1TB of storage to a VM if it’s only going to use 2% of that UNLESS you have thin provisioning enabled and in use on your SAN.. which pretty much mootifies this whole conversation 🙂
Anyways, so if env | grep RESIZE_IS_TRUE
returns false for you, go onto to step 2, otherwise, determine the minimal size for your partitions then run ntfsresize
to resize them. Here is an example: ntfsresize -s11000M /dev/hdc2
.
Once you’ve resized, you then need to then resize the underlying partition. Run the command ntfsresize
with the --info
flag against your resized device and grab the bytes value from the line that reads Current volume size:
. Divide that number by 512 and put that into a notepad somewhere. Now run the command sfdisk -d
against your device and redirect the contents to where you’ve mounted the external storage. Here is an example: sfdisk -d /dev/hdc > /media/hdc_disk.txt
That command will dump the partition table of the device to a text file. All you need to do is modify the size
column for the partition(s) you’ve resized. Again, make sure you’ve divided the number from ntfsresize
by 512. Once you’ve modified the file, we need to modify the device’s partition table. To do this, run the sfdisk
command against your device and redirect the modified file you created with the -d
flag. For example: sfdisk --force /dev/hdc < /media/hdc_disk.txt
.
You'll notice that I'm using a "force" flag. This is because sfdisk complained that it didn't like the new partition table because the end of the partition is not on a sector boundary. Too bad sfdisk.. this is happening whether you like it or not lol!
After you've resize, you should reboot the server and when it comes back up, take another backup using ntfsclone
to a new file. You'll have to add the --force
flag because the resizing operation has marked the filesystem as dirty and only the Windows chkdisk utility seems to be able to change this.
Once you have your images, time to boot up your target.
Step 2: PXEboot your target Windows 2008 R2 VM
I simply created a VM using the Windows 2008 R2 template and set it to boot from the network. Once the VM boots into DRBL, ssh into it, mount your external storage and restore the partition table to the disks on the VMs using sfdisk
. Use the same syntax you used to write the modified changes to the source. Once that is done, you'll need to restore the images. Here is an example:
ntfsresize -r -O /dev/hdc1 /media/hdc1_disk_resized.img
. Run the appropriate command(s) for all your partitions.
Next you'll need to restore the mbr. I generally use testdisk
for this. It has saved my bacon soooo many times!
Run the command with the 2nd argument being the device you need to modify (e.g. xvda). Following the menu, Create a new logfile, select "Intel" as your partitioning type and select "MBR Code". Once you've done this for your boot disk, shutdown the VM, change it to boot from CD/DVD and "insert" your Windows 2008 DVD ISO.
Step 3: Fixing boot error in Recovery
Here is what you need to to:
- Boot the VM from the ISO
- Select the keyboard layout and etc, Next
- Click Repair your computer
- Select the operating system to repair, Next
- Click Command Prompt
- Unassign drive letters from all volumes
- Run
bcdedit
Use diskpart
to "remove" the drive letters from all mounted volumes except for the X device which is your DVD tray and assign each volume it's appropriate letter. The problem that I've noticed is that in the Recovery environment, Windows will mount that 100MB system partition as the C: drive.
Once you've corrected this, you need to run the bcdedit
command as follows:
bcdedit /set {bootmgr} device partition=C:
bcdedit /set {default} device partition=C:
bcdedit /set {default} osdevice partition=C:
Once you've run those commands, shutdown the VM and set your VM to boot from the Hard Disk. It should hopefully boot up without issue. Once it's up, install the xstools and reconfigure your nics.