Announcement

Collapse
No announcement yet.

Get rid of old Kernels?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Get rid of old Kernels?

    I'd like to remove some old kernels but not sure how to proceed the right way and have Grub2 work correctly. If you could lend a hand I'd appreciate it. Thanx for any help!

    Bob
    Being able to access the internet whilst answering a call of nature was 'one of life's most liberating experiences.'  Vic Hayes

    #2
    Re: Get rid of old Kernels?

    Basically, use your package manager to remove the kernels and related files:

    Kernels, removing from GRUB menu, Rog131:
    HOWTO: Removing unnecessary entries from the grub menu list
    http://kubuntuforums.net/forums/inde...opic=3082556.0

    (just take the parts related to removing the kernels; applies to GRUB 2 also)
    An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

    Comment


      #3
      Re: Get rid of old Kernels?

      Thank you sir, I appreciate it! Here's another little one I just found, same stuff just worded different.

      #


      # Removing Entries from Grub 2
      Entries should be removed by editing or removing files in the /etc/grub.d folder. The /boot/grub/grub.cfg file is read-only and should not normally require editing.

      * Automatically.
      o Too Many Kernels? Kernels removed via Synaptic or with "apt-get remove" will automatically update grub.cfg and no user action is required.
      + In Synaptic, type the kernel number in the search window at the upper right (for example - 2.6.28-11).
      + Find the "linux-image" and "linux-headers" files for the applicable kernel (example - linux-image-2.6.26-11 or "linux-image-2.6.26-11-generic).
      + Right click and select "Mark for Complete Removal" and then press the Apply main menu button.
      + The kernels will be removed from your system and from the Grub menu.
      + If you are not sure of the kernel you are currently using, in a terminal type "uname -r".
      + Many users keep one previous kernel on the machine which previously ran without problems.
      o Other Operating Systems which have been removed from the computer will also be removed from the menu once "update-grub2" is run as root.
      o To prevent one of the /etc/init.d files from running, remove the "executable" bit.
      + Example: If you don't want to see the "Memtest86+" entries, run this command:
      Code:

      sudo chmod -x /etc/grub.d/20_memtest86+

      + Run the update-grub command to allow the changes to be incorporated in grub.cfg

      Being able to access the internet whilst answering a call of nature was 'one of life's most liberating experiences.'  Vic Hayes

      Comment


        #4
        Re: Get rid of old Kernels?

        Thanx again Qqmike, Worked like a charm and I got my boot order the way I want it again and all is right in my world. Have a good weekend! ;o)

        Bob
        Being able to access the internet whilst answering a call of nature was 'one of life's most liberating experiences.'  Vic Hayes

        Comment


          #5
          Re: Get rid of old Kernels?

          Glad it went smooth, now we can both have a good weekend!

          Thanks for the feedback.
          --Mike
          An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

          Comment


            #6
            Re: Get rid of old Kernels?

            Yesterday, I got bored of the kids asking which was the right Kubuntu to choose each time they boot the computer. Of course, they are not able to remember the simple answer "the first one in the list is the good one". Since I've four boxes to maintain, I came up with this rather long one liner to remove all kernels but the last installed one

            Code:
            sudo dpkg -l | grep ^ii | grep linux-image | awk '{ print $2 }' | sort | head -n -2 | xargs sudo apt-get -y remove
            Type it in a single line. It just lists all the packages, looks for the installed ones (whose lines start with ii), looks for the ones called linux-image, gets the package name, sorts the list and removes the last two (the generic linux-image and your latest kernel) and removes the rest.

            For safety, I always execute all of the command except what is after the last pipe to check that it is going to remove only older kernels.

            Warning: use at your own risk, this command may burn your house and destroy your computer. Don't ask me if something goes wrong, I would not know how to fix it if it removes all your kernels, for example.

            Comment


              #7
              Re: Get rid of old Kernels?

              Here's a good description of kernels and how to remove them from one of the Ubuntu members.

              Pay special note to the function rmkernel:
              Code:
              rmkernel () {
                  local cur_kernel=$(uname -r|sed 's/-*[a-z]//g'|sed 's/-386//g')
                  local kernel_pkg="linux-(image|headers|ubuntu-modules|restricted-modules)"
                  local meta_pkg="${kernel_pkg}-(generic|i386|server|common|rt|xen|ec2)"
                  sudo aptitude purge $(dpkg -l | egrep $kernel_pkg | egrep -v "${cur_kernel}|${meta_pkg}" | awk '{print $2}')
                  purge_pkg
              }
              Boot Info Script

              Comment


                #8
                Re: Get rid of old Kernels?

                When you do remove old kernels, be sure to keep the most recent kernel that worked, in case the next kernel upgrade doesn't work as well on your box.
                "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
                – John F. Kennedy, February 26, 1962.

                Comment


                  #9
                  Re: Get rid of old Kernels?

                  WARNING!

                  This reply, and others in this thread includes a bash command line 'script' that will alter your system if run. I've put that portion of the command in red. NEVER execute a script you see if you do not fully understand what it will do. Not everyone writes qualified scripts, and not all scripts are safe to run.
                  Originally posted by barbolani
                  sudo dpkg -l | grep ^ii | grep linux-image | awk '{ print $2 }' | sort | head -n -2 | xargs sudo apt-get -y remove
                  Nice. A little testing with it here finds that you can shorten it to:
                  Code:
                  sudo dpkg -l | grep ^ii | grep linux-image | awk '{ print $2 }' | head -n -2 | xargs sudo apt-get -y remove
                  and get the same results. For testing, I omitted the last part:
                  Code:
                  | xargs sudo apt-get -y remove
                  Test results on my system:
                  Code:
                  sudo dpkg -l | grep ^ii | grep linux-image | awk '{ print $2 }' | sort | head -n -2
                  linux-image-2.6.31-17-generic
                  Code:
                  sudo dpkg -l | grep ^ii | grep linux-image | awk '{ print $2 }' | head -n -2
                  linux-image-2.6.31-17-generic
                  And I do have more than one kernel installed:
                  Code:
                  sudo dpkg -l | grep ^ii | grep linux-image | awk '{ print $2 }'
                  linux-image-2.6.31-17-generic
                  linux-image-2.6.31-19-generic
                  linux-image-generic
                  Windows no longer obstructs my view.
                  Using Kubuntu Linux since March 23, 2007.
                  "It is a capital mistake to theorize before one has data." - Sherlock Holmes

                  Comment

                  Working...
                  X