Importing VHD Disk Images into XCP
Earlier today I needed to move a VHD disk image from VirtualBox into XCP, but couldn’t find an obvious way to do this. The
xe vdi-import command only seems to work with raw disk images, and I didn’t want to convert my VHD into a raw image only to have XCP convert it back to a VHD. What I ended up doing was creating a new VDI in an NFS storage repository, then overwriting the image.
The main caveat to this approach is that it only works with VHD images, and only with NFS repositories (at least that’s what I gather from the documentation).
Also, don’t blame me if something goes wrong and you accidentally wipe out your mission-critical disk image, or your XCP host, etc.
So here’s what I did:
- Get the SR ID:
SR_ID=$(xe sr-list type=nfs --minimal)
- Get the associated PBD:
PBD_ID=$(xe sr-param-list uuid=$SR_ID | grep 'PBDs' | sed -e 's/.*: //')
- Get the NFS path:
xe pbd-param-list uuid=$PBD_ID | grep 'device-config'
- Create an image, specifying an image size larger than the VDI:
VDI_ID=$(xe vdi-create sr-uuid=$SR_ID name-label='new image' type=user virtual-size=<image-size>)
- Mount the NFS export locally:
mount <nfs-server>:<nfs-path> /mnt
- Replace the VHD:
cp <your-vhd-file> /mnt/$SR_ID/$VDI_ID.vhd