User Tools

Site Tools


vm:clean-vm.sh

This is an old revision of the document!


This is the clean-vm.sh script that cleans up the student's home directory and frees up space in the VM before creating a golden image.

Do not run this on a VM you are already using, as this will wipe out a number of files in the student home directory.

#!/bin/bash
 
echo "Removing unused packages..."
apt auto-remove -y
 
 
echo "Cleaning logs..."
# Stop logging service
service rsyslog stop
# Clear logs
logrotate -f /etc/logrotate.conf
rm /var/log/*.gz /var/log/*.1
 
 
echo "Cleaning /tmp and /var/tmp..."
rm -rf /tmp/*
rm -rf /var/tmp/*
 
 
echo "Removing SSH keys..."
rm -rf ~student/.ssh/*
rm -rf ~root/.ssh/*
 
 
echo "Removing configuration files and histories..."
rm -rf ~root/.bash_history
rm -rf ~student/.bash_history
rm -rf ~student/.mozilla/firefox
rm -rf ~student/.ipython
rm -rf ~student/.chisubmit
rm -rf ~student/.vim
rm -rf ~student/.emacs.d
rm -rf ~student/.gitconfig
rm -rf ~student/.local/share/recently-used.xbel
rm -rf ~student/.config/sublime-text-3
 
 
echo "Removing old snaps..."
# From https://www.linuxuprising.com/2019/04/how-to-remove-old-snap-versions-to-free.html
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
    while read snapname revision; do
        snap remove "$snapname" --revision="$revision"
    done
 
 
echo "Clearing caches..."
apt clean
rm -rf ~student/.cache
rm -rf /root/.cache
rm -rf /var/lib/apt/lists/*
rm -rf /var/lib/snapd/cache/*
 
 
echo "Adding SSH host key for mit.cs.uchicago.edu..."
ssh-keyscan -H mit.cs.uchicago.edu > ~student/.ssh/known_hosts
ssh-keyscan -H $(dig +short mit.cs.uchicago.edu) >> ~student/.ssh/known_hosts
chown -R student.student ~student/.ssh
 
 
sync
/var/lib/dokuwiki/data/attic/vm/clean-vm.sh.1587039784.txt.gz · Last modified: 2020/04/16 07:23 by borja

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki