Forums » Tips and Tricks

Remove Old Kernels

    • 17 posts
    September 17, 2012 11:04 AM PDT

    After an apt-get dist-upgrade to a new kernel will leave the old kernel still on the hard drive.  While these kernels are between 150-250MB which is tiny these days, it may be a good idea to remove them yearly to free up some space.

     

    Here's the complete article if you'd like the details, but if you're just looking to add this to your cleaning list here's the command:

     

    dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge

    • 563 posts
    September 18, 2012 11:42 AM PDT
    Good stuff...thanks for contributing.
    • 6 posts
    May 26, 2013 11:50 AM PDT

    Although it is probably obvious, it may be worthwhile mentioning that this also applies to Synaptic and Update Manager. I had been running Update Manager in WattOS R6 regularly and there had been several kernel updates. One day, Update Manager failed to install an update (thus creating a broken package) but, unfortunately, it did not explain what the problem was. After several frustrating attempts to install the failed package, I changed to using Synaptic which told me that it didn't have enough disk space to install the update. I tried deleting some old log files but this barely made any improvement (the disk was still 97% full). By using du to find large directories, I eventually found out that I had at least 10 kernels installed and the headers in /usr/src were taking up huge amounts of disk space. I did not realise that, unlike applications where the new version replaces the old one, new kernels are installed alongside the old one(s). I used Synaptic to uninstall all but the last 3 kernels and now disk space is only 47% used! Yes, you read that right: 7 or 8 kernels were taking up 50% of the disk space....

     

    Admittedly, the disk is not large by today's standards but I felt that it was worth mentioning because some modern PCs are fitted with SSDs for speed and, as they are still expensive, they tend to rather small.

     

    patermann

    • 17 posts
    May 30, 2013 6:06 AM PDT

    Glad this helped you!