I covered this in the past here:
Reclaim unused space from VMDK – Zewwy’s Info Tech Talks
But this time I wanna covered it a bit differently. Things I noticed:
- A proper VM with VMtools installed, and thin provisioned will automatically shrink the overall size being shown and used on disk on the ESXi browser.
Yet for some reason after I used the SCP method to move a VM from one host to another (frowned upon as it secretly converts it from thin to thick). Yet even after migrating to a new datastore specifying thin, it still show as full disk usage on the host.
I know is less checking the VM itself via it’s console/terminal whatever:
In my old blog post I mentioned “using DD” but not showing for stating how at all, Googling this I found this thread with an interesting answer:
“The /zero-Tag is actually a file name. The command just copies zeros from the virtual File /dev/zero (infinite number of zeros) into /mnt/hdb/zero until the disk is full, or some other error occurs.
This is why you have to remove the file /mnt/hdb/zero after that in order to regain the unused space.
However, a better way to fill free space with zeros (on ext2,3,4 file systems) is to use a tool called zerofree.”
Oooo zerofree?
Huh, something created (a tool) for exactly the task (job) at hand. Great!
Error, how classic, complained path is mounted RW, like yeah and?
Ughhh, google? virtualbox – zerofree on ubuntu 18.04 – Ask Ubuntu
Step 1) Reboot into ubuntu recovery console, hold down [Perfect ESC keystroke]
K how do I get into Advanced Grub boot? Holding Shift did nothing, if I mash ESC I get grub> (notices tiny flicker of Grub menu).. great I have to Mash ESC only once perfectly in a less then 1 second boot window… man give me a break… Once in I see advanced option as stated by the answer.
Step 2) advanced options -> recovery mode -> root console
Step 3) find the root directory
mount | grep "sda"
Step 4) run zerofree
echo "u" > /proc/sysrq-trigger mount /dev/mapper / -o remount,ro zerofree -v /dev/sda1
Step 5) reboot
Checking the ESXi host… what it went up 2 gigs, da fuq man…
Step 6) Compress Disk.
In my previous post this was to vMotion to datastore or use holepunch option which from what I can tell this the -K option, which I dont’ think can be used on a live VM, and a storage vMotion can’t be done. without vCenter. Since I’m temp working without a vCenter server, let’s try the holepunch option, this will require shutting down the VM, but since the zerofree required it anyway down time was already in play.
On the ESXi host:
[root@Art-ESXi:~] vmkfstools -K /vmfs/volumes/Art-Team/VM1/VM1.vmdk vmfsDisk: 1, rdmDisk: 0, blockSize: 1048576 Hole Punching: 100% done.
Oh noooo I’ve tainted my results… checking the web UI the space has gone back done to stating 20 Gigs like the first snippet… but doing a du -h on the flat file shows it is only the 10 Gigs as expected it to be:
Well I don’t know what to make of this discrepancy…
Huh, I found this post of someone doing the exact same thing around the time I wrote my original post but simply used the command:
dd bs=1M count=8192 if=/dev/zero of=zero
I have no clue how output file of zero means the disk… guess you can try that too, then holepunch the VMDK just like I did.
There.. I shutdown the VM again and this time did my ol trick to vMotion a VM without vCenter, and after re-registering the vMotion (between two datastores) it finally showed up with the correct space in the UI. 🙂
Hope this post helps someone, it’s been covered many times in the past.