Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Howto Shrink a Thin Provisioned Virtual Disk (VMDK) | Virten.net https://www.virten.net/2014/11/howto-shrink-a-thin-provisioned-virtual-d...

Home About Homelab VMware vSphere 6.7 NSX vSAN Tools

RSS Feed
Howto Shrink a Thin Provisioned Virtual Disk (VMDK)
Posted by fgrehl on November 24, 2014 Go to comments Leave a comment (25)

Thin provisioned disks are a great feature to save capacity as you virtual machines filesystem will never
use the full capacity. I do not know a single system where you do not have at least 10GB of free space for
OS disks. I am not considering databases, applications or fileservers which will grow constantly. Having thin Enter your email address to subscribe to this blog and
receive notifications of new posts by email.
provisioned disk is usually no longer a performance problem so it is a valid design choice even
in production.

A common issue with thin disks is that the size will grow when required, but never shrink. When you
require the capacity only once you might want to get it back from the virtual machine. This post describes
how to reclaim unused space from the virtual machine.

Advertise Here
Virtual Machine Preparation (Windows)

Windows does not automatically zero deleted blocks. Microsoft provides a tool that can zero blocks after
while deleting a file or zero out the entire free space. This is required to reclaim space back from the
VMware ESXi SCSI Sense Code Decoder
virtual disk. VMware ESXi Release and Build Number History
Free ESXi 6.7 - How to Download and get License
1. Download SDelete Keys
2. run sdelete.exe -z [Drive] Free ESXi 6.5 - How to Download and get License
Keys
Create a Bootable ESXi Installer USB Flash Drive

Wait a couple of minutes until the process is finished. Please note that you virtual disk file (VMDK) will
grow to the full size during the process.

Virtual Machine Preparation (Linux)

Linux does not zero deleted blocks too. There are various tools available to create zeroed blocks. The best
known tool is dd which should be available on all systems.

1. Identify free space with df


2. Fill the free space with dd

vma:/mnt/data # df -h
vma:/mnt/data # dd bs=1M count=8192 if=/dev/zero of=zero

This website uses cookies to give you the best online experience. By using our website you agree to our use of cookies. Accept

1 of 5 2/19/2020, 2:12 PM
Howto Shrink a Thin Provisioned Virtual Disk (VMDK) | Virten.net https://www.virten.net/2014/11/howto-shrink-a-thin-provisioned-virtual-d...

file (VMDK)©will
Copyright 2020grow to the |full
Virten.net size during| Impressum
www.v13g.de the process.
/ Privacy Policy | Powered by WordPress and zBench ↑ Top

Shrink VMDK File

1. Power off the Virtual Machine, or disconnect the virtual Disk you want to shrink
2. Connect to the ESXi Host with SSH
3. Navigate to the Virtual Machine Folder
4. Verify disk usage with du
5. Run vmkfstools -K [disk]
6. Verify disk usage with du

root@esx3:/vmfs/volumes/ds1/vma $ du -h vma_1-flat.vmdk
7.9G vma_1-flat.vmdk

root@esx3:/vmfs/volumes/ds1/vma $ vmkfstools -K vma_1.vmdk


vmfsDisk: 1, rdmDisk: 0, blockSize: 1048576
Hole Punching: 25% done.

root@esx3:/vmfs/volumes/ds1/vma $ du -h vma_1-flat.vmdk
1.9G vma_1-flat.vmdk

Share:

Share

Related posts:

1. Identify Disk Usage of a Thin Provisioned Virtual Disk


2. Identify and solve ineligible disk problems in Virtual SAN
3. Disable Virtual Machine Swap File (.vswp)
4. Howto Install VMware tools on a virtual ESXi
5. Migrate E1000 Adapter to vmxnet3 with Linux Virtual Machines

Virtualization ESXi, Howto, Troubleshooting

← Identify Disk Usage of a Thin Provisioned Virtual Disk Reuse VSAN Claimed Disks as VMFS Datastore →

