Last active
March 8, 2016 17:18
-
-
Save evenme/218238d2a2a555bf3b24 to your computer and use it in GitHub Desktop.
Perform cleanup of Linux template creation for vagrant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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