<

HOW TO: Shrink a VMware Virtual Machine Disk (VMDK) in 15 minutes

Published on
217,811 Points
179,010 Views
43 Endorsements
Last Modified:
Awarded
Andrew Hancock (VMware vExpert / EE MVE^2)
MVE^2, Expert of the Year 2016-2011, Scribe 2016-2012, Author of the Year 2016,2013-2012 VMware vExpert 2016-2011 27 years of experience.
HOW TO: Shrink a VMware Virtual Machine Disk (VMDK) in 15 minutes

In my previous Experts Exchange Articles, most have featured Basic and Intermediate VMware and Virtualisation Topics.

If you would like to read my Basic VMware articles,  they are listed here for your convenience.  

During this series of articles VMware released VMware vSphere 5.5 and VMware vSphere Hypervisor ESXi 5.5. These articles are also applicable to VMware vSphere Hypervisor ESXi 5.x and 5.5. For consistency, I have used VMware vSphere Hypervisor ESXi 5.1 through this series.


Increasing the size of a VMware Virtual Machine Disk (VMDK) is straightforward, and is supported in the vSphere Client, by selecting the virtual hard disk, and increasing the size using the up arrow. or typing in a new value. Please see my previous Experts Exchange article:


Resize - VMDK.jpg
However, although there is a down arrow present, you cannot shrink the disk in this way, it's not supported. The only supported method of shrinking a VMware virtual machine disk (VMDK) is to use VMware vCenter Converter Standalone and create a virtual to virtual (V2V) conversion, a similar process to a Physical to Virtual (P2V) conversion.

Please see my previous Experts Exchange articles


V2V Disadvantages
V2V Conversions can be slow.
You need to ensure, you have enough datastore storage space for the new virtual machine disk.
The virtual machine is converted, so there is a small risk, the conversion can cause issues with the converted virtual machine.
The converted machine can contain a different MAC address.
V2V are prone to failure.

V2V Advantages
Support end-user method of re-sizing a virtual machine disk.
GUI Interface when using VMware vCenter Converter Standalone

After reading and understanding this article, you will be able to reduce the size of virtual machine disks in less than five minutes. I will let the reader decide if this is a faster method than the traditional practice of using a V2V, to change the size of a VMware Virtual Machine Disk (VMDK). On occasion we come across an installation, where an Administrator has assigned a 2TB virtual disk, and does not have the space to create a V2V!

In this article we will show you HOW TO: Shrink a VMware Virtual Machine Disk (VMDK) in 15 minutes

I feel this is a little more advanced, so I've not included it in the Basic VMware article series.

Before your start the following procedure, please ensure you have a valid and tested Full Backup of your virtual machine. This does not mean a VMware Snapshot.

Also check to see the virtual machine is NOT running on a Snapshot disk, If unsure please refer to my Experts Exchange Article


The following procedure is split into two parts

Shrink the Operating System partition - This is covered in Step 1.
Shrink the VMware Virtual Machine Disk (VMDK) - This is covered in Step 2

1. Login to the Virtual Machine and shrink the OS Partition

Before we can shrink the VMware virtual machine disk (VMDK), we need to shrink the OS partition. (to avoid file system corruption). In this example I am using Windows 2008 R2, which has a shrink function. If you are using another OS, please see the other 3rd party partition utilities which are available, they are listed in my Experts Exchange article Using an RDP (Remote Desktop Protocol) connection or connect via the Console, using the vSphere Client, login to the virtual machine as an Administrator.
Logon to the Virtual MachinePress Control-Alt-Delete to login to the virtual machine.
Right Click My Computer and Select ManageRight Click My Computer and Select Manage
Select Disk ManagementSelect Disk Management, and select the partition you need to shrink.
Right Click VolumeRight Click the Volume/Partition to shrink, and select Shrink.
Shrink Disk QueryThe above dialogue will briefly appear whilst the file system is queried.
Shrink C:the above dialogue will appear. Enter a size to reduce the OS partition.

In this example the VMware virtual machine disk (VMDK) is 40GB, and we would like to reduce the size of the VMware virtual machine disk (VMDK) to 20GB. The Disk Management utility scans the available file system, and reports a maximum size the OS partition can be reduce by, this is based on current file system usage.

