VMWare-Fusion-Shrink-Linux-Disk

Shrink VMWare Fusion Linux Guest Virtual Disk

Right! VMWare Fusion on Mac OSX allows you to shrink virtual disks easily for Windows virtual machines right from the graphical interface – Virtual Machine -> Settings -> General -> Clean Up Virtual Machine… but how about for Linux guests? There isn’t such option to do this from the graphical interface, so Terminal here we go!

If you have a virtual disk that grows as data is added, you can shrink it as described below. If you allocated all the space for your virtual disk at the time you created it, you cannot shrink it.

vmware-fusion-virtual-hard-drive

When you delete files from your virtual machine, Fusion does not return the space to your Mac. Shrinking the virtual machine by cleaning up the hard disk returns that freed space to your Mac.
Cleaning up the virtual hard disk also consolidates any unconsolidated snapshot files left on the virtual machine. Unconsolidated snapshot files can be left on the virtual machine when manually deleting a snapshot fails.

There are a couple things we want to do before shrinking the virtual disk; cleaning the clutter (deleting unnecessary files), defragmenting the drive and wiping the free space clean so the shrinker will know what is free to get rid of, to recover as much disk space as possible.

So, boot up your Linux Virtual machine, delete all old files, ISO images, empty the trash and fire up a Terminal window.

Preparing Linux Guest Virtual Machine

1- Defrag guest virtual disk (usually sda1, sdb1) – Listing in Terminal: ls -la /dev/sd*

Note: Defragmenting the virtual disk will tax the host and guest I/Os. Both, your Mac and the Guest OS may become slow or unresponsive while this process is taking place. Be patient.

sudo e4defrag /dev/sda1

Defrag Guest virtual disk

2- Wipe the guest virtual disk free space clean so the shrinker will know what is free to get rid of:

Note: Wiping the virtual disk free space clean will tax the host and guest I/Os. Both, your Mac and the Guest OS may become slow or unresponsive while this process is taking place. Again, be patient!

dd if=/dev/zero of=wipefile bs=1024x1024; rm wipefile

Wipe guest free space

We’re now ready to shrink the virtual disk but we can’t reclaim space with the virtual machine running, so shut it down first (Power off).

Shrink VMWare Fusion Linux Guest Virtual Disk

Open Mac OS X Terminal and change directory to /Applications/VMware/Fusion.app/Contents/Library/

cd /Applications/VMware\ Fusion.app/Contents/Library/

OSX Terminal

Next browse to your Virtual Machine in Finder, right click it and select “Show Package Contents

Show Package Contents

Package Contents

In Terminal, type ./vmware-vdiskmanager -k and drag & drop the virtual disk to Terminal for its path to be autocompleted as shown below:

Virtual Disk Path

Press enter and be patient while your Linux virtual disk is shrank :)

Virtual Disk Shrink Completed

Virtual Disk size shrank

Cheers!

Related Post

More ♥ for Software Sources and Update Manager in ... Software Sources and Update Manager in Linux Mint 17.3 Rosa get some extra love! I mentioned before that users didn't use other Linux Mint mirrors mai...
Dropbox fix for Linux Mint 18.x Xfce I came across this Dropbox bug in Linux Mint 18.2 Sonya Xfce where it simply refuses to show up the correct icon in my system tray or to give me any m...
Definitive fix for Linux Lite 3.x Menu Linux Lite's heavily customized Whisker menu wouldn't be such a problem if proper measures had been put in place during its development; or better sai...

Leave a Reply