Skip to content

Commit

Permalink
Merge pull request #718 from chef/shrink
Browse files Browse the repository at this point in the history
Reduce size of Linux images
  • Loading branch information
Seth Thomas authored Nov 18, 2016
2 parents 14f93ff + 8acb783 commit 4efd2c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
16 changes: 12 additions & 4 deletions scripts/common/minimize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ case "$PACKER_BUILDER_TYPE" in
qemu) exit 0 ;;
esac

# Whiteout root
count=$(df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}')
count=$(($count-1))
dd if=/dev/zero of=/tmp/whitespace bs=1M count=$count || echo "dd exit code $? is suppressed";
rm /tmp/whitespace

# Whiteout /boot
count=$(df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}')
count=$(($count-1))
dd if=/dev/zero of=/boot/whitespace bs=1M count=$count || echo "dd exit code $? is suppressed";
rm /boot/whitespace

set +e
swapuuid="`/sbin/blkid -o value -l -s UUID -t TYPE=swap`";
case "$?" in
Expand All @@ -21,8 +33,4 @@ if [ "x${swapuuid}" != "x" ]; then
/sbin/mkswap -U "$swapuuid" "$swappart";
fi

dd if=/dev/zero of=/EMPTY bs=1M || echo "dd exit code $? is suppressed";
rm -f /EMPTY;
# Block until the empty file has been removed, otherwise, Packer
# will try to kill the box while the disk is still full and that's bad
sync;
19 changes: 17 additions & 2 deletions scripts/ubuntu/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dpkg --list \
# e.g. 'linux-image-generic', etc.
dpkg --list \
| awk '{ print $2 }' \
| grep 'linux-image-3.*-generic' \
| grep 'linux-image-.*-generic' \
| grep -v `uname -r` \
| xargs apt-get -y purge;

Expand All @@ -27,16 +27,31 @@ dpkg --list \
| grep -- '-dev$' \
| xargs apt-get -y purge;

# delete docs packages
dpkg --list \
| awk '{ print $2 }' \
| grep -- '-doc$' \
| xargs apt-get -y purge;

# Delete X11 libraries
apt-get -y purge libx11-data xauth libxmuu1 libxcb1 libx11-6 libxext6;

# Delete obsolete networking
apt-get -y purge ppp pppconfig pppoeconf;

# Delete oddities
apt-get -y purge popularity-contest;
apt-get -y purge popularity-contest installation-report command-not-found command-not-found-data friendly-recovery;

apt-get -y autoremove;
apt-get -y clean;

rm -f VBoxGuestAdditions_*.iso VBoxGuestAdditions_*.iso.?;

# Remove docs
rm -rf /usr/share/doc/*

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

# delete any logs that have built up during the install
find /var/log/ -name *.log -exec rm -f {} \;

0 comments on commit 4efd2c5

Please sign in to comment.