Skip to content

Instantly share code, notes, and snippets.

@evenme
Last active March 8, 2016 17:18
Show Gist options
  • Save evenme/218238d2a2a555bf3b24 to your computer and use it in GitHub Desktop.
Save evenme/218238d2a2a555bf3b24 to your computer and use it in GitHub Desktop.
Perform cleanup of Linux template creation for vagrant
# Stop logging services.
systemctl stop rsyslog
systemctl stop auditd
# Remove old kernels
yum install yum-utils -y
package-cleanup --oldkernels --count=1 -y
# Clean out yum
yum clean all
# Force the logs to rotate & remove old logs
logrotate --force /etc/logrotate.conf
rm -f /var/log/*-???????? /var/log/*.gz
rm -f /var/log/dmesg.old
rm -rf /var/log/anaconda
rm -f /var/log/vboxadd-*
# Truncate the logs
cat /dev/null > /var/log/audit/audit.log
cat /dev/null > /var/log/dmesg
cat /dev/null > /var/log/wtmp
cat /dev/null > /var/log/btmp
cat /dev/null > /var/log/lastlog
cat /dev/null > /var/log/grubby
# Remove the udev persistent device rules
rm -f /etc/udev/rules.d/70*
# Remove the traces of the template MAC address and UUIDs
sed -i '/^\(NETBOOT\|IPV6\|HWADDR\|UUID\)/d' /etc/sysconfig/network-scripts/ifcfg-eth*
# Clean /tmp out
rm -rf /tmp/*
rm -rf /var/tmp/*
# Remove the root user’s SSH history & other cruft
rm -rf ~root/.ssh/
rm -f ~root/anaconda-ks.cfg
# zero out the drive
dd if=/dev/zero of=/EMPTY bs=1M
sync
rm -f /EMPTY
# clear the bash_history and exit root
cat /dev/null > ~/.bash_history && history -c && unset HISTFILE && exit
cat /dev/null > ~/.zhistory && echo $HISTFILE && rm $HISTFILE && exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment