Vmkfstools: Difference between revisions
Jump to navigation
Jump to search
→activehosts
m (→Examples) |
|||
(5 intermediate revisions by the same user not shown) | |||
Line 68: | Line 68: | ||
=== Examples === | === Examples === | ||
Export a VM disk in 2GB chunks, note that since ESXi 5.1+ the 2GB sparse driver is disabled. | ==== Export a VM disk ==== | ||
Export a VM disk in 2GB chunks, note that since [[Esxcli#enable_2GB_Sparse_disks|ESXi 5.1+ the 2GB sparse driver is disabled]]. | |||
vmkfstools -i /vmfs/volumes/storagename/YourVM/YourVM.vmdk -d 2gbsparse /vmfs/volumes/storage2/YourVM/YourVM.vmdk | vmkfstools -i /vmfs/volumes/storagename/YourVM/YourVM.vmdk -d 2gbsparse /vmfs/volumes/storage2/YourVM/YourVM.vmdk | ||
==== Check or repair a disk ==== | |||
-x, --fix -[check|repair] | -x, --fix -[check|repair] | ||
This option will check and/or repair the virtual disk in case of an unclean shutdown. | This option will check and/or repair the virtual disk in case of an unclean shutdown. | ||
Line 78: | Line 80: | ||
Disk is error free | Disk is error free | ||
==== Set a UUID ==== | |||
-J, --miscop [setuuid | getuuid] | -J, --miscop [setuuid | getuuid] | ||
'setuuid´ option creates a unique identifier (UUID) for the virtual disk and stores the UUID in the descriptor file of the | 'setuuid´ option creates a unique identifier (UUID) for the virtual disk and stores the UUID in the descriptor file of the | ||
Line 86: | Line 89: | ||
´getuuid´ option displays the UUID of the virtual disk. | ´getuuid´ option displays the UUID of the virtual disk. | ||
==== dumpfs ==== | |||
dumpfs can be used by specifying either "-D | --dumpfs" and specifying a VMFS volume, file or folder. | dumpfs can be used by specifying either "-D | --dumpfs" and specifying a VMFS volume, file or folder. | ||
Line 96: | Line 99: | ||
Addr <4, 0, 0>, gen 1, links 4, type dir, flags 0, uid 0, gid 0, mode 1755 | Addr <4, 0, 0>, gen 1, links 4, type dir, flags 0, uid 0, gid 0, mode 1755 | ||
len 1260, nb 1 tbz 0, cow 0, zla 1, bs 1048576 | len 1260, nb 1 tbz 0, cow 0, zla 1, bs 1048576 | ||
==== activehosts ==== | |||
activehosts can be used by specifying "--activehosts" and specifying a VMFS volume | activehosts can be used by specifying "--activehosts" and specifying a VMFS volume | ||
Line 104: | Line 107: | ||
(1): MAC address 00:50:56:92:3f:86 | (1): MAC address 00:50:56:92:3f:86 | ||
Reclaim disk space by returning unused blocks of data in the virtual disk to the host OS. | Displays the MAC address of the management interface of each host which is currently using the datastore. | ||
This is also what vSphere HA uses to see if a host is still active. | |||
==== punchzero ==== | |||
Since vSphere 5.1 there's an option to shrink disks besides the normally required storage vmotion. | |||
With the guest shut down you can run vmkfstools with the punchzero option. | |||
Reclaim disk space by returning unused blocks of data in the virtual disk to the host OS. | |||
Note that this will only work if your virtual disk is of type thin. | |||
Before running it you will also need to zero out the unused blocks of data in the guest OS. | |||
For a windows VM, you can use Microsoft's tool [http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx sdelete]. | |||
Run it as | |||
sdelete -z c: | |||
Note that the -z option is needed as of sdelete version 1.6 | |||
For a linux based VM, run a command like: | |||
cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill | |||
to zero out the unused space. | |||
Note of warning that you should stop database -and other disk intensive- services before running the above. | |||
Some more detailed descriptions and tips on zero-ing out data from your guest OS can be found at [[Shrink guest on hosted platform]] | |||
Example: | Example: | ||
# vmkfstools --punchzero | # vmkfstools --punchzero disk.vmdk | ||
vmfsDisk: 1, rdmDisk: 0, blockSize: 1048576 | vmfsDisk: 1, rdmDisk: 0, blockSize: 1048576 | ||
Hole Punching: 3% done. | Hole Punching: 3% done. | ||
After you're done and list the VM from within the console, it looks like nothing has changed, in this example the disk is 10GB in size. | |||
# ls -lh *.vmdk | |||
-rw------- 1 root root 10.0G Nov 27 20:58 disk-flat.vmdk | |||
-rw------- 1 root root 527 Nov 27 21:02 disk.vmdk | |||
If you use the command du however then you can see the difference: | |||
# du -hs *.vmdk | |||
4.3G disk-flat.vmdk | |||
0 disk.vmdk | |||
You can also use the vSphere Client data browser to see the effect of reclaiming disk space. | |||
If you try to run this command against a VM living on NFS storage you might end up seeing the following error: | |||
vmkfstools --punchzero myvmdk.vmdk | |||
Not a supported filesystem type | |||
The error is a bit confusing as you might expect vmkfstools to talk about the guest OS here, but it is actually reporting that NFS does not support the punchzero option. | |||
Your solution is to either move the vmdk by hand to storage not located on VMFS or use storage vmotion to migrate to non NFS storage. On moving using storage vmotion, the zero data is already being discarded. So you can just storage vmotion back afterwards and you have reclaimed the lost disk space. | |||
=== Links === | === Links === |