Compacting and exporting an Ubuntu-Appliance from VirtualBox

Posted . Visible to the public.

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)

  1. install zerofree: sudo apt-get install zerofree

  2. remove unneeded packages (optional) sudo apt-get autoremove

  3. empty cache of downloaded packages

    sudo apt-get autoclean
    sudo apt-get clean
    
  4. 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

    1. hold shift-key at reboot to get into the grub menu
    2. select recovery
    3. select root to get a root shell
    4. before remounting /read-only, you might need to stop some services Show archive.org snapshot
    5. remount root-fs ro: mount -o remount,ro /
    6. run zerofree zerofree /dev/sda1 -v
    7. shutdown -h now
    8. 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
    9. .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)
Markus
Last edit
Markus
Keywords
Ubuntu
Posted by Markus to Markus's deck (2015-05-07 13:49)