This article discussed about how we can reclaim the free space for linux root partition that was implemented using thin provisioned disks in Linux VMware virtual machine (VM). Common advantages by implementing thin provisioned disks in VMware is the administrator are able to over-allocate storage because the provisioned thin disks consume only the space used. The concept of thin provisioning disk disregard either the operating system running on Linux or Windows. However, by using thin provisioned disks, you will find that vmdk file size still expands over the time whenever you install, uninstall or delete applications in VM. You will noticed that the vmdk file size does not shrink or return to its previous size. When this happens to the linux VM, we need to use zerofree utility to reclaim and shrink the free space. The following steps is mainly to reclaim free space for linux root partition, tested in CentOS 7 and RHEL 7.
1. Install “zerofree” on your virtualbox guest machine.
2. Run this command to boot into rescue mode :
# systemctl rescue
3. In the rescue mode, enter root password :
4. Mount the root partition as read-only. Then run zerofree command. Once zerofree command complete, kindly reboot the VM.
# mount -o remount, ro /dev/mapper/centos-root # zerofree -v /dev/mapper/centos-root
5. Do a virtual clone V2V using vCenter or vmkfstool command. You will notice the vmdk size reduce to only the space used.