Skip to content

Instantly share code, notes, and snippets.

@jjuarez
Last active August 29, 2015 14:02
Show Gist options
  • Save jjuarez/cc45d5e8d4ed8d94975c to your computer and use it in GitHub Desktop.
Save jjuarez/cc45d5e8d4ed8d94975c to your computer and use it in GitHub Desktop.
Shellscript for clean our VM images
# Mount the img (qcow2)
guestmount -a my_vm.qcow2 -i /mnt/my_vm —rw
# Hacemos chroot
chroot /mnt/my_vm
# Clean yum information
/usr/bin/yum —enablerepo=extra,repos,if,apply clean all
# Rotate logs
/usr/sbin/logrotate -f /etc/logrotate.conf
/bin/rm -f /var/log/*-???????? /var/log/*.gz
# Clear the audit log
/bin/cat /dev/null > /var/log/audit/audit.log
/bin/cat /dev/null > /var/log/wtmp
# Remove all the udev persistent device rules
/bin/rm -f /etc/udev/rules.d/70*
# Remove the traces of the template MAC address and UUIDs
for vif in /etc/sysconfig/network-scripts/ifcfg-eth?; do
/bin/sed -i ‘/^\(HWADDR\|UUID\)=/d’ ${vif}
done
# Clean /tmp
/bin/rm -rf /var/tmp/*
# Remove SSH host keys
/bin/rm -f /etc/ssh/*_key /etc/ssh/*_key.pub
# Clean
/bin/rm -f ~root/.bash_history
unset HISTFILE
# Unmount FS
umount /mnt/my_vm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment