Skip to main content

VirtualBox: How To Shrink VDI File

One area where Parallels is much better than VirtualBox is in the ease of compacting a VM disk to what's actually in use.

I've found that VM disks just keep increasing in size, regardless of what you might delete. Parallels makes compacting easy - all you do is select "Shrink..." from the Parallels menu.

The situation with VirtualBox is more complicated 😀
While there is a command line "compact" option, this relies on unused stuff being zero - which it won't be for things that got deleted...

However there is a tool (zerofree) which you can run in the VM and it sets all the free space on the disk to zero, which can then be compacted in VirtualBox.

Here are the steps I've been using:

Step 1: Install zerofree in the VM (Linux in my case):

$ sudo apt install zerofree

Step 2: Empty Trash and delete unneeded files

Step 3: Boot into a recovery session

  • Enter root password.

Step 4: Remount disk as read-only

# mount -n -o remount,ro /dev/sda1

Step 5: Run zerofree on disk

# zerofree -v /dev/sda1

Step 6: Shutdown VM

Step 7: Shrink VDI File from Host

$ VBoxManage modifymedium disk <your disk>.vdi --compact

Let me know if there is an easier way?!
In particular, it would be great if the zeroing part could be done from the host environment.

Comments

Popular posts from this blog

My Work in new Top Trumps Birds of Prey Pack

The new Top Trumps "Birds of Prey" pack has my picture illustrating the Secretary Bird card 😀 Here's the original picture: From Flickr

Merging Git Repositories

No project of significant size that I've ever seen has retained its initial structure. Restructuring projects is a fact of life, but unfortunately Git doesn't make it easy. Fundamentally this stems from the way Git works, treating changes as a succession of snapshots and not storing any other metadata. Of course this is part of what makes Git fast and efficient, but at the expense of making some common operations more difficult for users. Git really is a perfect 21st century illustration of the classic  "Worse Is Better"  paradigm of successful software 😀 Previously I discussed how to split a Git project apart into separate repositories . Now I'm going to discuss how to do the opposite and merge separate repositories into one. On the face of it, this would seem a simpler task as Git has powerful support for merging... Let's take the opposite example to my splitting apart article - say you have a main Git repo (ProjA) and a second repo (ProjB) in...

Black Hole Marsh

We also visited Black Hole Marsh nature reserve, which is a large saltwater lagoon having two large bird hides, one in the middle of the lagoon  (Island Hide) and the other overlooking both the lagoon and the Axe Estuary (Tower Hide). There were many birds to be seen, but just as at the Seaton hide, a 400mm lens was not really enough to get frame-filling shots of the birds. All the following taken with Nikon D700, 70-200 f/2.8G VR II and TC-2E III converter (400mm focal length equivalent): Heron Fishing on the Lagoon with the Island Hide in the background Axe Estuary from the Tower Hide Pair of Bar-tailed Godwits Little Egret Mallards on the Lagoon Lapwing Fallow Deer  and Egret on the banks of the Axe Pied Wagtail on the thick green algae of Black Hole Marsh. Rat enjoying leftovers from the bird feeder