New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making smaller base boxes #343

Closed
johnf opened this Issue Apr 14, 2011 · 11 comments

Comments

Projects
None yet
8 participants
@johnf
Copy link

johnf commented Apr 14, 2011

Using the following procedure when creating the base box can greatly reduce it's size.

I tested by using the lucid32 base. This box is 479MB from the website.

vagrant up
vagrant ssh
aptitude clean
cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill
exit
vagrant package

This cuts the box down to 390MB

If you go further and remove packages that won't be needed by most ie

sudo aptitude purge ri
sudo aptitude purge installation-report landscape-common wireless-tools wpasupplicant ubuntu-serverguide
sudo aptitude purge python-dbus libnl1 python-smartpm linux-headers-2.6.32-21-generic python-twisted-core libiw30
sudo aptitude purge python-twisted-bin libdbus-glib-1-2 python-pexpect python-pycurl python-serial python-gobject python-pam python-openssl libffi5

You can bring the box size down to 360MB. This one might not be worth doing but the first is probably a good idea.

@ghost ghost assigned mitchellh Apr 20, 2011

@mitchellh

This comment has been minimized.

Copy link
Member

mitchellh commented Apr 20, 2011

This should be added to the documentation. I've labelled it as such and will do so.

Thanks!!

@mitchellh

This comment has been minimized.

Copy link
Member

mitchellh commented Jul 4, 2011

I've actually started including this in the scripts to create the base boxes:

# Zero free space to aid VM compression
dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY

I'll add the remaining purges as well.

@mitchellh mitchellh closed this Jul 4, 2011

@ghost

This comment has been minimized.

Copy link

ghost commented Apr 3, 2014

I have just did a test, and it seems that this is not working anymore. Once I have package the vagrant bo the size was:

527M 2014-04-03 22:00 package.box

Then I performed these commands:

vagrant up
vagrant ssh
aptitude clean
cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill
exit
vagrant package

Checking size now:

247M 2014-04-03 22:05 package.box

I suggest reopening the bug. It's either dd is not as effective, or the scripts are not working anymore.

@mitchellh

This comment has been minimized.

Copy link
Member

mitchellh commented Apr 3, 2014

@edvinasme Vagrant itself makes no effort to save disk space from VirtualBox. It just calls VBoxManage exportvm. So this is not a bug with Vagrant.

@ghost

This comment has been minimized.

Copy link

ghost commented Apr 3, 2014

Yes, but this should at least be mentioned in the documentation. I would also consider adding that as a possible feature to vagrant, as making images smaller would be a good thing to have. I don't know if that could be supported though.

@SgtPooki

This comment has been minimized.

Copy link

SgtPooki commented Jun 6, 2014

+1

Doing this for a new lubuntu box i'm creating reduced my size significantly:

drwxr-xr-x+ 1 rdempsey None    0 Jun  6 15:24 .
d---------+ 1 rdempsey None    0 Jun  6 13:53 ..
-rwxr-xr-x+ 1 rdempsey None 2.0G Jun  6 14:07 lubuntu-trustytahr-64.box
-rwxr-xr-x+ 1 rdempsey None 1.1G Jun  6 15:27 package.box
@client9

This comment has been minimized.

Copy link

client9 commented Jun 6, 2014

everyone may wish to checkout opscode's bento project. It takes raw ISO from ubuntu, etc and smashes them into shape.

https://github.com/opscode/bento

in particular the OS specific cleanup scripts, e.g.

https://github.com/opscode/bento/blob/master/packer/scripts/ubuntu/cleanup.sh

and the common minimiser script

https://github.com/opscode/bento/blob/master/packer/scripts/common/minimize.sh

Other tricks for ubuntu...

apt-get purge -y locate

to save a few more megabytes

dpkg -l | grep -- '-dev' | xargs apt-get purge -y will also delete any old dev libraries you likely won't need.

enjoy!

nickg

@wsouto

This comment has been minimized.

Copy link

wsouto commented Jun 7, 2014

In the line of other tricks for Ubuntu you can tell apt to not download translation indexes creating a file like /etc/apt/apt.conf.d/90translations and putting this in this file: Acquire::Languages "none";. This prevents apt to get a lot of index files related to translations that is not needed in the VM which speed up a lot the update.

Then, remove the indexes lists before pack your machine.:

$ rm -rf /var/lib/apt/lists/*

It will save you something around 70MB of space, which is quite relevant. You'll must do an sudo apt-get update first thing before install anything, but it's easily accomplished via a simple provisioning via shell script.

In a machine with 160MB (packaged) like the one I do and use as a base for another VMs it can be relevant. My dev machine has about 240MB (also packaged).

@cybertk

This comment has been minimized.

Copy link

cybertk commented Mar 19, 2015

+1

@lferro9000

This comment has been minimized.

Copy link

lferro9000 commented Mar 11, 2016

Another area that could also be cleaned is the /var/log and the /tmp folders (if at all possible).

@acefei

This comment has been minimized.

Copy link

acefei commented Apr 12, 2017

It did not work for me.

[vagrant@localhost ~]$ cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill
cat: write error: No space left on device

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