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.
This should be added to the documentation. I've labelled it as such and will do so.
Thanks!!
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.
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.
@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.
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.
+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
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
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).
+1
Another area that could also be cleaned is the /var/log and the /tmp folders (if at all possible).
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
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.