I have a thin-provisioned Ubuntu 18 VM on ESX 6 with one virtual disk that is using almost all the underlying physical disk (I have a new 4TB disk ordered to move to shortly). The VM filesystem is ext4 on LVM.
So, if I deleted a large file or files inside the VM, does Ubuntu/ESX re-use that now available space first, before expanding the virtual disk? Do I have to do something like zeroing the available space, or is this all taken care of at the ext4, LVM or ESX level?
More simply, can I get by by temporarily deleting some junk until the replacement disks arrive?
(I’m aware I could do this manually using vmkfstools or some such action normally, but I’m more curious that serious – this is my home lab).
Your guest OS doesn’t know or care that the disk is virtual and thin provisioned. It will delete and write files on the disk according to however the filesystem chooses to lay out the files, and you don’t really have much control over this.
Further, ESXi knows nothing about the files in the virtual disk. It is just an opaque blob of data to ESXi.
But since the virtual disk is thinly provsioned, the files comprising the virtual disk can be shrunk. There is a way for the guest OS to tell the host that it has deleted data in part of the disk and that that space can be freed. It is by mounting the filesystem with discard, the same way, in fact, that the OS tells an SSD that it has deleted data.
You should ensure that your filesystems are mounted with the
discard mount option in
/etc/fstab, and that in
/etc/lvm/lvm.conf the setting
issue_discards = 1 is set. Linux will then send up TRIM/UNMAP commands when you delete data, and ESXi will know that those virtual disk sectors are no longer in use.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.