Friday, February 19, 2010

Direct Booting a VHD in XenServer

By:Andy Paul
Running XenServer, you may run into instances where you needed to directly mount and boot a VHD file in XenServer. I have encountered this several times, including migrating a virtual server from Hyper-V to XenServer as well as updating XenTools and Provisioning Tools for Citrix-based deployments.

The following process will take you through preparing a storage repository in XenServer and importing your VHD file for direct boot.
PART I - Creating an EXT3 DRIVE

VHD files require an NFS or EXT3 formatted storage repository. The standard install of XenServer creates a local storage repository using LVM format. You can destroy this and create an EXT partition instead. In my XenServer farms where I am using shared storage, I like to create at least one host with an EXT drive for flexibility.
Please note, this will also destroy ANY VMs on that partition, so proceed with caution.
  1. Connect to your XenServer command line interface. You can use XenCenter for this, but I like to use PuTTY for the copy/paste and scroll features.   
  2. Collect your necessary information:

    1. Find the default SR device ID (DEFAULT_SR_PHYSDEVS=) In a single disk system this should be /dev/sda3:  # cat /etc/xensource-inventory  
    2. Determine the UUID for your default SR: # xe sr-list type=lvm
    3. Determine the UUID your default SRs PBD your default SR: # xe pbd-list sr-uuid=your SR UUID (from step 2b above) 
    4. in a multi-host pool, you want to make sure you reference to correct host.  You can find this results step 2a under the label INSTALLATION_UUID= or run the command: # xe host-list
  1. Destroy the existing LVM partition:

    1. Disconnect the default SR: # xe pbd-unplug uuid=your PBD UUID (from 2c above) 
    2. Remove the default SR: # xe sr-destroy uuid=your SR UUID (from 2b above)
  1. Create EXT partition

    • # xe sr-create content-type="Local SR" host-uuid=[YOUR HOST ID] type=ext device-config-device=[YOUR DEVICE] shared=false name-label=" Local EXT3"
    • NOTE: This command takes a few minutes to run and will return the UUID of the new partion when complete.  Also, if you are on a single host system, you can tab after host-uuid= to poplate the host-id value 
    • Example Command: # xe sr-create content-type="local SR" host-uuid=0d1c9ba5-2304-46d9-8b75-459f41fb7f8a type=ext device-config-device=/dev/sda3 shared=false name-label="Local EXT3"
YOUR NEW SR IS READY TO USE AND SHOULD APPEAR IN XENCENTER

However, if you need to define a default SR, such as in a single host / single drive system, use the following:
  • Set the default SR: # xe pool-param-set default-SR=YOUR NEW SR UUID uuid=xxxxxxxx 
  • Set your SR as the default location for suspended VM images: # xe pool-param-set suspend-image-SR= YOUR NEW SR UUID uuid=xxxxxxxxxx

PART II - COPYING VHD FILES TO XENSERVER

  1. Connect to your target XenServer with an SCP Utility to copy the files. I have used WinSCP with good results.
  2. Copy to /var/run/sr-mount/[uuid of ext3 SR create in Part 1] 
  3. If using explorer mode of WinSCP, you can drag and drop your files to initiate the copy
IMPORTANT NOTE: MAKE SURE YOU COPY YOUR FILES TO THE CORRECT PARTITION!!!! (not the Root!)

PART III - DIRECT MOUNTING

  1. In XenCenter, create a new VM with setting similar to the configuration of the VHD you copied over.  DO NOT POWER ON THIS VM
  2. Using your SSH utility, note the name (UUID) of the new VHD file created by the wizard.
  3. Delete this file (UUID.VHD)
  4. rename your target VHD to this UUID name
  5. Power on your machine... and if everything goes right, VIOLA!
Your VHD is now imported and locally mounted.  Once you power on the VM, you can update drivers, files, etc. If you plan on provisioning this server, connect a new blank vDisk and use XenConvert to capture an updated image. If you have enough storage space, I recommend keeping this image on the server for future updates/captures.

Additional Reading:
blog comments powered by Disqus
Microsoft Virtualization, Citrix, XENServer, Storage, iscsi, Exchange, Virtual Desktops, XENDesktop, APPSense, Netscaler, Virtual Storage, VM, Unified Comminications, Cisco, Server Virtualization, Thin client, Server Based Computing, SBC, Application Delivery controllers, System Center, SCCM, SCVMM, SCOM, VMware, VSphere, Virtual Storage, Cloud Computing, Provisioning Server, Hypervisor, Client Hypervisor.