Skip to main content

How to shrink a virtual disk

XCP-ng doesn't support VDI (Virtual Disk Image) shrinking, only growing. However, there are solutions to achieve the same result, albeit with some manual steps.

Windows VMs

There are two options to do this. The most reliable is the Clonezilla method, but the XenConvert route might also work.

XenConvert

  1. Attach a disk of the desired size to the VM.
  2. Within the VM: Format this new disk in NTFS (quick format).
  3. Install and start XenConvert: select the system disk (probably C:) and set the newly formatted disk as the destination.
  4. Acknowledge the warning that the destination disk is smaller than the source.
  5. Wait for the copy process to complete.
  6. Using the Windows Disk Management tool, set the partition of the new disk to "Active" status.
  7. Shut down the VM.
  8. Detach both disks, then reattach the new disk so that it is in position 1.
  9. Start the VM.

CloneZilla

tip

Use the i686 version of Clonezilla to avoid boot issues on the ISO while using a Windows template.

Pre-requisites

warning

It seems that doing a dism /Online /Set-ReservedStorageState /State:Disabled first (before anything else) is required on Windows to get a succesful partition shrink and avoiding any data loss.

  1. Identify the partition you want to move to the new disk and then shut down the VM.
  2. Create a new drive of the smaller size you want in this VM.
  3. Switch the VM to BIOS mode.
  4. Get the Clonezilla ISO available in your ISO SR and insert it.
  5. Check the boot order to ensure it's CD drive and then HDD.

Steps

  1. Boot the VM.
  2. Select "Start CloneZilla."
  3. Choose "device-device," meaning CloneZilla will copy from one disk to another, which is our goal.
  4. Select "Expert Mode."
  5. Choose "Disk to local disk" mode.
  6. Select the origin disk (the bigger one).
  7. Then select the destination disk (the smaller one).
  8. In the advanced options, make sure to unselect "-g auto."
  9. Also select "Don't check the source filesystem."
  10. Use the "-k1" option (Create the partition table proportionally).
  11. Finally, select "-p poweroff" once the copy is done.
  12. Start the cloning process!

When it's done:

  1. Eject the Clonezilla CD.
  2. Switch back the VM to UEFI.
  3. Detach the bigger disk (keep it as a backup in case something goes wrong).
  4. Boot the VM.

Linux VMs

You can use the same Clonezilla method. However, since "everything is a file" in Linux/BSDs, you can also use rsync to migrate the files from the original system to the new one.