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.
- 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.
- Collect your necessary information:
- Find the default SR device ID (DEFAULT_SR_PHYSDEVS=) In a single disk system this should be /dev/sda3: # cat /etc/xensource-inventory
- Determine the UUID for your default SR: # xe sr-list type=lvm
- Determine the UUID your default SRs PBD your default SR: # xe pbd-list sr-uuid=your SR UUID (from step 2b above)
- 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
- Destroy the existing LVM partition:
- Disconnect the default SR: # xe pbd-unplug uuid=your PBD UUID (from 2c above)
- Remove the default SR: # xe sr-destroy uuid=your SR UUID (from 2b above)
- 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"
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
- Connect to your target XenServer with an SCP Utility to copy the files. I have used WinSCP with good results.
- Copy to /var/run/sr-mount/[uuid of ext3 SR create in Part 1]
- If using explorer mode of WinSCP, you can drag and drop your files to initiate the copy
PART III - DIRECT MOUNTING
- In XenCenter, create a new VM with setting similar to the configuration of the VHD you copied over. DO NOT POWER ON THIS VM
- Using your SSH utility, note the name (UUID) of the new VHD file created by the wizard.
- Delete this file (UUID.VHD)
- rename your target VHD to this UUID name
- Power on your machine... and if everything goes right, VIOLA!
Additional Reading: