Once I reclaimed the hard drive space from my database, I had to shrink the hard drive in order to get my image smaller. Here is what I did.
Shrinking the Partition
I used a version of Linux called Knoppix. You can download it from here.
I never actually burned the image to CD. I just opened the properties of the CD drive in the virtual machine (while it was shutdown) and told it to use the iso image that I downloaded instead of the physical drive.
Determining the how small you can shrink the drive:
sudo ntfsresize --info /dev/sda1
Changing the size of the drive (test)
sudo ntfsresize --no-action --size=42831122432 /dev/sda1
Changing the size of the drive
sudo ntfsresize --size=42831122432 /dev/sda1
Changing the size of the partition
sudo fdisk /dev/sda
- m for help
- p for print (note the partition number and type/id)
- d for delete
- n for new partition (choose primary and same partition number and desired size +###M)
- t for changing the partition type/id
- p for print ( verify everything is the correct)
- w for write
Shrinking an Unshrinkable Hard Drive
The only way that you can get a smaller hard drive if you can’t shrink the drive is to copy the data to a new virtual drive.
Copy the partition table.
sudo dd if=/dev/sda of=/dev/sdb bs=512 count=1
Copy the partition itself.
sudo dd if=/dev/sda1 of/dev/sdb1
Note: I had to reboot between copying the partition table and the actual partition.
Shrinking a Shrinkable Hard Drive
Shutdown the virtual machine.
From a command window run:
"C:\Program Files\VMware\VMware Server\vmware-mount " m: c:\VirtualMachines\HCM90\Database.vmdk
"C:\Program Files\VMware\VMware Server\vmware-vdiskmanager.exe" -p m:
"C:\Program Files\VMware\VMware Server\vmware-mount " m: /d
"C:\Program Files\VMware\VMware Server\vmware-vdiskmanager.exe" -k WindowsServer2003Standard.vmd
Note: to expand, you would use the -x option
"C:\Program Files\VMware\VMware Server\vmware-vdiskmanager.exe" -x 30Gb WindowsServer2003Standard.vmdk