Skip to content

Latest commit

 

History

History
63 lines (44 loc) · 2 KB

README.md

File metadata and controls

63 lines (44 loc) · 2 KB

vmware-vm-deflate

Shell script that automates reducing unused free space (deflates) / resizing thin / thick VMDK disks with XFS filesystem.

Result of unused free space deflation

Script uses buffer disk (Attach VmWare disk with ext/xfs for XFS file dumps storage)

Disk structure (default layout for CentOS):

- VmWare VMDK file (disk configuration file)
	- VmWare VMDK flat disk file (binary data)
		- Disk Partition Table
			- Primary 1 boot partition - UEFI BootLoader 
			- Primary 2 LVM member -  LVM
				- VOLUME GROUP (VG) CENTOS (name is configured in script)
					- LOGICAL VOLUME (LV) SWAP
					- LOCICAL VOLUME (LV) ROOT (name is configured in script)
						- XFS VOLUME / - root filesystem

Script has following algorithm:

  1. ) Mount BUFFER and GUEST filesystems
  2. ) Create full filesystem dump using xfsdump for GUEST and store it on BUFFER (/mnt/buffer mounted disk)
  3. ) Repartition GUEST disk - delete existing LVM part.
  4. ) Script asks for new LVM partition parameters
  5. ) Restore XFS dump into new partition
  6. ) Calculate cut off extent for VMDK file https://virtualman.wordpress.com/2016/02/24/shrink-a-vmware-virtual-machine-disk-vmdk/
  7. ) Manually edit VMDK descriptor file
  8. ) Run "vmkfstools -i input.vmdk -d thin output.vmdk"
  9. ) Attach output.vmdk back to VM

Usage:

Attach new VM and install: Linux debian 3.16

Shutdown target VM and attach its VMDK to fixer VM (/dev/sdc).

Attach second buffer virtual disk (/dev/sdb) Attach

Install packages:

	sudo apt-get install parted xfsdump xfsprogs lvm2

Run:

	sudo ./vm-deflate.sh

EDIT script configuration BEFORE run. BACKUP your data before resizing. NO responsibility for data loss.

Uncomment those two lines

 set -x
 trap read debug

if you want step by step disk editing commands tracing.