Shell script that automates reducing unused free space (deflates) / resizing thin / thick VMDK disks with XFS filesystem.
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:
- ) Mount BUFFER and GUEST filesystems
- ) Create full filesystem dump using xfsdump for GUEST and store it on BUFFER (/mnt/buffer mounted disk)
- ) Repartition GUEST disk - delete existing LVM part.
- ) Script asks for new LVM partition parameters
- ) Restore XFS dump into new partition
- ) Calculate cut off extent for VMDK file https://virtualman.wordpress.com/2016/02/24/shrink-a-vmware-virtual-machine-disk-vmdk/
- ) Manually edit VMDK descriptor file
- ) Run "vmkfstools -i input.vmdk -d thin output.vmdk"
- ) 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
)
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.