Unless you’ve freshly installed Ubuntu or Linux Mint Ubuntu & Debian Editions, you’ll probably notice that each time you boot up, the GRUB bootloader menu lists a bunch of previous Linux kernels which you can boot into. While this can come in handy for disasters – if you suddenly can’t boot into the new kernel after an upgrade – those previous kernels, images and modules are mostly just wasting disk space.

While you can manually go into Synaptic Package Manager, search for all the bits and pieces of previous kernels, and mark them for removal, here is a much easier method, thanks to Kana, she’s a Linux consultant and teaches me Linux using Mint, OpenSuSE and Debian. In a terminal, simply paste the following command, and it will remove all but the current kernel (if you’ve upgraded your system, or had an update with a new kernel, please reboot your machine before running this). It will also remove old graphics driver modules for old kernels, and modules related to VirtualBox if installed:

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

Yeah, I know, looks like Geek hieroglyphics, doesn’t it? Kana said she studied the docs for Debian Packager and Apt to get all that! You will see some info about what is going on:

The following packages will be REMOVED:
linux-headers-2.6.35-22* linux-headers-2.6.35-22-generic*
linux-headers-2.6.35-23* linux-headers-2.6.35-23-generic*
linux-image-2.6.32-25-generic* linux-image-2.6.35-22-generic*
0 upgraded, 0 newly installed, 7 to remove and 13 not upgraded.
After this operation, 586MB disk space will be freed.
(Reading database … 261863 files and directories currently installed.)
Removing linux-headers-2.6.35-22-generic …
Removing linux-headers-2.6.35-22 …
Removing linux-headers-2.6.35-23-generic …
Removing linux-headers-2.6.35-23 …
Removing linux-image-2.6.32-25-generic …

It will then generate a new GRUB menu, and when you reboot, you’ll see only the current kernel is listed. Kana uses this all the time, she says she’s never had any trouble with it 🙂 Aren’t geeky girlfriends cool?

Be Sociable, Share!
Leave a Reply