Skip to content

Instantly share code, notes, and snippets.

@atmin
Last active August 25, 2016 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atmin/6807052 to your computer and use it in GitHub Desktop.
Save atmin/6807052 to your computer and use it in GitHub Desktop.
Compact dynamically expanding VirtualBox CentOS image
1. Delete unnecessary files from image
2. sudo yum install zerofree
3. reboot, edit kernel parameters, add 'rescue single ro'
4. remount root read-only:
sudo mount -r -o remount /dev/mapper/vg_centos6generic-lv_root
5. null the free space (-v = verbose, -n = dry run):
sudo zerofree -v /dev/mapper/vg_centos6generic-lv_root
6. turn off VM
7 from host OS:
vboxmanage modifyhd --compact MachineDisk.vdi
Was able to shrink 50GB image to 36GB with only 366MB free space on the host machine.
@xabolcs
Copy link

xabolcs commented Aug 25, 2016

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment