VMware Communities
ddamerjian
Enthusiast
Enthusiast
Jump to solution

Hard disk space in VM not reclaimed after deleting files

Running VMware Workstation Pro v12.5

I created a disk for a NEW VM from scratch and brought the VM into operation Running Debian Linux as the guest. At one point the size got up to 21 Gb due to the copying of some zipped files into the guest from the host. After deleting the zip I expected the actual size in my host (Windows 7) to decrease to more closely match the size of the drive in the VM, but it has never come back down.

Here is the output from df -h to show what the size of the drive is in Linux, confirming size of 13 Gb out of 50 Gb drive.

Boxer-SIM:~# cd /

Boxer-SIM:/# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda1              48G   13G   35G  27% /

tmpfs                 3.9G  4.0K  3.9G   1% /dev/shm

But as you can see in my Windows host, more space it being taken up by the Boxer-SIM.vmdk disk. (output is while VM is running, same result as when powered off)

Directory of C:\Users\ddamerji\Documents\_Virtual Machines\Boxer-SIM

11/14/2016  09:45 AM    <DIR>          .

11/14/2016  09:45 AM    <DIR>          ..

11/14/2016  09:45 AM     8,388,608,000 564d8740-cb5a-d200-48cc-2b46cb5b3dc6.vmem

11/14/2016  09:45 AM    <DIR>          564d8740-cb5a-d200-48cc-2b46cb5b3dc6.vmem.lck

11/14/2016  02:52 AM             8,684 Boxer-SIM.nvram

11/14/2016  09:45 AM    22,131,048,448 Boxer-SIM.vmdk                     <==  shouldnt be this large, I am only using 13Gb for my files

11/14/2016  09:45 AM    <DIR>          Boxer-SIM.vmdk.lck

11/13/2016  01:15 PM                 0 Boxer-SIM.vmsd

11/14/2016  09:45 AM             2,920 Boxer-SIM.vmx

11/14/2016  09:45 AM    <DIR>          Boxer-SIM.vmx.lck

11/13/2016  01:15 PM               264 Boxer-SIM.vmxf

11/14/2016  09:45 AM               395 vmware.log

               7 File(s) 30,519,668,711 bytes

               5 Dir(s)  59,235,213,312 bytes free


pastedImage_4.png

I know the system has the capacity to provide more space up to the 50Gb limit as I need more space, but on the flip side, can't it also decrement the amount of space used as I delete files? (Linux doesnt have any recycle bin that I am aware of where deleted files are kept, does it?)

Thanks

dd

Reply
0 Kudos
1 Solution

Accepted Solutions
wila
Immortal
Immortal
Jump to solution

Hi,

The question got already answered at another topic of yours, but let me copy the method to reclaim zero space in here to help others bumping into this topic.

Before you try to shrink the virtual disk files, you should try to remove any unneeded files from the virtual machine to free space.

For example, on Debian-based VMs, you can run

apt-get autoremove apt-get clean all 


to clear out the local repository of retrieved package files.

Also note that if you run a service on the guest that depends on having a bit of free space (such as database services, eg mySQL/Oracle/postgreSQL) that you should shut down the service before continuing with the next step.

Next, run as root (sudo won't work)

cat /dev/zero > /zero.fill;sync;sleep 1;sync;rm -f /zero.fill 

to fill the unused space with zeros.

Then power down the VM and open a command box on your windows host.

Run vmware-vdiskmanager with the -k option to shrink (=reclaim unused space) the virtual disk.

edit: normally Linux does not have a recycle bin. Certainly not when deleting files in the terminal. Deleting a file however does not zero out the blocks, it only removes the file from the directory. In order to reclaim the disk space you need to zero out the data first. Which is what is described above using the zero.fill file. If you have multiple partitions setup then you would run it for each partition.

--

Wil

| Author of Vimalin. The virtual machine Backup app for VMware Fusion, VMware Workstation and Player |
| More info at vimalin.com | Twitter @wilva

View solution in original post

Reply
0 Kudos
5 Replies
wila
Immortal
Immortal
Jump to solution

Hi,

The question got already answered at another topic of yours, but let me copy the method to reclaim zero space in here to help others bumping into this topic.

Before you try to shrink the virtual disk files, you should try to remove any unneeded files from the virtual machine to free space.

For example, on Debian-based VMs, you can run

apt-get autoremove apt-get clean all 


to clear out the local repository of retrieved package files.

Also note that if you run a service on the guest that depends on having a bit of free space (such as database services, eg mySQL/Oracle/postgreSQL) that you should shut down the service before continuing with the next step.

Next, run as root (sudo won't work)

cat /dev/zero > /zero.fill;sync;sleep 1;sync;rm -f /zero.fill 

to fill the unused space with zeros.

Then power down the VM and open a command box on your windows host.

Run vmware-vdiskmanager with the -k option to shrink (=reclaim unused space) the virtual disk.

edit: normally Linux does not have a recycle bin. Certainly not when deleting files in the terminal. Deleting a file however does not zero out the blocks, it only removes the file from the directory. In order to reclaim the disk space you need to zero out the data first. Which is what is described above using the zero.fill file. If you have multiple partitions setup then you would run it for each partition.

--

Wil

| Author of Vimalin. The virtual machine Backup app for VMware Fusion, VMware Workstation and Player |
| More info at vimalin.com | Twitter @wilva
Reply
0 Kudos
ddamerjian
Enthusiast
Enthusiast
Jump to solution

THANKS!

Similar to my other post, I did the same thing as suggested here to zero out the disk and then shutdown the VM:

Boxer-SIM:~# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda1              48G   13G   35G  27% /

tmpfs                 3.9G  4.0K  3.9G   1% /dev/shm


Boxer-SIM:~# cat /dev/zero > /zero.fill;sync;sleep 1;sync;rm -f /zero.fill

cat: write error: No space left on device

Boxer-SIM:~#

Boxer-SIM:~# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda1              48G   13G   35G  27% /

tmpfs                 3.9G  4.0K  3.9G   1% /dev/shm

Boxer-SIM:~# init 0

Then I compressed it:

C:\Program Files (x86)\VMware\VMware Workstation>vmware-vdiskmanager.exe -k "C:\Users\ddamerji\Documents\_Virtual Machines\Boxer-SIM\Boxer-SIM.vmdk"

  Shrink: 100% done.

Shrink completed successfully.

And note the new smaller size:

C:\Users\ddamerji\Documents\_Virtual Machines\Boxer-SIM>dir

Volume in drive C is os

Volume Serial Number is C0B1-1385

Directory of C:\Users\ddamerji\Documents\_Virtual Machines\Boxer-SIM

11/15/2016  10:50 AM    <DIR>          .

11/15/2016  10:50 AM    <DIR>          ..

11/15/2016  10:47 AM             8,684 Boxer-SIM.nvram

11/15/2016  10:50 AM    14,703,067,136 Boxer-SIM.vmdk

11/13/2016  01:15 PM                 0 Boxer-SIM.vmsd

11/15/2016  10:47 AM             2,918 Boxer-SIM.vmx

11/15/2016  10:26 AM    <DIR>          Boxer-SIM.vmx.lck

11/13/2016  01:15 PM               264 Boxer-SIM.vmxf

11/15/2016  10:10 AM           347,284 vmware-0.log

11/15/2016  10:47 AM           274,468 vmware.log

   7 File(s) 14,703,700,754 bytes

   3 Dir(s)  91,528,368,128 bytes free

Very very nice!  Appreciate all the help provided!

dd

Reply
0 Kudos
ddamerjian
Enthusiast
Enthusiast
Jump to solution

Also one more point, if you get the following error:

C:\Program Files (x86)\VMware\VMware Workstation>vmware-vdiskmanager.exe -k "C:\Users\ddamerji\Documents\_Virtual Machines\VIRL\VIRL-disk1.vmdk"

Failed to shrink the disk 'C:\Users\ddamerji\Documents\_Virtual Machines\VIRL\VIRL-disk1.vmdk' : An error occurred while writing a file; the disk is full. Data has not been saved. Free some disk space and try again (0x8).

then that means you have to free space ON THE HOST machine. And having just done this, it appears that it needs as much free space as the file you are trying to actually compress, since the process itself creates a new file and then deletes the old one. I had to free up over 55 GB.  Here it is in the middle of the process of compressing:

C:\Users\ddamerji\My Documents\_Virtual Machines\VIRL>dir

Volume in drive C is os

Volume Serial Number is C0B1-1385

Directory of C:\Users\ddamerji\My Documents\_Virtual Machines\VIRL

10/26/2017  03:18 PM    <DIR>          .

10/26/2017  03:18 PM    <DIR>          ..

10/26/2017  02:50 PM             8,684 nvram

10/26/2017  03:10 PM    56,718,458,880 VIRL-disk1.vmdk                 <== Existing file to be removed when done

10/26/2017  03:18 PM    20,450,377,728 VIRL-disk1.vmdk-dfgshkgrw-tmp   <== NEW FILE BEING CREATED

10/26/2017  03:18 PM    <DIR>          VIRL-disk1.vmdk.lck

11/20/2016  08:50 AM                 0 VIRL.vmsd

10/26/2017  03:11 PM             4,262 VIRL.vmx

10/26/2017  11:57 AM             3,450 VIRL.vmxf

10/26/2017  02:51 PM           275,844 vmware-0.log

10/26/2017  02:05 PM           283,405 vmware-1.log

10/26/2017  12:25 PM           274,103 vmware-2.log

10/26/2017  03:11 PM           272,002 vmware.log

              10 File(s) 77,169,958,358 bytes

               3 Dir(s)  52,764,102,656 bytes free

Afterwards, I saved over 20 GB, not too shabby!

C:\Program Files (x86)\VMware\VMware Workstation>vmware-vdiskmanager.exe -k "C:\Users\ddamerji\Documents\_Virtual Machines\VIRL\VIRL-disk1.vmdk"

  Shrink: 100% done.

Shrink completed successfully.

C:\Users\ddamerji\My Documents\_Virtual Machines\VIRL>dir

Volume in drive C is os

Volume Serial Number is C0B1-1385

Directory of C:\Users\ddamerji\My Documents\_Virtual Machines\VIRL

10/26/2017  03:25 PM    <DIR>          .

10/26/2017  03:25 PM    <DIR>          ..

10/26/2017  02:50 PM             8,684 nvram

10/26/2017  03:25 PM    33,939,193,856 VIRL-disk1.vmdk

11/20/2016  08:50 AM                 0 VIRL.vmsd

10/26/2017  03:11 PM             4,262 VIRL.vmx

10/26/2017  11:57 AM             3,450 VIRL.vmxf

10/26/2017  02:51 PM           275,844 vmware-0.log

10/26/2017  02:05 PM           283,405 vmware-1.log

10/26/2017  12:25 PM           274,103 vmware-2.log

10/26/2017  03:11 PM           272,002 vmware.log

               9 File(s) 33,940,315,606 bytes

               2 Dir(s)  100,377,108,480 bytes free

Reply
0 Kudos
wila
Immortal
Immortal
Jump to solution

Hi,

Yep, that's why I always advise to use split disks, in that case you only need to have the free space for the max size of a slice.

People are worried about performance differences, but the difference between one disk and multiple split files can be ignored.

The thing that might actually be a bit faster is pre-allocated, but then you can't shrink at all...

--

Wil

| Author of Vimalin. The virtual machine Backup app for VMware Fusion, VMware Workstation and Player |
| More info at vimalin.com | Twitter @wilva
Reply
0 Kudos
Ashadsaleem
Contributor
Contributor
Jump to solution

Just wondering, will it have any effect on snapshots ?

Reply
0 Kudos