Vmware shrinking virtual disks.

Thu, 17 Dec 2015 (tags:linux, windows, vmware)

I have been dealing with this in past and forgot about it. So when I needed to shrink drive it got me stuck for moment. So I decided to make a blog so I will not forget. Problem is that shrinking straight away will not work. When deleting something in guest you will leave file there and data will stay on drive, you will just remove the record poiting to the file. But shrinking tool can't tell what is used by filesystem and what is deleted file. So first you have to wipe the delete files and then shrink. This script will do it.

#!/bin/sh
#https://www.vmware.com/support/ws55/doc/ws_disk_manager_examples.html
 
cd /home/fredy/vmware/Windows\ 7/
 
echo "-----Listing partitions for virtual drive"
vmware-mount -p Windows\ 7.vmdk
 
echo "-----Mounting virtual drive"
mkdir mountForShrink
vmware-mount Windows\ 7.vmdk 2 ./mountForShrink/
 
echo "-----Preparing for shrink"
vmware-vdiskmanager -p /home/fredy/vmware/Windows\ 7/mountForShrink/
vmware-mount -x
 
echo "-----Shrink"
vmware-vdiskmanager -k Windows\ 7.vmdk