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

Samba Share for Beginners – Video I noticed I have never posted a video in my blog. So, here is one that may help you setup Samba if you're new to Samba Shares. How to create Samba ...
Update Manager status custom icons for Linux Mint I've put together a small set of fresher Linux Mint 17.x (Cinnamon, MATE, Xfce, KDE) Update Manager status icons and I'd like to share it with you :) ...
Yad 3.9.1-0 package in Linux Lite breaks few thing... If you have installed some of the extra apps I've made available for Linux Lite in my repo, you'll notice that after updating Linux Lite home-brew ver...

Leave a Reply