Enter the figure 19.5 (GB) x 1024 = 19968
Shrink SizeOS Partition size after Shrink Operation.
Disk Manager after Shrink OperationAs can be clearly seen in the above screenshot, there is now an unallocated 19.5GB space on the virtual disk, in Step 2 the VMware virtual machine disk (VMDK) will be "chopped", removing this unallocated storage space, and finally reducing the virtual machine disk (VMDK) to 20GB. Providing that we DO NOT affect the existing partitions, this is a safe operation. So in effect the "cut" will be made in the unallocated storage space, after the OS partition.

2. Reducing the size of the VMware Virtual Machine Disk (VMDK)


Login and connect to the VMware vSphere Host ESXi server which hosts the virtual machine.

see my previous Experts Exchange articles


Power OFF the Virtual Machine, and change to the datastore path where the VMware virtual machine disk (VMDK) is located.

cd /vmfs/volumes/<datastore name>/<VM foldername>
VM Folder PathWe need to edit the *.vmdk, which is the descriptor file, which contains the variables for the size of the *.-flat.vmdk. Using cat, this is what the descriptor file contains
VMDK Descriptor fileThe number highlighted above, under the heading #Extent description, after the letters RW, defines the size of the VMware virtual disk (VMDK).

this number - 83886080, and it's calculated as follows:

40 GB = 40 * 1024 * 1024 * 1024 / 512  =  83886080

We wanted to reduce the size of the VMware virtual machine disk (VMDK) from 40 GB to 20 GB. So the value we need to enter into the descriptor file is:-

20 GB = 20 * 1024 * 1024 * 1024 / 512  =  41943040

Using vi, edit the descriptor file, and change the number from 83886080 to 41943040, and save the file.
VMDK Edited with viMigrate or Copy the virtual machine to another datastore, if you do not have the migrate option, see my Experts Exchange article here


After the virtual machine disk (VMDK) has been moved, you will notice the disk size reflects the desired size of 20GB.
Size of virtual disk, as viewed from vSphere ClientSize of virtual disk as viewed from consoleAfter restarting the virtual machine, and checking with Disk Management, you will notice the 19.5GB unallocated storage space, has been removed, and disappeared.
Size of virtual disk as viewed from Disk Management in the OS
Congratulations, you have successfully Shrunk a VMware Virtual Machine Disk (VMDK)

****************************************************************************
Thank you for reading my article, please leave valuable feedback. If you liked my VMware article and would like to see more Articles from me, please click the Yes button near the: Was this article helpful? at the bottom of this article just below and to the right of this information. Thank You. Do not forget if you have a question about this article or another VMware, Virtualisation, Windows Server 2012 question, why not post a Question for me and the other Experts Exchange Experts in the VMware, Virtualisation, Windows 2008, Windows 2012 Zones. I look forward to hearing from you. - Andy :- twitter @einsteinagogo
****************************************************************************
43
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
38 Comments
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
Todd

Okay, moved what do you think of the placement now?

Andy
0
 
 

Administrative Comment

by:lherrou
Andrew,

Congrats, the page editors agree that your article is worthy of the Experts Exchange Approved award for your excellent work.

LHerrou
Experts Exchange Editor
0
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
Todd

That's excellent news.

I've got many more......

Andy
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:Todd Reibling
Andrew,
I ran through your instructions, but some reason the disk space is not reduced in my edit settings > provisioned size.

Any ideas what I am doing wrong?  I even went back and did a cat of the .vmdk file and the settings are as they should be.  I reduced the disk number from 209715200 to 104857600.
0
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
@Todd, PLease post a question, and myself or other experts will be glad to assist.
0
 

Expert Comment

by:Todd Reibling
Andrew,

I ran through your instructions and yet the setting for the hard drive hasn't decreased.  Do you know why the number is not able to be decreased in the disk provisioning section?

http://screencast.com/t/yGxmU8fLzu

http://screencast.com/t/6QU5d88NA
0
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
@Todd, Please post a question to the VMware Zone, and myself or other experts will be glad to assist you with your issue, and work through the issue.
0
 

Expert Comment

by:itezcouk
Hi, there seems to be a contradiction to what you are saying in the article and the steps involved...

"On occasion we come across an installation, where an Administrator has assigned a 2TB virtual disk, and does not have the space to create a V2V!"

but one of the tasks is to move the vm to another datastore.

