# Shrink VMDK file?



## gurutech (Apr 23, 2004)

I'm running VMWare under Centos Linux, and looking for a way to quickly shrink one of my VMDK files (virtual hard drive).

I've searched Google, but have only found how to shrink the partition INSIDE the virtual file, not the virtual file itself. As of now, I have a file that is 465gb, but only 200gb of it is used. I want to bring this down to around 250gb total size.

One of the suggestions I found is to simply create a new VMDK file, then "copy" the files from the larger drive to the smaller one, then get rid of the larger one. But this only applies to "non-bootable" files. I'm trying to do this on a "bootable" Win8 file.

Any suggestions?


----------



## TonyB25 (Jan 1, 1970)

Use the VMware tools to shrink the drive.


----------



## gurutech (Apr 23, 2004)

tried that, but as soon as I enter the command in Terminal, it shows a > prompt, and that's it. Have to CTRL-C out of it.


----------



## TonyB25 (Jan 1, 1970)

I just use the GUI interface for those operations. You don't have a GUI interface for VMware in Linux?


----------



## gurutech (Apr 23, 2004)

What app would I use then? I'm using vmware-vdiskmanager from command line. I don't see any GUI apps other than VMWare Workstation and Virtual Network Editor.


----------



## DaveBurnett (Nov 11, 2002)

You may well need to defragment the virtual disk before you can shrink it (as you would for a partition)


----------



## gurutech (Apr 23, 2004)

I did that. but doing it again just to make sure.


----------



## DaveBurnett (Nov 11, 2002)

Dfrag and move to beginning/end of partition. often defrag may just defrag the files/directory NOT consolidate the space.


----------



## TonyB25 (Jan 1, 1970)

You'd use the VMware Workstation program. In Windows there's an option on the application menus to clean up and defrag drives for each guest VM. But if you don't have a GUI, you'd have to find the Linux commands for terminal. I don't use that, so I don't know what to tell you. You might try reading the manual for VMware Workstation.


----------



## DVOM (Jun 21, 2002)

cd /usr/bin

sudo vmware-toolbox-cmd disk shrink /


----------



## gurutech (Apr 23, 2004)

I think I have found a way to do this, but it's not pretty.

Set up a second VMDX file the size I want. Use a "ghost" application to copy the larger drive to the smaller drive.

Normally this would be a piece of cake, but because I'm going from a larger drive to a smaller one, I'm running into some minor issues... 

I'm in the process of "backing up" the larger drive, and when that is complete (in about 7 hours, as the timer goes), then I will try restoring to the smaller drive.


----------



## DVOM (Jun 21, 2002)

My apologies, my previous post was for an linux VM. 

So for a Win 8.1 VM in VMware Player 6.0.4 this is working for me:

Open a CMD prompt with admin priviledges (in Win 8.1 VM) and type "C:\Program Files\VMware\VMware Tools\VMwareToolboxCmd.exe disk shrink c:\"

Another way I have done it is that I have several old VMs with old style tools that still have the shrink tab in the tools console. For instance I have a Ubuntu 10.04 VM and I can attach the newer Win 8.1 vmdk, start up the Ubuntu VM and shrink the Windows Vmdk from there.


----------



## gurutech (Apr 23, 2004)

That looks like it's going to work, however at the very end, it tells me that there's not enough room to shrink the C: drive.

I was able to shrink the original C: drive to be smaller than the "new" one, however I can't do a "disk to disk" conversion because I have the 100mb system partition, a 240gb main partition, and then about 240gb of "unallocated" space, and a full copy will try to copy the unallocated space.

Got everything copied, except it won't boot. I boot from the Win8 DVD (in ISO format), and run an automatic repair, but that doesn't work.

Any other ideas?

Actual error is:

C:\WINDOWS\system32>"C:\Program Files\VMware\VMware Tools\VMwareToolboxCmd.exe" disk shrink c:\
Please disregard any warnings about disk space for the duration of shrink process.
Progress: 100 [===========>]
Error while shrinking:
Shrinking not completed.


----------



## DVOM (Jun 21, 2002)

A couple of thoughts: First, If I remember correctly, vmware needs about twice the used space to shrink the vmdk. I'm not certain on that. But I started always dividing my vmdk's into 2GB files. I've read that it needs a lot less space to shrink.

Due to the "twice as much space as used" theory, I'd try expanding the partition to take up the entire disk. From what I understand you saying, that would double the space.


----------



## gurutech (Apr 23, 2004)

So I tried expanding the volume to the full size of the vmdx file, and ran the shrink bit again. Same error!


----------



## DVOM (Jun 21, 2002)

Here's another possibility:

Shrink the VM system partition back down to the previous 240GB.

Create another VM of at least a little bigger than 240GB.

Download an ISO of Parted Magic. Includes Clonezilla.

Attach both the Parted Magic ISO and the original Win8 VM to your new VM.

The new VM should boot directly to Parted Magic and allow you to do a partition to partition clone.


----------



## gurutech (Apr 23, 2004)

I tried that already, but with a program called Ease-US.

I was considering doing the same thing with a Live Linux DVD (ISO), using "dd" with a disk to disk copy, but I wasn't sure how that would work with a blank partition that I really don't want to copy.


----------

