So you set up your {Ku,Lu,U}buntu-VM inside VirtualBox and want to export it as an appliance as small as possible. Do this. (Tested with Lubuntu 14.04)
-
install zerofree:
sudo apt-get install zerofree
-
remove unneeded packages (optional)
sudo apt-get autoremove
-
empty cache of downloaded packages
sudo apt-get autoclean sudo apt-get clean
-
to zero out the free space, we need runlevel 1, but
telinit 1
is useless due to a bug around since at least Ubuntu 11.04, so...
0. make a snapshot
0. reboot VM- hold shift-key at reboot to get into the grub menu
- select recovery
- select root to get a root shell
- before remounting
/
read-only, you might need to stop some services Show archive.org snapshot - remount root-fs ro:
mount -o remount,ro /
- run zerofree
zerofree /dev/sda1 -v
shutdown -h now
- most guides will tell you now that you have to convert to and from .vdi to get compaction of your disk but when exporting to ova the snaphot is merged with the current state an by this way the image is compacted
- .ova is technically a regular .tar file (see tar, zip, gzip, bzip), so further compression (zip, xz, bzip2) can be applied, but your mileage may vary (expect about 2% reduction for a small Lubuntu image)
Posted by Markus to Markus's deck (2015-05-07 13:49)