Difference between revisions of "Shrinking VMware Virtual Disks"

From Nearline Storage
Jump to navigation Jump to search
m
m
 
(One intermediate revision by the same user not shown)
Line 11: Line 11:
 
**Open a terminal window
 
**Open a terminal window
 
**vmware-toolbox-cmd disk list
 
**vmware-toolbox-cmd disk list
**vmware-tool-box-cmd disk shrink /
+
**vmware-toolbox-cmd disk shrink /
  
 
In ESXi:
 
In ESXi:
Line 36: Line 36:
 
**Locate and change to directory that contains the guest's VMDK file
 
**Locate and change to directory that contains the guest's VMDK file
 
**vmkfstools --punchzero ''<guest>''.vmdk
 
**vmkfstools --punchzero ''<guest>''.vmdk
 +
 +
[[Category:Linux]]

Latest revision as of 15:42, 31 December 2019

The guest cannot have snapshots and it cannot be marked as a template from which clones are made.

In VMware Workstation:

  • For Windows guests:
    • Start the guest system and log in
    • Open a command prompt window in administrator mode
    • C:\Program Files\VMware\VMware Tools\VMwareToolboxCmd.exe disk list
    • C:\Program Files\VMware\VMware Tools\VMwareToolboxCmd.exe disk shrink C:\
  • For Linux guests:
    • Start the guest system and login as root
    • Open a terminal window
    • vmware-toolbox-cmd disk list
    • vmware-toolbox-cmd disk shrink /

In ESXi:

  • For Linux guests using LVM volumes:
    The zerofree utility is much quicker than the old "dd if=/dev/zero" method and it does not expand the thin-provisioned volume to full size, but it requires that the partition be unmounted.
    • Download the systemrescuecd.iso and place it on one of the ESXi server's datastore volumes
    • Remove any snapshots
    • Modify the guest system's settings so that it boots from the ISO image
      • Change "Boot Options" to "Force BIOS Setup"
      • Set the CD drive to "Connected" and and point it at the ISO image
      • Restart the guest and, in boot settings, set it to boot from the CD ahead of the hard drive
      • "Save and Exit" to boot the guest into the systemrescuecd image
    • Activate the LVM volume that contains the root partition
      • Activate all volume groups
        lvm vgchange -a y
      • List all volumes and their volume groups
        lvm lvs --all
    • Zero out the root volume
      zerofree -v /dev/volume_group/volume
      in my case that's
      zerofree -v /dev/vg_ioc51prod/lv_root
    • Shutdown the systemrescuecd guest system
    • Modify the guest system's settings to restore the original boot settings
      • Remove the systemrescuecd.iso as the CD device
      • Change "Boot Options" to "Force BIOS Setup"
      • Power on the guest and set it to boot from the hard drive ahead of the CD in boot settings
      • "Save and Exit" to boot the guest to confirm that it still works
    • Shutdown the guest
    • SSH to the ESXi server
    • Locate and change to directory that contains the guest's VMDK file
    • vmkfstools --punchzero <guest>.vmdk