How can we remove the unused linux kernels and at the same time have our boot configuration (grub’s entries in the grub cfg menu) updated?
First we want to list all the kernel-related packages, like linux-image and linux-headers, linux-generic, etc:
$ dpkg -l linux-*
On my 10.04 Ubuntu system the above command results in the following list of packages:
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Description
+++-======================-======================-============================================================
ii linux-alsa-driver-modu 2.6.32-28.201103131600 Ubuntu-supplied Linux modules for version 2.6.32-28-generic
un linux-backports-module (no description available)
un linux-doc-2.6.32 (no description available)
ii linux-firmware 1.34.7 Firmware for Linux kernel drivers
ii linux-generic 2.6.32.38.44 Complete Generic Linux kernel
un linux-headers (no description available)
un linux-headers-2.6 (no description available)
un linux-headers-2.6-686 (no description available)
un linux-headers-2.6-amd6 (no description available)
ii linux-headers-2.6.32-2 2.6.32-21.32 Header files related to Linux kernel version 2.6.32
ii linux-headers-2.6.32-2 2.6.32-21.32 Linux kernel headers for version 2.6.32 on x86/x86_64
ii linux-headers-2.6.32-2 2.6.32-28.55 Header files related to Linux kernel version 2.6.32
ii linux-headers-2.6.32-2 2.6.32-28.55 Linux kernel headers for version 2.6.32 on x86/x86_64
ii linux-headers-2.6.32-3 2.6.32-30.59 Header files related to Linux kernel version 2.6.32
ii linux-headers-2.6.32-3 2.6.32-30.59 Linux kernel headers for version 2.6.32 on x86/x86_64
ii linux-headers-2.6.32-3 2.6.32-33.72 Header files related to Linux kernel version 2.6.32
ii linux-headers-2.6.32-3 2.6.32-33.72 Linux kernel headers for version 2.6.32 on x86/x86_64
ii linux-headers-2.6.32-3 2.6.32-38.83 Header files related to Linux kernel version 2.6.32
ii linux-headers-2.6.32-3 2.6.32-38.83 Linux kernel headers for version 2.6.32 on x86/x86_64
ii linux-headers-2.6.32-3 2.6.32-39.86 Header files related to Linux kernel version 2.6.32
ii linux-headers-generic 2.6.32.38.44 Generic Linux kernel headers
un linux-image (no description available)
un linux-image-2.6 (no description available)
ii linux-image-2.6.32-21- 2.6.32-21.32 Linux kernel image for version 2.6.32 on x86/x86_64
ii linux-image-2.6.32-28- 2.6.32-28.55 Linux kernel image for version 2.6.32 on x86/x86_64
ii linux-image-2.6.32-30- 2.6.32-30.59 Linux kernel image for version 2.6.32 on x86/x86_64
ii linux-image-2.6.32-33- 2.6.32-33.72 Linux kernel image for version 2.6.32 on x86/x86_64
ii linux-image-2.6.32-38- 2.6.32-38.83 Linux kernel image for version 2.6.32 on x86/x86_64
ii linux-image-generic 2.6.32.38.44 Generic Linux kernel image
un linux-initramfs-tool (no description available)
un linux-kernel-headers (no description available)
un linux-kernel-log-daemo (no description available)
ii linux-libc-dev 2.6.32-38.83 Linux Kernel Headers for development
un linux-restricted-commo (no description available)
ii linux-sound-base 1.0.22.1+dfsg-0ubuntu3 base package for ALSA and OSS sound systems
un linux-source-2.6.32 (no description available)
un linux-tools (no description available)
These are all the “linux-” packages that dpkg knows of at the moment (installed and not installed). Let’s say we want to remove all the kernels except the most recent one. Actually, leaving one of the older ones, just in case, is usually a good idea 😉
We’ll use awk and grep to filter the above list, getting just the 2nd column (which contains the actual names of packages) for those rows which contain the unwanted packages. The easiest thing to do (especially if you’re not a grep/gawk guru) is to use the unwanted kernel versions as a grep search string at the same time telling awk to print just the 2nd column, e.g. this will print all the packages of the 2.6.32-30 kernel:
$ dpkg -l linux-* | awk '{ print $2 }' | grep -w 30
linux-headers-2.6.32-30
linux-headers-2.6.32-30-generic
linux-image-2.6.32-30-generic
We can now give all of these files to apt-get (via xargs) for removal:
$ dpkg -l linux-* | awk '/^ii/{ print $2 }' | grep -w 30 | xargs sudo apt-get -y purge
… do the same for all the other kernel packages that you no longer want on your system.
One Response to How to uninstall the old kernels in Ubuntu (and grub)
Leave a Reply Cancel reply
-
Categories
- Android Development
- Bash
- C programming
- dpkg/apt-get
- drupal
- Emacs
- Git
- Java
- Linux administration
- Linux device drivers
- Linux Gaming
- Linux kernel
- Linux Networking
- Linux on Windows
- Linux printing
- Linux sound and ALSA
- Package Managers
- Programming
- RPM
- Shell and environment
- Tips and tricks
- Uncategorized
- VirtualBox
- Virtualization
- web development
- wine
- WMaker
- Wordpress Tips
- X Window System
- XFCE
-
Articles
- August 2020
- August 2019
- May 2019
- July 2017
- February 2017
- January 2017
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- April 2016
- March 2016
- December 2015
- November 2015
- September 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- October 2014
- February 2014
- January 2014
- November 2013
- October 2013
- June 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- October 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- September 2011
- August 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
-
Meta
Cloud
audio bash boot compile C programming cups drupal emacs etc Fedora git grep how to httpd init kernel libc linux linux partition localtime login make mount mp3 mysql networking oracle package managers password phpMyAdmin programming rpm shell sql vbox version control system virtual box vm web server wordpress www xargs xfce xwin yum
Dude, keep up the good work! You’re helping alot of people, even tough most wont leave a comment.
thank you.
~afijgæjfg