Reduce vdisk disk usage


Recommended Posts

When you create a VM it's vdisk is a sparse file. A sparse file saves a huge amount of space on your disk, because data which contains nothing (zeros) is "compressed". But after a while it will become bigger as deleted files are not really deleted. To understand this, we use an example. I created a 32G vdisk for my Windows 10 machine:

image.png.4a8a23e9a76362af37481a58bf63cea4.png

 

After installation its size is 15G (as it's a sparse file):

file="/mnt/cache/domains/Windows 10/vdisk1.img"
du -h "$file"
15G     /mnt/cache/domains/Windows 10/vdisk1.img

 

After installing the network driver and some updates it grow to 18G:

du -h "$file"
15G     /mnt/cache/domains/Windows 10/vdisk1.img

 

After installing this tool inside the Windows VM:

https://docs.microsoft.com/de-de/sysinternals/downloads/sdelete

 

and executing this command:

sdelete64 -z c:

 

it grow to 30G:

du -h "$file"
30G     /mnt/cache/domains/Windows 10/vdisk1.img

 

And finally after this command:

fallocate -d "$file"

 

It shrunk to 15G again:

du -h "$file"
15G     /mnt/cache/domains/Windows 10/vdisk1.img

 

 

 

The same can be reached with a Linux VM and the command "zerofree".

 

 

This could be executed once every month.

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.