b7433917a4
* Use Ubuntu 14.04.3 ISO instead ovf box * Add a libvirt target as well * Add additional build shell scripts from bogdando/packer-atlas-example * Use sudo for all shell commands * Fix virtualbox guest additions build order * Cleanups to reduce end image size * Update README how to build and up both for vbox/libvirt Signed-off-by: Bogdan Dobrelya <bdobrelia@mirantis.com>
70 lines
1.7 KiB
Bash
70 lines
1.7 KiB
Bash
#!/bin/bash -eux
|
|
|
|
CLEANUP_PAUSE=${CLEANUP_PAUSE:-0}
|
|
echo "==> Pausing for ${CLEANUP_PAUSE} seconds..."
|
|
sleep ${CLEANUP_PAUSE}
|
|
|
|
# Make sure udev does not block our network - http://6.ptmc.org/?p=164
|
|
echo "==> Cleaning up udev rules"
|
|
rm -rf /dev/.udev/
|
|
rm /lib/udev/rules.d/75-persistent-net-generator.rules
|
|
rm /etc/udev/rules.d/70-persistent-net.rules
|
|
mkdir /etc/udev/rules.d/70-persistent-net.rules
|
|
|
|
echo "==> Cleaning up leftover dhcp leases"
|
|
# Ubuntu 10.04
|
|
if [ -d "/var/lib/dhcp3" ]; then
|
|
rm /var/lib/dhcp3/*
|
|
fi
|
|
# Ubuntu 12.04 & 14.04
|
|
if [ -d "/var/lib/dhcp" ]; then
|
|
rm /var/lib/dhcp/*
|
|
fi
|
|
|
|
# Add delay to prevent "vagrant reload" from failing
|
|
echo "pre-up sleep 2" >> /etc/network/interfaces
|
|
|
|
echo "==> Cleaning up tmp"
|
|
rm -rf /tmp/*
|
|
|
|
# Cleanup apt cache
|
|
apt-get -y autoremove --purge
|
|
apt-get -y clean
|
|
apt-get -y autoclean
|
|
|
|
echo "==> Installed packages"
|
|
dpkg --get-selections | grep -v deinstall
|
|
|
|
# Remove Bash history
|
|
unset HISTFILE
|
|
rm -f /root/.bash_history
|
|
rm -f /home/vagrant/.bash_history
|
|
|
|
# Clean up log files
|
|
find /var/log -type f | while read f; do echo -ne '' > $f; done;
|
|
|
|
echo "==> Clearing last login information"
|
|
>/var/log/lastlog
|
|
>/var/log/wtmp
|
|
>/var/log/btmp
|
|
|
|
# Whiteout root
|
|
count=$(df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}')
|
|
let count--
|
|
dd if=/dev/zero of=/tmp/whitespace bs=1024 count=$count
|
|
rm /tmp/whitespace
|
|
|
|
# Whiteout /boot
|
|
count=$(df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}')
|
|
let count--
|
|
dd if=/dev/zero of=/boot/whitespace bs=1024 count=$count
|
|
rm /boot/whitespace
|
|
|
|
# Zero out the free space to save space in the final image
|
|
dd if=/dev/zero of=/EMPTY bs=1M
|
|
rm -f /EMPTY
|
|
|
|
# Make sure we wait until all the data is written to disk, otherwise
|
|
# Packer might quite too early before the large files are deleted
|
|
sync
|