Skip to content

Instantly share code, notes, and snippets.

@martinseener
Last active August 29, 2015 13:57
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 martinseener/9411739 to your computer and use it in GitHub Desktop.
Save martinseener/9411739 to your computer and use it in GitHub Desktop.
Shrinking Virtual Machine Boxes

Shrinking Virtual Boxes

  • Remove manuals

rm -rf /usr/share/doc

  • Remove VirtualBox OSE

rm -rf /usr/src/vboxguest*
rm -rf /usr/src/virtualbox-ose-guest*

  • Clean up the cache folder

find /var/cache -type f -exec rm -rf {} \;

  • Remove unused locales

rm -rf /usr/share/locale/{af,am,ar,as,ast,az,bal,be,bg,bn,bn_IN,br,bs,byn,ca,cr,cs,csb,cy,da,de,de_AT,dz,el,en_AU,en_CA,eo,es,et,et_EE,eu,fa,fi,fo,fr,fur,ga,gez,gl,gu,haw,he,hi,hr,hu,hy,id,is,it,ja,ka,kk,km,kn,ko,kok,ku,ky,lg,lt,lv,mg,mi,mk,ml,mn,mr,ms,mt,nb,ne,nl,nn,no,nso,oc,or,pa,pl,ps,pt,pt_BR,qu,ro,ru,rw,si,sk,sl,so,sq,sr,sr*latin,sv,sw,ta,te,th,ti,tig,tk,tl,tr,tt,ur,urd,ve,vi,wa,wal,wo,xh,zh,zh_HK,zh_CN,zh_TW,zu}

Go into Single-User mode and write zeros to free space

init 1
mount -o remount,ro /dev/sda1
zerofree /dev/sda1
init 0

  • Now you can compact the VM (.vdi files) with VBoxManage or just create the base box with vagrant

Done!

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