A question that often comes up when working with Dynamic vDisk when using Citrix Provisioning Server is does PVS automatically shrink the vDisk or is there a built in method to compact them. Citrix PVS does not have a way to do this automatically but with a few steps this can save some disk space on your storage.
** Update: 9/23 You can find the PowerShell script to Shrink VHD files here
A good use case is lets say you clean up your images and remove old programs, installation files and things you no longer need, you will notice the file size does not go down. In order to maximize your storage investment, you want to keep these images as small as possible so you can do this on a regular basis.
This method can also be used to shrink any VHD files which are used by Hyper-V, Citrix PVS, and you can even configure Windows 2008 and Windows 7 to use VHD files.
- Make a copy of the VHD file that you have to compact
- Open Server Manager
- Expand Storage
- Right-click on Disk Management on the server.
- Select Attach VHD.
- Select the required VHD File (The VHD appears as a volume on the server.)
- Defragment the drive for performance and storage optimization. (After defragmentation and optimization, the data on the VHD is now all at the beginning of the disk and defragmented.)
- Detach the VHD from within Disk Management. (Ensure that you do not delete the VHD when you are detaching the VHD.)
- Run the DISKPART command from a command Window.
- Run the following commands, substituting the path to your VHD file
- select vdisk file =”c:pathvdisk.vhd”
- attach vdisk readonly
- compact vdisk
- detach vdisk
Coming soon I will write a script that will execute against a folder and compact all VHD files in the folder. Keep an eye out here for that script 🙂