Tag: virtualbox

How to reduce your virtualbox linux virtual machine size

After using a linux virtual machine that has been configured with dynamically expanding drive, the size gets larger even if you remove files from it.

Here is the steps to shrink your linux virtual machine size :

1- Remove any unnecessary files you don’t need from the virtual machine.

2- Fill the unused spaces on it with zeros.

  • Open the virtual machine.
  • Install zero free
sudo apt-get install zerofree
  • Reboot the machine in repair mode, and login to root shell
  • Kill any processes using the hard disk.
service rsyslog stop
service network-manager stop
killall dhclient
  • list your virtual machine harddisks
df
  • Unmount and Fill all the unused spaces for each physical drive on the machine with zeros.
mount -n -o remount,ro -t ext3 /dev/sda1 /
zerofree /dev/sda1
  • Shutdown the machine.

3- Clone the old HD file into a new shrinked one

VBoxManage clonehd oldHd.vdi newHd.vdi

4- Now add the new cloned HD file as the new HD for the machine and test it.

5- Remove your old HD file.

 

Backup / Increase the Guest OS Drive on VirtualBox

Tried to search online for a way to increase the size of a vdi image, and there was no solution available online to do so.
I had windows XP installed on a virtual machine for mail, and testing purposes on the most hated IE6, and the drive ran out of a space, no solution or work around helped me increase it, all the solutions to modify the partition table, etc didn’t work for me.
Here is the simple steps i followed :

  • Add Another Disk Drive to the Guest OS
  • Backup the Guest Operating system drive using Norton Ghost to the newly added drive.
  • Copy the backup to a DVD image (I had to move it to the host drive first)
  • Make a new Virtual Machine with the new size you want.
  • Boot the new machine using Norton Ghost drive, and attach the DVD image with the created backup.
  • Restore the backup from the DVD created using Norton Ghost.
  • Restart the machine and you should have a working.
  • Delete the created DVD image, the extra hard disk, and the old machine.

If you have a shorter solution, please share :)