Friday, October 31, 2008

Online Backup of Hyper-V Virtual Machines - Part 2

These are the steps to do an online backup of your Hyper-V machines.

The process comprises of three parts.

1. Finding your "Microsoft Hyper-V VSS Writer" ID

2. Using DiskShadow to take a snapshot of the volume that your virtual machine resides

3. Copy the backup file to your destinated location


1. Finding your "Microsoft Hyper-V VSS Writer" ID

On your Windows 2008 Virtual Host, run command prompt in administrator mode.
Run the command vssadmin list writers. Take note of your "Writer Id".


Example:
C:\>vssadmin list writers
vssadmin 1.1 - Volume Shadow Copy Service administrative command-line tool
(C) Copyright 2001-2005 Microsoft Corp.

Writer name: 'Microsoft Hyper-V VSS Writer'
Writer Id: {66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}
Writer Instance Id: {fcb279d5-6271-44fb-a3ca-eb75c42e0804}
State: [1] Stable
Last error: No error


2. Using DiskShadow to take a snapshot of the volume that your virtual machine resides

What I did is to pass parameters in a text file to DiskShadow command.
These are what the parameters are doing.
The 'Delete Shadows volume G:' parameter delete any existing shadow copies if any.
Then ensure shadow copies will persist and turn verbose on.
Next is to add the volume that you want to backup. The volume should contain the virtual machine that you want to backup.
With the Writer ID you get from Step 1, let's verify that Hyper-V VSS Writer is included.
Next, the command Create will start the snapshot.
When Backup completes, use the Expose command to 'map' the snapshot volume to X drive.

Example below:
# Use DiskShadow cmdlet with parameters specified in the text file.
diskshadow -s c:\vmbackup.txt

Contents of vmbackup.txt
# DiskShadow script file to backup VM from a Hyper-V host
# First, delete any shadow copies of the drives. System Drives needs to be included.

Delete Shadows volume C:
Delete Shadows volume G:

#Ensure that shadow copies will persist after DiskShadow has run
set context persistent

# make sure the path already exists
set verbose on
begin backup

add volume G: alias VirtualDisk
add volume C: alias SystemDrive

# verify the "Microsoft Hyper-V VSS Writer" writer will be included in the snapshotwriter verify {66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}
create
end backup

# Backup is exposed as drive X: make sure your drive letter X is not in use
Expose %VirtualDisk% X:
Exit


3. Copy the backup file to your destinated location
The exposed X drive is just a snapshot drive of the volume. You need to copy the snapshot files to your backup destination to really have a backup copy of your virtual machines. Use robocopy command to copy the Virtual Machines files (.vmc, .vhd, and snapshot files) to your backup location.

Example:
robocopy x:\virtualmachines \\backupsvr\virtual-machines\hostserver /mir

Once you are sure that you have made copies of your virtual machine, remove the expose X drive.
unexpose X:

Done! Now you have completed a online backup of your Hyper-V virtual machines.
Next, I will show you how to log your backup process and send an email alert when the backup completes. Watch this space for Part 3.

Online Backup of Hyper-V Virtual Machines - Part 1

You must have created numerous virtual machines on your Hyper-V servers now. Ever consider how to do backup of your VMs?? Without shutting down or put your VMs on saved state?
Do not misunderstood snapshot as backup. No, snapshot is a point in time image of your virtual machine. You will lost everything if you lose the base machine.
There are a few methods that online backup works now.
1. Use Windows Server Backup that is shipped with Windows 2008. However, restoring can be hard with this option.
2. Stop the virtual machine or put it on saved state. Then copy the VHD and export the configuration files. This option is considering that you can stop this server.
3. Solutions from 3rd party vendors. For example, Symantec BackupExec 12.5 provides this option.
4. Use DiskShadow cmdlet plus some scripting.

Let me share with you how to use DiskShadow to do a online backup of your Hyper-V virtual machines.

Friday, October 24, 2008

Wednesday, October 22, 2008

Migrate Virtual Machine from Virtual Server 2005 to Hyper-V

This post is to illustrate how to migrate a Microsoft Virtual Server 2005 R2 Virtual Machine to Windows Server 2008 Hyper-V.

My Virtual Machine is a Windows 2003 Server and I did this on a box-to-box migration. It is easy, so enjoy!



Pre migration process:

1. The guest systems needs to be upgraded to the latest Service Pack (Vista SP1, XP SP3, Windows 2003 SP2).

2. Install Windows Server 2008 onto the new machine and install Hyper-V. (make sure it you installed any hotfixes for Hyper-V too)

3. Copy the VHD to the new Hyper-V box.

4. Setup a Virtual Network on the new Hyper-V server.



Migration Steps:

1. Open Hyper-V Manager and create a new Virtual Machine.

2. Type a Name for the VM and if desired, you can store the virtual machine in a different location.

3. Specify the amount of Memory to assign to this VM.

4. Assign a Network Adapter.

5. Select "Use an existing virtual hard disk" and select the .VHD file to migrate.

