Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: HOWTO: Remove Older Kernels via GUI

  1. #1
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    HOWTO: Remove Older Kernels via GUI

    HOWTO: Remove Older Kernels via GUI (or CLI)

    When new kernels are introduced and installed the older kernels remain in the system. They are located in the /boot folder and are displayed in the Grub menu. Over time, unless the older kernels are removed, the Grub menu will continue to expand, as will the space occupied in the /boot folder.

    Should the user wish to remove one or more older kernels there are several ways to do so. Physically removing a kernel from the OS will also remove it from the Grub 2 menu once the Grub menu is updated with the "update-grub" command. Another method is to manually edit the Grub 2 scripts to display only an assigned number of kernels (even if more kernels are retained in /boot).

    Note: Users should consider keeping a known, working older kernel. This provides insurance in case the user experiences problems with a newly-introduced kernel. The older kernel will be displayed on the Grub 2 menu as long as it remains in the /boot folder.

    The "CLI" portion of the title is due to the contributions of Ubuntu Forum contributor slakkie, who wrote the script in Post #2. Thank you slakkie.

    An Easy GUI Method - Ubuntu-Tweak

    Ubuntu Tweak is an excellent GUI third-party application which can easily remove older kernels. It is independent of Grub and will work with Grub legacy and Grub 2. It performs a variety of common Ubuntu tasks, one of which is to remove older kernels. Ubuntu Tweak removes older kernels and updating Grub afterwards will remove them from the menu.

    To install Ubuntu-Tweak:
    Ubuntu-Tweak is not currently in the normal respositories. Go to the Ubuntu-Tweak site, http://ubuntu-tweak.com/ and, click on the "Download" button.
    • If prompted, allow Gdebi to install the package automatically;
    • Download the package and double click the .deb file to install Ubuntu-Tweak; or
    • Install using the terminal. Change to the folder containing the .deb file and run
      Code:
      sudo dpkg -i ubuntu-tweak*.deb

    To run Ubuntu-Tweak:
    Main Menu: System Tools > Ubuntu Tweak
    or
    Code:
    ubuntu-tweak
    • Select "Package Cleaner" on the left and ""Clean Kernel" from the right panel.
    • Press the "Unlock" button at the lower right, enter your password.
    • Select from the displayed list the kernel images and headers you wish to remove. The kernel in use is not listed.
    • Press the "Cleanup" button at the lower right to remove the selected kernel images and headers.

    Update Grub to refresh the menu:
    This should be run by Ubuntu Tweak after it removes the kernel, but to be sure:
    Code:
    sudo update-grub

    Removing Kernels via Synaptic

    First, determine which kernel you are using:
    Code:
    uname -r
    Open Synaptic via System > Administration > Synaptic; or
    Code:
    gksu synaptic
    Search for the kernels by typing linux-image in the upper right search box.

    • The kernels are those that being with "linux-image".
      • Example: linux-image-2.6.32-24, linux-image-2.6.32-24-generic.
      • The older kernels will have lower ending numbers. linux-image-2.6.32-23 is older than linux-image-2.6.32-24
    • Those with green selection boxes are currently installed.


    Remove unused kernels as you would any other package by right clicking the package and selecting the desired option.

    You can also remove the associated linux-headers and linux-restricted-modules-... for the earlier versions. Example: linux-headers-2.6.32-23

    Hint: An easy way to find all the installed kernels, headers and modules for a given kernel is to type the main kernel version (2.6.XX) into the top search bar. Click on the top left column status entry in the package window to bring the installed packages (green boxed) to the top of the list.

    When you delete a an older kernel via synaptic the kernel is removed from the computer and more disk space is freed up. The grub configuration file (grub.cfg) is updated and the deleted kernel will no longer be displayed on the menu. Make sure you are satisfied with the performance of newly-released kernels before deleting older ones.

    Hiding Kernels via Grub Customizer
    If you want to keep the kernels on your system, but don't want them displayed, you can use a Grub 2 GUI app called "Grub Customizer". It's a great app that allows the user to hide, rename and reorder the items which appear in the Grub menu. Here is a link which explains how to use it:
    HOWTO: Grub Customizer


    Hiding Kernels via the Grub 2 Scripts
    The number of displayed kernels can be set by modifying the /etc/grub.d/10_linux file. It is documented in Section 2 of my Grub 2 Title Tweaks This tweak hides the kernels but does not remove them from the OS. Note: Recommended only for geeks.

    Other Notes

    Linux kernels, headers and modules can also be removed via the command line (terminal), but if you want to attempt this you probably don't need this guide.

    To hide specific kernels from the menu there is now a GUI app called Grub Customizer that can easily accomplish the task. See the following link:
    Grub Customizer

    For Grub Legacy (Grub 1), the GUI application Startup-Manager can limit the number of displayed kernels. It will not remove them from the OS. For more information on StartUp-Manager, review this thread: HOWTO: StartUp Manager & Kernel Display Options StartUp-Manager currently does not support limiting kernel displays for Grub 2.
    Last edited by drs305; April 4th, 2011 at 02:00 AM.
    GRUB2

    Retired.

  2. #2
    Join Date
    May 2006
    Location
    Amsterdam
    Beans
    1,731
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: HOWTO: Remove Older Kernels via GUI

    I made a cli version for this, had it a long time ago, for Ubuntu, recently made a version which supports Debian/Ubuntu and has been tested on:

    • Ubuntu 8.04 LTS / 10.10
    • Debian stable / testing / unstable


    The rmkernel function below will remove all kernels, kernel header, kernel modules and backport packages except for the running kernel. The function will make sure that any kernel package related to your current kernel will stay installed. As said, all others will be removed. The script depends on aptitude, so for those who haven't installed that package yet: sudo apt-get install aptitude

    Regular warnings apply:
    • Use this only when your current kernel is working as expected, since we do remove all kernels and kernel modules for kernels which we are not running.
    • This script will not work in a chrooted environment.



    Include these functions in your .bashrc/.zshrc:

    Code:
    _egrep-pattern () {
            [ -z "$1" ] && return
            local regexp=$1
            shift
            for i in $*
            do
                    regexp="$regexp|$i" 
            done
            echo ${regexp}
    }
    
    rmkernel () {
            local cur_kernel="$(uname -r)"
            local all_kernels="$(dpkg -l | grep -- linux- | egrep -- "-(image|headers|backports|modules|firmware)" \
            | grep "^ii" | awk '{print $2}')"
            local cur_kernel_pkgs="$(echo -e "$all_kernels" | grep "$cur_kernel$")"
            local cur_kernel_img=$(echo -e "$cur_kernel_pkgs" | grep image)
            local cur_kernel_hdr=$(echo -e "$cur_kernel_pkgs" | grep headers)
            if [ -z "$cur_kernel_img" ]
            then
                    echo "Unable to get the current kernel package. What are you doing?" >&2
                    echo "Possibly running in a chroot, eitherway aborting!" >&2
                    return 1
            fi
            local cur_kernel_img_rdepends="$(apt-cache rdepends $cur_kernel_img | tail -n +3)"
            local cur_kernel_hdr_rdepends
            local cur_kernel_hdr_depends
            if [ -n "$cur_kernel_hdr" ]
            then
                    cur_kernel_hdr_rdepends="$(apt-cache rdepends $cur_kernel_hdr | tail -n +3)" 
                    cur_kernel_hdr_depends="$(apt-cache depends $cur_kernel_hdr | egrep 'linux-(image|headers)' | grep Depends | awk '{print $2}')" 
            fi
            local keep="$(_egrep-pattern $cur_kernel_pkgs $cur_kernel_img_rdepends $cur_kernel_hdr_rdepends $cur_kernel_hdr_depends)"
            if [ -z "$keep" ]
            then
                    echo "Unable to determine which kernels to keep!" >&2
                    echo "This should not happen in normal circumstances" >&2
                    return 1
            fi
            local remove="$(echo -e "$all_kernels" | egrep -v "^($keep)$")"
            local rm_modules="$(find /lib/modules -mindepth 1 -maxdepth 1 -type d ! -name ${cur_kernel} )"
            if [ -n "$remove" ] || [ -n "$rm_modules" ]
            then
                    echo "Going to remove the following kernel packages:" $remove
                    echo "Going to remove the following kernel modules directories afterwards:" $rm_modules
                    echo "Waiting 5 seconds for ctrl-c to abort mission"
                    sleep 3
                    echo -n ..2
                    sleep 1
                    echo -n ..1
                    sleep 1
                    echo "..Start removal"
                    if [ -n "$remove" ]
                    then
                            sudo aptitude -y purge $remove
                    fi
                    [ -n "$rm_modules" ] && sudo rm -rf $rm_modules
            fi
            return 0
    }
    Source your .bashrc/.zshrc.

    Now run rmkernel from your shell and you will remove all unneeded kernel packages. Enjoy!
    Last edited by slakkie; March 22nd, 2011 at 11:48 AM. Reason: Added firmware (natty and up)
    Upgrade Ubuntu | Upgrade unsupported Ubuntu versions | Always backup | Howto upgrade flash
    Minimal CD install | Remove old kernels | My blog | Linux user #462801 | Conscience doth make cowards of us all. -- Shakespeare

  3. #3
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: HOWTO: Remove Older Kernels via GUI

    slakkie

    Thanks for this contribution. I have successfully run this and it worked as advertised. Of course, I also made a copying mistake and am responsible for slakkie's inserted warning.

    If you aren't familiar with .bashrc, "Source your .bashrc/.zshrc." means you should either close all your terminals and reopen them or run "source .bashrc" (for most) to 'refresh' with the new .bashrc contents.
    GRUB2

    Retired.

  4. #4
    Join Date
    May 2006
    Location
    Amsterdam
    Beans
    1,731
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: HOWTO: Remove Older Kernels via GUI

    No worries, I added an extra check, we shouldn't get into your situation again.
    Upgrade Ubuntu | Upgrade unsupported Ubuntu versions | Always backup | Howto upgrade flash
    Minimal CD install | Remove old kernels | My blog | Linux user #462801 | Conscience doth make cowards of us all. -- Shakespeare

  5. #5
    Join Date
    Mar 2011
    Beans
    13
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: HOWTO: Remove Older Kernels via GUI

    Hi dr305,
    thanks for this, very clear summary of methods and issues, I've downloaded Ubuntu-Tweak because good tools are always handy but did my clean-up using synaptic, because this is the inherent system procedure and 'should always work' on a properly-functioning install.
    Cheers,
    Ceriyx

  6. #6
    Join Date
    May 2010
    Beans
    28

    Re: HOWTO: Remove Older Kernels via GUI

    Just run:

    dpkg -l | grep linux-image-2; echo; uname -a

    The list are the installed kernels, the line on its own is the running kernel. You can use apt-get to remove the kernels but NOT the runing one. No need for 3rd party apps. You can do it yourself.
    Last edited by ActionParsnip; May 11th, 2011 at 09:38 PM. Reason: Wrong grep string

  7. #7
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: HOWTO: Remove Older Kernels via GUI

    Quote Originally Posted by ActionParsnip View Post
    Just run:

    dpkg -l | grep linux-image-2; echo; uname -a

    The list are the installed kernels, the line on its own is the running kernel. You can use apt-get to remove the kernels but NOT the runing one. No need for 3rd party apps. You can do it yourself.
    Thanks for the command. One of Linux' advantages is multiple ways of accomplishing tasks.

    One of the things Ubuntu Tweak does is also list the headers, and provides the option to clean those up as well. Depending on what command you use, in a terminal they would normally need to be uninstalled separately from the associated kernel.
    Last edited by drs305; May 11th, 2011 at 09:29 PM.
    GRUB2

    Retired.

  8. #8
    Join Date
    May 2010
    Beans
    28

    Re: HOWTO: Remove Older Kernels via GUI

    Yeah missed the - sign, my bad. True there is more than one way but if space is not a luxury or if you want to stick to official packages then the method I detailed is great

  9. #9
    Join Date
    Jul 2011
    Beans
    25

    Re: HOWTO: Remove Older Kernels via GUI

    Quote Originally Posted by ActionParsnip View Post
    Yeah missed the - sign, my bad. True there is more than one way but if space is not a luxury or if you want to stick to official packages then the method I detailed is great
    Hi, I have a diddifferent problem; in fact, two problems. First, let me tell you that I'm a zero tech-wise.

    I did a clean install of 10.04 and wanted to remove 9.10. So I formatted HD1 and installed Lucid.(Karmic was on the same disk before formatting). I have another HD for my files and old xp install that I don't use. I encounter two problems now:

    1. I went the synaptic way and tried to remove other kernels than "2.26.32.28-generic" which the terminal says I'm running while on Lucid. Two of the images listed are 2.26.32.38 and 2.26.32.32. Since the number is bigger than .28 I wasn't sure if I should remove these.

    2. So, I used Grub-customiser and unticked these two and XP in the hope that I'll get a faster direct boot into Lucid. When I booted next, to my surprise I found my computer booting into Karmic!(I used system > about ubuntu to find out) I thought I wiped the harddisk clean! A check of grub on reboot showed a new kernel 2.26.32.14. It was not there earlier. And it is not showing in grub optimiser, either.

    3. This 2.26.32.14 thing is listed as the first thing in grub. While I can move down the arrow keys to .28 and get into Lucid, my wife and kid, worse than me technically, are ending up in program-less Karmic. Some times you miss the 3 seconds that grub gives you to choose OS.

    3. While on this, Is it okay to untick memtest entries in grub optimiser? And lastly, Is there a way computer boots into Lucid without going through grub?

    I should also mention that I had a failed instal of Lucid (freeze at ubuntu screen; was trying dual-boot of karmic-lucid) before I went the fomtting route. I have two small 13gb, 26gb filesystems on my second hard disk now which I otherwise use only for data.

    Any help is much appreciated. I'm sorry If I posted it in the wrong forum (tutorial). I didn't know where else

    RK
    Last edited by rkanth; July 9th, 2011 at 02:56 PM.

  10. #10
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: HOWTO: Remove Older Kernels via GUI

    Yes, you can untick the memtest entry. It's not normally needed and you can always enable the entry if you end up wanting to run it.

    What I would first recommend is that you boot into Lucid (it doesn't matter the kernel version as long as you end up in Lucid).

    Next I would ensure Grub is from your Lucid installation. This command assumes sda is your Ubuntu drive. Don't use the partition number.
    Code:
    sudo grub-install /dev/sda
    I would then update your system to make sure you have the latest kernel:
    Code:
    sudo apt-get update && sudo apt-get upgrade
    If it finds a new kernel, you will be asked to reboot. Do so.

    Next, I would install and use Ubuntu Tweak to clean up your kernel list. It won't let you remove the currently-running kernel, and normally you should keep at least one extra kernel that you know works. You can go to the first post in this thread to read about installing and using Ubuntu Tweak. The Lucid kernels should all start with "2.6.32". The latest is 2.6.32-32.

    Removing or adding a kernel should run the script to update Grub2, but I'd run it anyway:
    Code:
    sudo update-grub
    Finally, you can open up Grub Customizer with (hopefully) a valid set of Lucid kernels and choose which ones you want to display.
    GRUB2

    Retired.

Page 1 of 4 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •