From 9200266ae9f7d71b8dc21537f9f5bf7fbfc6d3e5 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Wed, 16 Nov 2016 20:04:31 -0800 Subject: [PATCH 1/7] Clean up kernels on modern Ubuntu systems This drops the image size by about 50 megs Signed-off-by: Tim Smith --- scripts/ubuntu/cleanup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ubuntu/cleanup.sh b/scripts/ubuntu/cleanup.sh index c2306880f..55ebc9de8 100644 --- a/scripts/ubuntu/cleanup.sh +++ b/scripts/ubuntu/cleanup.sh @@ -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; From 57d9002267055c05fb99b08e169b97a316ef9d26 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Wed, 16 Nov 2016 21:16:22 -0800 Subject: [PATCH 2/7] =?UTF-8?q?Purge=20additional=20packages=20that=20don?= =?UTF-8?q?=E2=80=99t=20make=20sense=20on=20a=20test=20box?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These packages are only relevant for pets. They don’t make sense here. Signed-off-by: Tim Smith --- scripts/ubuntu/cleanup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ubuntu/cleanup.sh b/scripts/ubuntu/cleanup.sh index 55ebc9de8..abc09e55a 100644 --- a/scripts/ubuntu/cleanup.sh +++ b/scripts/ubuntu/cleanup.sh @@ -34,7 +34,7 @@ apt-get -y purge libx11-data xauth libxmuu1 libxcb1 libx11-6 libxext6; 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; From 4afad31c637f5c72f5e4b3165ae0c8c62ba52429 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Wed, 16 Nov 2016 21:18:26 -0800 Subject: [PATCH 3/7] Nuke the logs for /var/log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s not much, but we might as well do it Signed-off-by: Tim Smith --- scripts/ubuntu/cleanup.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/ubuntu/cleanup.sh b/scripts/ubuntu/cleanup.sh index abc09e55a..0f548aafb 100644 --- a/scripts/ubuntu/cleanup.sh +++ b/scripts/ubuntu/cleanup.sh @@ -40,3 +40,6 @@ apt-get -y autoremove; apt-get -y clean; rm -f VBoxGuestAdditions_*.iso VBoxGuestAdditions_*.iso.?; + +# delete any logs that have built up during the install +find /var/log/ -name *.log -exec rm -f {} \; From 83f93f37a205844d8cd196d0c12e50646db91d7f Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Wed, 16 Nov 2016 21:54:47 -0800 Subject: [PATCH 4/7] Remove docs packages This is currently just libssl-doc which is about 3 megs! Signed-off-by: Tim Smith --- scripts/ubuntu/cleanup.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/ubuntu/cleanup.sh b/scripts/ubuntu/cleanup.sh index 0f548aafb..1f128c115 100644 --- a/scripts/ubuntu/cleanup.sh +++ b/scripts/ubuntu/cleanup.sh @@ -27,6 +27,12 @@ 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; From eafd39b804dd67224776ea9e4fc4b5d31331fde7 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 17 Nov 2016 00:22:45 -0800 Subject: [PATCH 5/7] Remove docs Signed-off-by: Tim Smith --- scripts/ubuntu/cleanup.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/ubuntu/cleanup.sh b/scripts/ubuntu/cleanup.sh index 1f128c115..8bfbf2aa5 100644 --- a/scripts/ubuntu/cleanup.sh +++ b/scripts/ubuntu/cleanup.sh @@ -47,5 +47,8 @@ apt-get -y clean; rm -f VBoxGuestAdditions_*.iso VBoxGuestAdditions_*.iso.?; +# Remove docs +rm -rf /usr/share/doc/* + # delete any logs that have built up during the install find /var/log/ -name *.log -exec rm -f {} \; From a5e552a0efbb63aa2f08430ca46dbdb771c51091 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 17 Nov 2016 00:22:55 -0800 Subject: [PATCH 6/7] Remove caches Signed-off-by: Tim Smith --- scripts/ubuntu/cleanup.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/ubuntu/cleanup.sh b/scripts/ubuntu/cleanup.sh index 8bfbf2aa5..4b22ea875 100644 --- a/scripts/ubuntu/cleanup.sh +++ b/scripts/ubuntu/cleanup.sh @@ -50,5 +50,8 @@ 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 {} \; From 8acb7837fd540452273243d9c6c333d30af6c56b Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 17 Nov 2016 11:57:32 -0800 Subject: [PATCH 7/7] Whiteout both / and /boot This is a modified version of the code from boxcutter Signed-off-by: Tim Smith --- scripts/common/minimize.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/common/minimize.sh b/scripts/common/minimize.sh index 045d7be43..0173b4233 100644 --- a/scripts/common/minimize.sh +++ b/scripts/common/minimize.sh @@ -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 @@ -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;