No Boot Space No iNodes

When I set up my QEMU virtual machine system I made a couple of mistakes. As I was running on a host that had very limited resources I made the virtual machines as small as I possibly could and that has come back to bite me at bit. The two problems I seem to constantly suffer from are running out space on the boot partition and, on one machine, running out of inodes.

In my previous article about this problem I discussed what to do to prevent running out of space on the boot partition but it seems that on it’s own isn’t quite enough to prevent outbreaks of general nastiness. Firstly, rather than removing just the kernel you want to remove associated packages as well. This is a better command for removing an old kernel:

sudo apt-get remove linux-image-3.13.0-57

By not specifying the -generic on the end of the package name apt will wildcard select related packages. Obviously you want to check the list of selected packages carefully but generally you’re good to go.

The above command doesn’t, however, remove the kernel headers that get installed. On most machines this will never be an issue but on one of my virtual machines with a very small drive this does cause a problem. Oddly the machine didn’t run out of drive space it ran out of inodes (presumably the header files are quite small). To clean up the headers you can issue more apt-get remove commands or better you can purge the packages with dpkg. I prefer the purge method because it also cleans up the list of kernels that were installed previously. To find out what’s consuming all the inodes you can use a script called count_em which is linked in the reference section below.

First get the name of the current kernel. Take care not to bash this one:

uname -r

Now list all the kernels that the system knows about (e.g. ones that are or were installed). This command is nice because it automatically hides the currently installed kernel:

dpkg -l | tail -n +6 | grep -E 'linux-image-[0-9]+' | grep -Fv $(uname -r)

Getting your iNodes back

Any kernel with rc before it’s name is fair game for total purging. Any kernel with ii before it’s name is fair game for apt-get remove and then purging. Take care not to remove the last good kernel though, it’s always a good idea to have a known good spare. Now purge the kernels and headers that you don’t want:

sudo dpkg --purge linux-image-3.13.0-57-generic
sudo dpkg --purge linux-headers-3.13.0-57-generic
sudo dpkg --purge linux-headers-3.13.0-57

The last two commands may or may not work depending on whether the headers are still installed.

To find out if you’ve run out of space or inodes check the output of:

df -h
df -i

Note that you can also carry this process out quickly and efficiently using aptitude. With aptitude simply select the generic header package you don’t want any more (e.g. linux-headers-3.13.0.-57-generic) and select purge (use the _ key). Aptitude will automatically select the base package as well (e.g. linux-headers-3.13.0.-57).  Press g and then g again to make the change.