使用SDelete回收ESXi thin磁盘空间
使用SDelete回收ESXi thin磁盘空间
查看windows镜像vmdk大小
[root@localhost:/vmfs/volumes/5880ad3e-148f09d2-a1cf-c81f66e3b84b/Windows2012-Standard-bit64-testsdelete] du -sh *
0 Windows2012-Standard-bit64-testsdelete-0877e10f.hlog
4.0G Windows2012-Standard-bit64-testsdelete-f9884cb1.vswp
20.8G Windows2012-Standard-bit64-testsdelete-flat.vmdk
1.0M Windows2012-Standard-bit64-testsdelete.nvram
0 Windows2012-Standard-bit64-testsdelete.vmdk
0 Windows2012-Standard-bit64-testsdelete.vmsd
8.0K Windows2012-Standard-bit64-testsdelete.vmx
0 Windows2012-Standard-bit64-testsdelete.vmx.lck
8.0K Windows2012-Standard-bit64-testsdelete.vmx~
1.0M vmware-1.log
1.0M vmware.log
在创建windows2012虚机的时候,我指定的是64G的空间,但是由于我使用了thin的方式,可能实际上只分配了12GB的空间(还有12GB的空间预留着,并没有从存储上真正分出去)。但后来随着windows2012文件越来越多,那这时候我发现空间不够了,进行了删了操作,你以为在ESXi 存储上这删除的空间应被释放了,其实不是的,这部分空间还是真正划分给了windows2012虚机。这是因为这个delete操作是在guest OS中进行的,而hypervisor并不知道这个动作,所以也就不会reclaim space。所以,我们会发现虽然在创建虚机的时候使用thin的方式,但是到后来后端存储空间还是消耗的很快。
首先要在Guest系统上,把所有没用的数据写零
Linux主机,执行:
dd if=/dev/zero of=/bigemptyfile
rm /bigemptyfile
Windows,执行sdelete.exe:
下载地址:https://docs.microsoft.com/zh-cn/sysinternals/downloads/sdelete
Usage: sdelete [-p passes] [-s] [-q] <file or directory> ...
sdelete [-p passes] [-z|-c] [drive letter] ...
USING SDELETE
Parameter Description
-a Remove Read-Only attribute.
-c Clean free space.
-p passes Specifies number of overwrite passes (default is 1).
-q Don't print errors (Quiet).
-s or -r Recurse subdirectories.
-z Zero free space (good for virtual disk optimization).
sdelete -c -z C:\
执行完成后,关闭系统,开始压缩硬盘文件
VMware:
vmware-vdiskmanager -k my_hd.vmdk
ESXI:
vmkfstools --punchzero [DISKNAME].vmdk
执行操作
[root@localhost:/vmfs/volumes/5880ad3e-148f09d2-a1cf-c81f66e3b84b/Windows2012-Standard-bit64-testsdelete] vmkfstools --punchzero Windows2012-Standard-bit64-testsdelete.vmdk
vmfsDisk: 1, rdmDisk: 0, blockSize: 1048576
Hole Punching: 100% done.
#执行操作完成后,再次查看大小
[root@localhost:/vmfs/volumes/5880ad3e-148f09d2-a1cf-c81f66e3b84b/Windows2012-Standard-bit64-testsdelete] du -sh *
0 Windows2012-Standard-bit64-testsdelete-0877e10f.hlog
8.6G Windows2012-Standard-bit64-testsdelete-flat.vmdk
1.0M Windows2012-Standard-bit64-testsdelete.nvram
0 Windows2012-Standard-bit64-testsdelete.vmdk
0 Windows2012-Standard-bit64-testsdelete.vmsd
8.0K Windows2012-Standard-bit64-testsdelete.vmx
1.0M vmware-1.log
1.0M vmware.log