Skip to content

Write zeros to disk to improve disk compression

Created by: appleby

Write zeros to a file on the root partition until the filesystem is full, then unlink the file. Packer will compress the disk as part of the build, resulting in smaller final disk image.

The same strategy is used in the hashicorp/atlas-packer-vagrant-tutorial repo, here: https://github.com/hashicorp/atlas-packer-vagrant-tutorial/blob/master/scripts/zerodisk.sh

After this change, the virtualbox box file size was reduced by ~230MB on my system:

[ma@march arch-boxes]? du -h Arch-Linux-x86_64-virtualbox-2017-08-02-*
434M    Arch-Linux-x86_64-virtualbox-2017-08-02-after.box
667M    Arch-Linux-x86_64-virtualbox-2017-08-02-before.box

I've only tested this change with the virtualbox-iso provider. I have reason to believe it works with the vmare-iso and qemu providers as well, as I contributed a similar change to the packer-arch repo a while back and they have enabled it for vmware, qemu, and parallels providers. But if it turns out it breaks things for other providers, I can move it into a separate provisioner that has an "only": ["virtualbox-iso"] clause, if necessary.

Merge request reports

Loading