6. Click Finish and start the new Virtual Machine.

7. The new VM will begin detecting and installing new hardware. If prompted to install an Unknown Device, select "Ask me again later".


*I suggest to go through the below steps although it might have to effects on some platforms


8. Uninstall the Legacy Virtual Machine Additions from Add/Remove Programs.

9. Update the HAL. Click on Start, type "msconfig", click on Boot Tab, Advanced options. Check the box "Detect Hal". Then click OK to save and OK to exit msconfig.

10. Now restart the Virtual Machine.

11. Next step is to install Microsoft Hyper-V Integration Components on the new VM. Connect to the console of the Guest system, click Action, Insert Integration Services Setup Disk. Run "Install Microsoft Hyper-V Integration Components".

12. You will get a warning that you need to upgrade the HAL. Click OK. Restart the system when installation completes.

12. You will prompted to reboot again. Reboot again and you should now boot up to your migrated Virtual Machine.

Hosting Redhat Linux Virtual Machine on Hyper-V

These are the steps to setup a RedHat Linux virtual machine on Hyper-V host.
I get this working with the help from other bloggers and my colleague.
This post is an amended version from another blog.

Pre-requisites
Please note that I am using RHEL 5.2 x86_64 and you must have a valid RHN installation number. The RHEL VM is installed as a 64bit machine and please install all packages, meaning install everything. It is also helpful to have a RHN Account so that you can get yum update from rhn.redhat.com. Note that for that “yum” command to work with RedHat Linux, you must be subscribed to their update service so that you can fetch the package, or else you will have to go and find them on your installation DVD/CDs.
You first need to fetch a copy of the ISO image from the zip of the Linux Integration Components.
You will also have to download the kernel source RPM and copy/ftp it to your RHEL VM. You can get this from ftp://ftp.redhat.com/pub/redhat/linux/enterprise/5Server/en/os/SRPMS/kernel-2.6.18-92.el5.src.rpm.

Configuring the Virtual Machine
There are steps needed to get this Redhat Linux Virtual Machine working. So please follow this closely. Open Hyper-V Manager and add a Network Adapter, a Legacy Network Adapter and a SCSI Controller with a Hard Drive attached to you RHEL VM. Ensure the Legacy Network Adapter is assigned to the virtual network that contains your physical external network card.

Linux Integration Components RC2
Using the “Media” menu in the Hyper-V “Connect...” window, choose “DVD Drive”, “Insert Disk...” and select the Linux Integration Components ISO image, “LinuxIC-RC2.iso”. Then run
mkdir -p /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
cp -rp /mnt/cdrom /opt/linux_ic
umount /mnt/cdrom

Building the Kernel
Let's do a update to ensure that we have the required packages installed. (requires your network is working and have a valid RHN account)
yum install redhat-rpm-config gcc rpm-build make gnupg

Go to the directory where you store the kernel source RPM and install the SRPM with the command:
rpm -ivh kernel-2.6.18-92.el5.src.rpm

You need to edit the spec file in /usr/src/redhat/SPECS/kernel-2.6.spec., so make a backup copy of it first for safety.
Before the “%build” line, insert this line:
patch -p1 -d ../linux-%{kversion}.%{_target_cpu} < /opt/linux_ic/patch/x2v-x64-rhel.patch Next find the line that sets “with_headers” and change it to%define with_headers 0 Find the line that defined “%define with_xen” and change it to%define with_xen 1 and the line containing “%define with_xenonly” and changed to%define with_xenonly 1 You can now build the RPM, which will construct the xen one which is what you need. So cd /usr/src/redhat/SPECS rpmbuild -ba kernel-2.6.spec Be warned, this will take *hours* on a on a virtual machine.

Installing the Kernel
cd /usr/src/redhat/RPMS/x86_64
rpm --force -ivh kernel-xen-2*rpm
rpm --force -Uvh kernel-xen-devel-2*rpm

Build the x2v version of the kernel
cd /opt/linux_ic
perl setup.pl x2v /boot/grub/grub.conf

Reboot, and it should boot your newly built kernel with the X2V shims in place.

Building the Hypervisor, Network and Storage Drivers
The next step is to build the drivers. First, link the "build" link in /lib/modules/ directory to make it point into the kernel source that you have been building from.
Note: Please note that in the preceding commands, the quotes are single backquotes, not apostrophes or anything else.
cd /lib/modules/`uname -r`
ln -nsf /usr/src/kernels/`uname -r`-`arch` build

Build the Drivers
cd /opt/linux_ic
Edit setup.pl and look for the string “kernel-devel”. Change that to “kernel-xen-devel” and save the file.
perl setup.pl drivers

Reboot and you should now have the drivers running.

Building the X Mouse Driver
The last step is to build the mouse driver for use by X. This is very simple, you just need to install a couple of extra packages with
yum install xorg-x11-server-sdk xorg-x11-proto-devel
cd /opt/linux_ic
cd drivers/dist
make inputvsc_install

We are done! You now have the Linux IC installed on your Redhat Linux 5.2 vritual machine.