How to shrink a Windows VM in XenServer
When I was told that you could only grow (not shrink) the storage volume for a running Windows VM in XenCenter, I took that as a challenge. Guess what, there is a way to shrink it! Here is how:
- Use XenCenter to add a new disk to the existing VM, making it the size you want to srink the current server to.
- Select the VM from the list on the right, click Storage.
- Click “Add…” and create the new volume the size you want it.
- Log into the VM, (you can use the Console tab in XenCenter) and start ‘Disk Management’ and Initialize the new disk.
- You can find it in Start->Administrative Tools->Computer Management.
- Click on the new disk. Mine showed up as “Disk 1, Unknown… Not Initialized”.
- If you click on the words “Not Initialized” it will be selected.
- Next select Action->All Tasks->Initialize Disk. Select MBR and OK.
- Format a new partition on your new volume (you might be able to skip this step, did not try).
- Right click on the black “Unallocated” partition.
- Select “New Simple Volume”.
- Click Next twice, the size will be defaulted to the full disk, and specify a new drive letter.
- In my example, I use E:\.
- Format as NTFS using Quick Format, and click Finish.
- Once you see formatting finish, and the new partition turns blue and is marked “Healthy” (Primary Partition). Proceed to the next step.
- In the VM, download and run XenConvert.
- I used version 2.4.1.
- It requires Microsoft .NET v4.0, so you may need to download that from Microsoft and install it before running XenConvert.
- Start XenConvert and select From: Volume and To: Volume.
- Set the Source Volume to your boot drive (C:).
- Set the Destination Volume to your new drive (E:).
- Say “Yes” to the warning about losing free space.
- Click Convert, and accept the warning about erasing data on your Destination volume (E:)
- Go have a coffee, or something, and come back later.
- When XenConvert is finished, use “Disk Management” again in the VM to activate the new partition.
- Right Click the new partition and select “Mark Partition As Active”.
- Shut down the VM.
- I did this from inside the VM using Start->Shut down.
- Now re-order the drives on the VM so the new drive is in position 0.
- In XenCenter, select the VM, and select the Storage tab.
- Detach the original drive by selecting it and clicking the “Detach” button.
- Select the new drive, and click Properties, and set the Position to 0.
- Now you can boot the VM and voila! It’s now srunken to the size you wanted.
- If it all works the way you want it you can go delete the original drive in XenCenter to reclaim the space.
You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.
Thanks, Adrian! I was so close! I had done everything except mark the partition as active. Nice work. Thanks for the article. I will stick this into Evernote
Man, thank you very much. I´ve made it by my self to the finished volume to volume convertion, but i didn´t know what to do. The VM wasn´t able to boot, but now i realize…i have to make it active. I´ll try it tonight!.
Thanks for the hack! Having an oversized VM was driving me crazy.
Exactly what i was looking for. Thanks!
In my case i couldn’t change the drive letter of the new disk to the one of the old disk. It was because the where system files on that disk according the message. I converted the second disk to a third disk with the old drive letter and voila! Thanks again for sharing!