nd December 18, 2014 at 8:35 pm


Reply
thank you! an important part that my eyes had first bypassed is that we hole-punch the small
.vmdk, not the -flat.vmdk

Josh December 22, 2015 at 3:23 pm


Reply
Excellent post! I am going to do this on a volume that is 1.2TB - any ideas how long that will
take? I need to build a communication for the environment on how long the VM will be down.
Thanks!

Reply
This website uses cookies to give you the best online experience. By using our website you agree to our use of cookies. Accept

2 of 5 2/19/2020, 2:12 PM
Howto Shrink a Thin Provisioned Virtual Disk (VMDK) | Virten.net https://www.virten.net/2014/11/howto-shrink-a-thin-provisioned-virtual-d...

You can do it completely without downtime with Extrasphere disks (not VM) migration to another
datastore even on free licensed ESXi host.

sPatial January 16, 2017 at 2:05 pm


Reply
Thanks for sharing this useful info. I have a question after applying these steps. flat.vmdk size
has been decreased but VM Provisioned Storage is still showing the same size as original
flat.vmdk. Please let me know how I can reduce this size as well? Any help is highly appreciable.
Than You.

Reply
T Jardine April 10, 2019 at 12:01 am

Was wanting an answer to this as well.

Reply
T. Jardine April 10, 2019 at 1:09 am

Once you migrate to another host the provisioned storage reflects the shrunk size (so
migrate to another host and back again). Note: without vMotion you'll need to have the
VM powered off for the duration.

Reply
fgrehl April 18, 2019 at 11:23 am

Provisioned storage is the amount of space the disk can grow to. So it's correct that it
does not decrease when shrinking disks.

Reply
T. Jardine April 18, 2019 at 5:48 pm

Sorry, typo. The actual VM "Storage Usage" size is properly reflected in the vSphere
UI. Provisioned size obviously does not change.

Oliver Hirsch May 3, 2017 at 10:23 am


Reply
Important addition regarding the Linux preparation step: the "dd" command creates a file named
"zero" inside the current directory with the given size (8GB in your example) because of the
parameter "of=zero". Therefore not only the virtual disk (VMDK) grows up but also the virtual
drive inside the guest gets used nearly 100%. So you should mention that the file "zero" must be
deleted after shrinking to free up the filled space inside the guest!

Raimond Barbaro June 22, 2017 at 7:41 am


Reply
Shouldn't the --punchzero switch be used along with the vmkfstools -K command, as advised
here:
http://pubs.vmware.com/vsphere-
51/index.jsp?topic=%2Fcom.vmware.vsphere.storage.doc%2FGUID-CBF31A6B-B36F-4552-
B512-CC92B1943902.html

Reply
fgrehl June 25, 2017 at 1:29 pm

"-K" is the short version for "--punchzero". You don't have to use both switches.

Reply
Raimond Barbaro June 25, 2017 at 7:13 pm

Thanks for your reply. How do you know this? It's not in VMware's own
documentation on that page I linked. Can you please provide a source?

Thanks
Raimond

Reply
fgrehl June 25, 2017 at 7:19 pm

It is a common notation that the short and a long command is in the


documentation and in manpages. Using both does not work:

[root@esx4:/vmfs/volumes/57604a1d/pixel] vmkfstools -K
--punchzero pixel.vmdk
Failed to open virtual disk '--punchzero': The system
cannot find the file specified (25)
[root@esx4:/vmfs/volumes/57604a1d/pixel] vmkfstools
--punchzero pixel.vmdk
vmfsDisk: 1, rdmDisk: 0, blockSize: 1048576
Hole Punching: 0% done.
[root@esx4:/vmfs/volumes/57604a1d/pixel] vmkfstools -K
pixel.vmdk
vmfsDisk: 1, rdmDisk: 0, blockSize: 1048576
Hole Punching: 0% done.

Raimond Barbaro June 25, 2017 at 7:30 pm

Ok thanks.

Reply
This website uses cookies to give you the best online experience. By using our website you agree to our use of cookies. Accept

3 of 5 2/19/2020, 2:12 PM
Howto Shrink a Thin Provisioned Virtual Disk (VMDK) | Virten.net https://www.virten.net/2014/11/howto-shrink-a-thin-provisioned-virtual-d...

time.

Brad July 7, 2017 at 9:31 pm


Reply
Does the required steps require you to have the same amount of space available on the datastore
already to complete this? Our datastore has no space and we have no place to move the 2TB
VMDK file. So would we need 2TB free on the datastore to do this to reduce the space?

Anon July 8, 2017 at 7:45 am


Reply
It is NOT recommended to zero Linux ext[234] filesystems by just using dd (it's simple but will
degrade the filesystem). Please see https://unix.stackexchange.com/a/251804/134856 for
references for why this is the case and for a list of alternatives.

Grant September 24, 2017 at 4:11 am


Reply
I've tried this on a server I want to shrink in size. I used SDelete -z to zero out the drives which
increases the used storage to the full size of the disks but now when I run vmkfstools -K on the
vmdk files it completes but they do not get any smaller and I am stuck with a server that is
consuming almost 1TB on disk when it only has about 100GB of data on it's drives. Any idea
why the vmkfstools command isn't working for me? Using ESXi 6.0 and all the drives are thin
provisioned.

Reply
Grant September 24, 2017 at 4:24 am

Oh nvm my last post, I was using ls -l to view the files but that shows the full
provisioned size. du -h *.vmdk shows the actual disk usage size which was being
shrunken correctly.

Rocket September 27, 2017 at 3:54 pm


Reply
Hi,

hope somebody can help.


Is there any way to check if a Virtual Disk (VMware) was used or teated with "sdelete.exe -z" ?

I can not remember on which VMs i executed "sdelete.exe -z"

I would like to shrink the Virtual Disks because I need to safe as much space as possible on my
Storage where the VMs are running.

Can somebody help?

Thank you :-)

Ptal May 25, 2018 at 7:54 pm


Reply
Hi,

Is it possible to reduce the disk size to a specified size as i dont see any option to reduce to
specific size.

Thiago Carmo September 5, 2018 at 2:01 pm


Reply
Thank you for this article. That was very helpful for me and solve my problem. PS: This
procedure do not shrink the VMDK provisioned size, only the VMDK file size.

Presley Brenner December 11, 2019 at 9:45 pm


Reply
Thanks!!

Markus January 16, 2020 at 12:31 pm


Reply
Somehow, this didn't work...

It's a Linux-VM with a thin-disk of 8GB. In use are ...GB.

On the ESX 6.0u3 I can see it has 8GB:


8589934592 Jan 16 11:10 SLES-WEBSVR-flat.vmdk

After zeroing:
#> dd if=/dev/zero of=/test.dat bs=4k
#> rm /test.dat
#> poweroff

I shrink the disk:


#> vmkfstools -K SLES-WEBSVR.vmdk
vmfsDisk: 1 rdmDisk: 0 blockSize: 1048576

This website uses cookies to give you the best online experience. By using our website you agree to our use of cookies. Accept

4 of 5 2/19/2020, 2:12 PM
Howto Shrink a Thin Provisioned Virtual Disk (VMDK) | Virten.net https://www.virten.net/2014/11/howto-shrink-a-thin-provisioned-virtual-d...

I'd welcome any thoughts and hints!

cheers!

Reply
Markus January 16, 2020 at 12:37 pm

Sry, forgot the "in use" value:

in use are 5.1GB, meaning the "shrink" should result in a 2.9GB lower .vmdk file size

NOTE - You can use these HTML tags and attributes:


<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote
cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike>
<strong>

NAME

EMAIL

Website URL

Notify me of follow-up comments by email.

Notify me of new posts by email.

SUBMIT

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to give you the best online experience. By using our website you agree to our use of cookies. Accept

5 of 5 2/19/2020, 2:12 PM

You might also like