[SOLVED] VirtualBox – how to reduce virtual disk size

[SOLVED] VirtualBox – how to reduce virtual disk size

This guide shows you how to free up memory used by VirtualBox machines.

I. [Optional] Remove unnecessary data from the virtual machine

Run the virtual machine and remove unnecessary data. You can use tools like WinDirStat (Windows) or baobab (aka “Disk Usage Analyser” – for Linux).

#install baobab
sudo apt-get install baobab

#run Disk Usage Analyser as root
sudo baobab

II. [Optional] Fill unused disk space by zeros

Linux guest OS

There is a tool for Linux(called zerofree) that fills unused disk space by zeros which can be free up in the next step.

First you have to install zerofree  by:

sudo apt-get install zerofree

Then reboot the machine and run linux in safemode (press ESC  key on BIOS screen and choose Advanced -> Recovery Mode in Grub menu). Then run:

zerofree -v /dev/sda1

After all shutdown the machine:

shutdown now -hP

Windows Guest OS

Run virtual machine and then run Disk Defragmenter  for all disks.

III. Compact VirtualBox disk

Go to the VirtualBox installation directory. Default location is:

  • Windows: C:\Program Files\Oracle\VirtualBox;
  • Linux: /usr/share/virtualbox/ – /usr/bin/VBoxManage  is linked to /share/virtualbox/VBox.sh.

and run the following command to get the location of disk you are interested in:

#Windows
VBoxManage.exe list hdds

#Linux
VBoxManage list hdds

Here is my result:

UUID:           e94cfd7c-c792-4e47-9964-81479a1135f5
Parent UUID:    base
State:          locked write
Type:           normal (base)
Location:       D:\VM\Better-Coding.vdi
Storage format: VDI
Capacity:       102400 MBytes
Encryption:     disabled

Compact chosen disk by the following command:

#Windows
VBoxManage.exe modifymedium disk <DISK_LOCATION> --compact

#Linux
VBoxManage modifymedium disk <DISK_LOCATION> --compact

2
Leave a Reply

avatar
1 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
lukasz.cieslaMarck Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Marck
Guest
Marck

Have you a prroblem with the compact process ?, my process, consumming all the ram, forcing other process to liberate ram too.

Then the proccess turning very slow, all the machine really.
some times if i try to run a program, the ram, go down to the normal ram used by this process liberating more than the 95%, but i cant see all the aspect for repeating the flush.

its safe to stop the process ?

Close Menu