"Migrate or Copy the virtual machine to another datastore, if you do not have the migrate option, see my Experts Exchange article here"

I'm in the exact situation that Im unable to complete a storage VMotion due to not having enough space on the san (vm is 8TB) we have 500gb free
0
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
@itezcouk

With only 500GB available, your options are limited, please see this article

HOW TO: Shrink or Reduce a VMware Virtual Machine Disk (VMDK) using VMware vCenter Converter Standalone v5.5.2

Please post a new question if you want to discuss these options.
0
 

Expert Comment

by:Varun Tiwari
very good and helpful article
0
 

Expert Comment

by:Raja Inayat
Hi Sir Andrew

I am stuck in a problem of  vendor's pre-configured Datastore Disk which occupied all 1TB storage under Thick provisioning. I want to reduce the size of this  Datastore file which I cant as I dont find any shrink option as the Hardisk Size is un-editable please see attached screen shot.  Kindly guide me as I am new to VMware machine System. My Regards: Raja Inayat Assistant Professor, Department of Physics, University of Peshawar.
1
 

Expert Comment

by:Raja Inayat
Please see attached file

VMWARE-Veeam.png
1
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
@Raja Inayat Please post a question to the VMware Zone.
0
 

Expert Comment

by:hasayeret
Andrew, just so I understand: if I do the SSH/Putty way which is the none convertor way, do I still need to copy the new edited VM to a different datastore or can the shrink still happen within the datastore without moving the VM anywhere?

Thanks!!!
0
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
@hasayeret Please post questions in the VMware Zone, so they can be answered by experts. tagging questions onto the article comment page, is not going to get your Questions Answered, as no other members or Experts, get the benefit.

So take the time, to post a question, in the VMware Zone.

Thanks
0
 
LVL 20

Expert Comment

by:compdigit44
Excellent article as always!!!!

Two questions, in the example 40 GB = 40 * 1024 * 1024 * 1024 / 512  =  83886080
what can you break down the numbers? Why are you multiplying 1024 twice? Also when the VMDK file reduce is the white space freed up on the datastore?
0
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
Hi compdigit44

I'm glad you asked.

The formula to find the R value is actually

R = Gx1024x1024x(1024/512) 

Open in new window


or

R = 2097152*G 

Open in new window

 

You can also work out R (approx value), if you do not know the size of disk from cylinders, heads and sectors (this is a bit old school, when we worked in the physical realm, and knew heads, cylinders and sectors counts of disks, and had to write BIOS in PC to match MFM and RLL disks (SCSI) as well. (this is circa early 8o's)

R = (  (  ( cylinders + 1 ) x512 x sectors x heads ) /1024  )  - 8  )  x  2  ) 

Open in new window


R = ( ( ( 5221 +1) x 512 x 63 x 255 ) /1024 ) -8 ) x 2)

Open in new window


R = 83891414

(R = 83886080) (5334 diff!)

so close...

The space should be given back to the datastore, depending upon SANs, you may need to use a unmap command and reclaim the space. But as this process requires you to Storage vMotion and move the virtual machine disk from one datastore to another, it's just like any other storage vMotion so the space will be made available instantly, and the new virtual machine disk, on the new datastore will be smaller. (because of your adjustment).
1
 
LVL 20

Expert Comment

by:compdigit44
Very interesting do the values in the equation are the cylinders, heads and sectors now since we are talking about a virtual hd VMware much use some default values here since it is not directly present the HD to the VM correct? Are there any VMware KB's on this..

Once again great feedback!!!
0
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
virtual cylinders, virtual heads and virtual sectors.

This is not really VMware, but related to file systems, disk partitions, from early Unix and DOS, and VMware just used them to define their virtual disk geometry.

I'll see if there are any KBs.
0
 

Expert Comment

by:vpadala
Hi Andrew,

This  is very help full to me  i am able to decrease the drive size with the above procedure .
But here we are getting another issue like when we trying to increase hard disk again using vsphere client it throwing an error i am attaching error screen shot .
ESX version 6 and we are using vsan 6.

Virtual machine working without any issue
error.JPG
0
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
@vpadala

Please post a question in the VMware Topic Area and myself or other Experts will be glad to assist.
0
 

Expert Comment

by:kanky
Andrew, great info, nowere in the network is the same info you placed here. Im stuck at the step to use the vi command line. Could you set me an example of what exact line should i place on the vi editor, to do this type of change from xxx Gigas to xx Gigas? Thanks in advance
0
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
@kanky

Please post a question in the VMware Topic Area, and myself or other experts will gladly assist you.

This way other members benefit, from the Answer.
0
 

Expert Comment

by:kanky
Andrew, no worries, I wa sable to find the soluton. Moving the VM, hoping it shrinks as stated. Thanks in advance
0
 
LVL 13

Expert Comment

by:George Sas
Great article thank you.

One thing to add maybe. No need to move the machine from one host to the other, if you reboot your VM, the disk size will be the modified one.
0
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
@George

Thanks for your comments

Many methods are available..... removing and re-adding the disk removing and re-adding the VM!

.....
0
 
LVL 13

Expert Comment

by:George Sas
@Andrew

I just mentioned this because at the end you say :
"Migrate or Copy the virtual machine to another datastore, if you do not have the migrate option, see my Experts Exchange article here"

Just wanted to point out that there is no need to move it.
I am not a VM expert and I was just about to migrate it when I realized I have no space (that's why I want to shrink it). So I was looking for an extra disk or something when I thought I can just try and reboot and see if this does the trick :)
Anyway , your article saved me some precious time and space. Thanks again.
1
 
LVL 8

Expert Comment

by:Senior IT System Engineer
Thanks Andrew for the great article :-)

Yes, I still need to manually perform offline svMotion the VM after the VMDK descriptor change, because the VM Edit Settings HDD still showing the old HDD size.

Note:
I'm on ESXi 6.0U2 Essentials Plus edition.
0
 

Expert Comment

by:IT Q
Thanks for the interesting article.

We would like to reduce a 2TB vmdk (ESXi 5.1) but we noticed that the size is 4294967294 instead of 4294967296 as expected by multiplying 2048 * 1024 * 1024 * 1024/512.
Why two sectors are missing?
Wanting to reduce vmdk to 1900 GB how should we consider the difference of the two sectors?
Thanks again.
0
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
@IT Q, please post a question to the VMware Topic area, and we can discuss.
1
 

Expert Comment

by:Jack Howarth
Great article! How do you begin to edit the descriptor file, what is the command?
The way I tried said "VI out of memory", so I'm assuming I'm doing it wrong.

Many thanks,
0
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
@Jack Please post a question and myself or other Experts will be glad to answer.
0
 

Expert Comment

by:Tecnologia Tecnologia
Hello @andrew i did itall and worked it, but i don't know how to say to the vpshere client that can use that new space for another virtual machine. However that the shirk virtuales machine reflects the updated size, the file *.vmk in the datastore it still occupies the same amount of mb. Can you tell me if you can back the new free space that was shrinked to the original datastore?
0
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
Please post a question.
0
 

Expert Comment

by:Paul Kien
Good Job! Thanks for that! Works for me!
0
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
no problems.
0
 

Expert Comment

by:Ben Stephenson
I have to shrink a volume for a client at some point so I have been doing research and came across this article. Out of all the methods I have seen, this definitely looks like the best (and easiest way). Hopefully it goes well when I perform the work! Question out of curiosity. What is the importance of moving the VM (or vmdk at least) to a different datastore, or at least coping and pasting the files per the other article you referenced? Will the vmdk not actually change sizes until that happens, or will VMware not update the provisioned size? Either way, why is that the case? Thanks again for posting this article!
0
 
LVL 120

Author Comment

by:Andrew Hancock (VMware vExpert / EE MVE^2)
Will the vmdk not actually change sizes until that happens, or will VMware not update the provisioned size? Either way, why is that the case? Thanks again for posting this article!

Correct. Because it's a hack!

If you want more help, with ref. to this Article, please post a question, and we can discuss.

Thanks for reading.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Join & Write a Comment

Teach the user how to use configure the vCenter Server storage filters Open vSphere Web Client:  Navigate to vCenter Server Advanced Settings: Add the four vCenter Server storage filters: Review the advanced settings: Modify the values of the four v…
Teach the user how to configure vSphere clusters to support the VMware FT feature Open vSphere Web Client: Verify vSphere HA is enabled: Verify netowrking for vMotion and FT Logging is in place or create it: Turn On FT for a virtual machine: Verify …

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month