I’ve had an issue twice before where something filled up the hard drive and caused the server to crash. Once it was a hacked / compromised wordpress site and once it was excessive session files generated. I wrote about how I handled it once before in this post.
I used a similar process today to try to free up some space today and I thought I’d document the steps I took to save me time when I have to do this again in the future.
First, I again ran the ncdu linux command which is a great way to see what directories are using up the most space.
/var/log/journal was using over 3gb of space. In one of the directories there were a bunch of journal files. I checked online and it looks like it is safe to delete journal files. There was a nice post about how to remove the journal files and also set the system to keep removing old journal files when they are using too much space. This allowed me to quickly free up an extra 2.5gb of space. Until I better understand what the journal files are used for, I’m not going to set-up a regular process to remove old files yet. I hadn’t needed to do this previously even though I’ve had this server for about a year now. Perhap when I do it the next time I’ll be more aggressive in having it cull old files on a regular basis.
/var/lib/snapd directory had about 500mg of space used. I checked and there is a command to remove these snap files too. It looks like it is only retaining 2 versions of each snap, so I probably already have it set to remove anything more than 3. I will leave things as is for this directory.
/usr/src there are a bunch of linux header files taking up about 1gb of space. There is a command to remove old linux header files that are no longer needed. I used:
sudo apt-mark auto '^linux-headers-.*' sudo apt autoremove
That removed over 2gb of space – many files in addition to the linux headers got removed with that one.
I didn’t see any other obvious directories taking up unnecessary space. Freeing up 5gb of space is pretty good for my small server. I could have just upgraded the server to a bigger SSD, but I should be able to keep my websites safely running within the space I have. The websites themselves generally don’t use that much space. It is the server management software that sometimes gets a bit unruly.
I’m not super experienced with linux and having to do occasional file maintenance like this is a bit of a hassle. Overall, it has been very infrequent that I’ve needed to do this though. For me, It is a relatively small price to pay to have my own, very fast, private server at a very reasonable cost.