Wednesday, October 23, 2013

Remove Old Linux Kernel Images in Ubuntu from Command Line

As you upgrade your Ubuntu Linux, the number of different versions of Linux kernel images grow. The Linux kernel images can occupy quite some disk space. Your /boot file system may be short of space for future upgrades of Linux kernels. It may look for a method to remove the old Linux kernel images. The following discussion suggests that we remove old kernel images using "Synaptic Package Manager",


However, it requires a graphical user interface. I am more interested in removing the old Linux kernel images using command line tools only, as sometimes, I simply do not have the luxury of running a GUI. However, the discussion above indeed a good guide. I simply follow the steps below,

  1. Find the versions of Linux kernel images and their packages.

    You may first list the content of the /boot directory, which gives you an idea what kernel images are installed. Then you can use dpkg to find out the package names. Here is an example,
    userfoo@ubuntu:~$ dpkg -l | grep linux | grep 3.0
    ii linux-image-3.0.0-12-generic 3.0.0-12.20 i386 Linux kernel image for version 3.0.0 on x86/x86_64
    userfoo@ubuntu:~$

    In the above, I am looking for "3.0" because I figured from listing the content of the /boot directory that I have a Linux image of version of 3.0.0 installed. The above tells me that the corresponding package of the Linux image is "linux-image-3.0.0-12-generic".
  2. Remove the Linux image package.

    I remove the above Linux image package using apt-get.
    userfoo@ubuntu:~$ sudo apt-get remove linux-image-3.0.0-12-generic
Repeat the above steps for other versions of old Linux images. Typically, as suggested by many other people, you want to keep at least one or two old Linux image to fall back on in case there is an issue with your newest Linux kernel image.

Similar method can be applied to CentOS and Fedora Linux. You can accomplish it using yum alone.


No comments:

Post a Comment