Thursday, February 21, 2013

Ubuntu: Out of Disk Space


When I first installed Ubuntu on my desktop, I had decided I would like to partition my /home directory from the rest of my filesystem. This way, if an Ubuntu upgrade fails, I can always perform a clean install without having to backup my data. Or, theoretically, I could install another OS and my data would all still be there. When I partitioned the / directory, I decided that 10 GB should be enough.

Well, recently, I've been hitting up against that 10 GB limit. Every day when I boot up my computer, I get a warning that I only have a few hundred MB of space left. Well, today, I'm at 100% usage. I couldn't even send an email out from Thunderbird.

So, I tried clearing space. I tried running
sudo apt-get autoremove

Unfortunately, there was nothing left to autoremove.

I then browsed through /usr/local as that's where I store any applications I need to compile and run. Again, nothing extra to remove.

My last resort was heading to /tmp to clear anything there. However, it didn't make much of a difference.

I was still stuck.


Suddenly, a thought came to me. I've gone through several Ubuntu updates where it installed Linux kernel headers. Maybe that's what was taking up space. After a quick Google search, I came upon a post that would delete all unused Linux headers.

Just to be safe, before running this, restart your machine.
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

This ran in the terminal for some time while it cleaned out all my unused Linux kernel headers. I ended up getting rid of 3 GB of data.

I was free again!

So next time you're running out of room, make sure it isn't some old Linux headers taking up space.