This post explains about the step by step procedure to expand the virtual machine VMDK size using vmkfstools. Prior ESX 3.5, There is no option to extend the virtual hard disk size from vSphere client. Virtual harddsik expansion can be done only via CLI with the help of vmkfstools command and also. Nov 9, 2015 - I next looked at the C: drive in the Windows 10 VM after the upgrade, and it. My huge Windows 2012 R2 Essentials VM, with several terabytes of VEB. I was now confident enough that SDelete/vmkfstools combo was likely.
- 7Edit VMDK Descriptor
Purpose
This article gives the steps to shrink a Vmware VMDK virtual disk file from command-line with the Vmware utility vmkfstools. As far as it's known this is an unsupported method and can defiantly corrupt or break you virtual disk. So, make a backup first and try at your own risk. It worked great for me after I figured it all out. I only had to restore from my backup clone once or twice until I got the steps worked out.
This was performed on ESXi 5.1 and a CentOS 6.3 VM root partition. The VM had three virtual drives. Each dedicated to the three primary volumes (root,boot,swap). Not using LVM. Meaning a separate virtual drive for all three volumes.
Example Configuration
- ESXi 5.1.0-838463 Host
- CentOS 6.3 x64 Guest
- Root partition is 100GB
- /dev/sdb1
- 29GB of space is used
Example Goal
- Reduce root partition to 50GB
STEP 1
Remove All Snapshots on Guest
Backup
- Power off the VM Guest
- Create a clone of the root virtual drive
- SSH to ESX Host
- Browse to VM folder
- /vmfs/volumes/datastorename/vmfolder
If all the Snapshots are removed general there shouldn't be any files with 00001 in the name. If there is, most likely something like a backup program has gone wrong and you'll need to repair the virtual disk/s first.
Shrink Partition
- Boot guest off of GParted Live ISO
- Select Root drive
- Re-size (Shrink) partition to 49GB = 1024 * 49 = 50176
- Apply changes
- Power Off the VM Guest
![Live Live](/uploads/1/2/5/8/125839527/999472229.jpg)
Edit VMDK Descriptor
If there are snapshots or possibly orphaned snapshots: the VMDK file will appear empty even if you run cat against it. Obviously that will need to be fixed before attempting this unsupported shrink method.
Math
Formula [X * (1024 * 1024 * 1024)] / 512
X = Resulting Size in GB
X = Resulting Size in GB
Example
[50 * (1024 * 1024 * 1024)] / 512 = 104857600
[50 * (1024 * 1024 * 1024)] / 512 = 104857600
From ESX Host CLI
- TO
- Save and Quit
In this example we're cutting the drive in half... so the easy math is 209715200 / 2
Clone Edited VMDK
Make a clone of the VMDK that is set to only Read and Write to a different size.
In this example when cloning it will stop at 50% during the clone because our new VMDK is half the size of the original.
Swap VMDK Files
Replace new shrunk VMDK for the original one.
Extent Partition to End
- Boot guest off of GParted Live ISO
- Select Root drive
- Re-size (Grow) partition to entire 50GB virtual drive
- Absorb 1GB unallocated space at end
- Apply changes
- Exit Gparted | Eject ISO | Reboot
![Vmkfstools windows liverpool Vmkfstools windows liverpool](/uploads/1/2/5/8/125839527/652828742.jpg)
Test
- Boot OS and test
- Remove back and original cloned VMDK files
Remove and Re-Add to Inventory
Lastly if all is well then remove the virtual machine from the ESX host inventory and add it back to correct the GUI readout of the size. Plus, fix it so if you wanted to use the GUI later to grow it.
- Power Off VM
- Login to with ViClient
- Right-Click on Guest
- Select Remove from Inventory
- Browse Datastore to virtual machine folder
- Right-Click on hostname.vmx
- Select Add to Inventory
- Follow prompts
Windows
The same steps can be used to shrink a Windows drive. With Vista/2008 and newer the disk manager can be used to change the size of the partitions instead of Gparted or Gparted can be used as well.
Related Articles
(HowTo) Grow a VMDK with VMKFSTOOLS
(HowTo) Convert a VMDK from Thick to Thin on ESX
(HowTo) Convert a VMDK from Thick to Thin on ESX
Retrieved from 'https://www.bonusbits.com/index.php?title=HowTo:Shrink_a_VMDK_with_VMKFSTOOLS&oldid=2277'
vmkfstools - vSphere CLI for managing VMFS volumes.
If <target> is a file system, <options> can be one of the following:
If <target is a virtual disk, <options> can be one of the following:
You use the vmkfstools vSphere CLI to create and manipulate virtual disks, file systems, logical volumes, andphysical storage devices on an ESX/ESXi host. You can use vmkfstools to create and manage a virtual machine file system (VMFS) on a physical partition of a disk and to manipulate files, such as virtual disks, stored onVMFS-3 and NFS. You can also use vmkfstools to set up and manage raw device mappings (RDMs).
GENERAL OPTIONS
Specifies the target server and authentication information if required. Run
vmkfstools --help
for a list of all connection options.Prints a help message for each command-specific and each connection option. Calling the script with no arguments or with --help has the same effect.
When you execute a vCLI with the
--server
option pointing to a vCenter Server system, use --vihost
to specify the ESX/ESXi host to run the command against.FILE SYSTEM OPTIONS
Creates a VMFS3 file system on a specified partition, such as naa.<naa_ID>:1. The specified partitionbecomes the file system's head partition.
Specifies the block size of the VMFS file system to create. When omitted, defaults to using 1MB.
Name of the VMFS file system to create.
Extends the VMFS file system with the specified head partition by spanning it across the partition specified by <span_partition>.
Lists attributes of a file or directory on a VMFS volume. DisplaysVMFS version number, the VMFS file system partitions, thecapacity and the available space.
VIRTUAL DISK OPTIONS
Creates a virtual disk at the specified location on a VMFS volume. With <size> you can specifyspecify k|K, m|M, or g|G. Default size is 1MB, default adapter type is 'busLogic', and defaultdisk format is 'zeroedthick'.
Adapter type of a disk to be created. Accepts buslogic, lsilogic or ide.
Specifies the target disk format when used with -c, -i, or -X.
For c, accepts
zeroedthick
, eagerzeroedthick
, or thin
.For i, accepts
zeroedthick
, eagerzeroedthick
, thin
, rdm:dev
, rdmp:dev
, or 2gbsparse
.For -X, accepts
eagerzeroedthick
.Creates a copy of a virtual disk or raw disk. The copywill be in the specified disk format. Takes source disk and destination disk as arguments.
Deletes files associated with the specified virtual disk.
Renames a specified virtual disk.
Extends the specified VMFS virtual disk to the specifiedlength. This command is useful for extending the size of a virtual disk allocated to a virtual machine after the virtual machine has been created. However, this command requires that the guest operating system has some capability for recognizing the new size of the virtual disk and taking advantage of this new size (e.g. by updating the file system on the virtual disk to take advantage of the extra space).
On ESX/ESXi 4.0 and later, you can use
-d | --diskformat
tospecify that the disk should grow in eagerzeroedthick format. You can use -d
only with eagerzeroedthick. By default, any disk, regardless of format, is extended as zeroedthick. Extending disks to eagerzeroedthick makes sense only when these virtual disks are used for fault tolerance or clustering and have to be preallocated and zeroed out up front.Creates a raw disk mapping, that is, maps a raw disk to a file on a VMFS file system. Once the mapping is established, the mapping file can be used to access the raw disk like a normal VMFS virtual disk. The 'file length' of the mapping is the same as the size of the raw disk that it points to.
Creates a passthrough raw disk mapping. Once the mapping is established, it can be used to access the rawdisk like a normal VMFS virtual disk. The 'file length' of the mapping is the same as the size of the raw disk that it points to.
This option is not currently supported.
Returns the geometry information (cylinders, heads, sectors)of a virtual disk.
Initializes the virtual disk with zeros. Any existing data on the virtual disk is lost.
Converts a 'thin' virtual disk to 'eagerzeroedthick'.Any data on the 'thin' disk is preserved. Any blocks that were not allocated are allocated and zeroed out.
The following examples assume you are specifying connection options, either explicitly or, for example, by specifying the server, user name, and password. Run
vmkfstools --help
for a list of common options including connection options.The examples use single quotes around some names; use double quotes on Windows.Create the specified file system:
For ESX/ESXi version earlier than 4.0, specify the VMHBA name:
For ESX/ESXi version 4.0 or later, specify the device name, for example naa.xxx:
Create a virtual disk:
Rename files associated with a specified virtual disk to the specified name:
Get the geometry information (cylinders, heads, and sectors) of a virtual disk:
Delete an existing virtual disk:
Shrink the size of the virtual disk:
Extend the virtual disk to specified size, the extended region of the diskgrows in eagerzeroedthick format:
Initialize the virtual disk with zeros: