Google Plus

How to uninstall the old kernels in ubuntu

Written by Mel Kham on . Posted in Linux tutorials

Everytime there is an update for the kernel, the new kernel is installed while the old one is not automaticaly uninstalled, after several kernel updates, you will find a large list of old kernels in the start grub menu . So if we got no problem with the new installed kernel, we can just delete the old ones.

Today i will show you how to uninstall the old kernels, it is important to keep at least one old kernel, so in case if you have any problem with the new one, you can then  switch to the old kernel.





First use this command to see the list of the installed kernels in your Ubuntu : 

$ dpkg --get-selections | grep linux-image

In my case :

Now for example try to delete the oldest one (change oldest kernel with your oldest one) :

$ sudo apt-get purge oldest-kernel 

In my case :

$ sudo apt-get purge linux-image-2.6.31-14-generic

If the kernel you try to uninstall is not updated, you will got a message to update first before to continue. update then the kernel and then uninstall that old kernel and the updates using the same command above.

Important : Do not uninstall the linux-image-generic as it is necessary to receive updates of the kernel.

Thanks to guia ubuntu for this tip ( In spanish)


For questions please refer to our Q/A forum at : http://ask.unixmen.com

Mel Kham

Founder of Unixmen, Living in Amsterdam. Am working in my free time to help people to understand the Opensource and to explain them in easy way how to make the fist steps to the the light. Working day and night with my Co-founder Zinovsky to keep this website live even with less resources.
  • http://sites.google.com/site/mametitles/ Giorgos

    Or just uninstall them, with Ubuntu Tweak! :D

  • Rajasun

    An alternative method is as such:
    1.
    For a listing of unused linux headers, image, and modules:

    dpkg -l ‘linux-*’ | sed ‘/^ii/!d;/’”$(uname -r | sed “s/\(.*\)-\([^0-9]\+\)/\1/”)”‘/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d’

    2.
    To purge them:
    sudo 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

    Also do have a look at http://ubuntuforums.org/showpost.php?p=8514471&postcount=10

  • http://tuxicity.wordpress.com tuxicity

    In 9.10 you get this message :
    The following packages were automatically installed and are no longer required:
    linux-headers-2.6.31-14 linux-headers-2.6.31-14-generic
    Use ‘apt-get autoremove’ to remove them.
    So sudo apt-get autoremove does the trick.
    This tip is obsolete. 8)

  • Rico Chopete

    When you get warnings of this kind, what should you do AND WHY does this happen?

    dpkg – warning: while removing linux-headers-2.6.24-19-generic, directory `/lib/modules/2.6.24-19-generic’ not empty so not removed.

    dpkg – warning: while removing linux-ubuntu-modules-2.6.24-16-generic, directory `/lib/firmware/2.6.24-16-generic’ not empty so not removed.

    rmdir: failed to remove `/lib/modules/2.6.24-19-generic’: Directory not empty
    dpkg – warning: while removing linux-image-2.6.24-19-generic, directory `/lib/modules/2.6.24-19-generic/kernel/drivers/input/misc’ not empty so not removed.

  • jkr

    professor@ProfessorAnonymous:~$ dpkg –get-selections | grep linux-image
    linux-image-2.6.32-28-generic deinstall
    linux-image-2.6.32-32-generic deinstall
    linux-image-2.6.32-33-generic deinstall
    linux-image-2.6.32-34-generic deinstall
    linux-image-2.6.32-35-generic deinstall
    linux-image-2.6.32-36-generic deinstall
    linux-image-2.6.32-38-generic deinstall
    linux-image-2.6.32-39-generic deinstall
    linux-image-2.6.32-40-generic deinstall
    linux-image-2.6.32-41-generic install
    linux-image-2.6.32-42-generic install
    linux-image-3.2.0-30-generic install
    linux-image-generic install
    professor@ProfessorAnonymous:~$ sudo apt-get purge linux-image-2.6.32-28-generic[sudo] password for professor:
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    The following packages were automatically installed and are no longer required:
    libktnef4 libosip2-4 libkimproxy4 kdebase-runtime kdelibs5 libkxmlrpcclient4
    libeina-svn-05 kdesudo ruby1.8 libqgpgme1 ruby libkrossui4 libkblog4
    kdepimlibs5 libexosip2-4 update-manager-kde libruby1.8 libsyndication4
    libreadline5 libgpgme++2
    Use ‘apt-get autoremove’ to remove them.
    The following packages will be REMOVED:
    linux-image-2.6.32-28-generic linux-image-2.6.32-32-generic
    linux-image-2.6.32-33-generic linux-image-2.6.32-34-generic
    linux-image-2.6.32-35-generic linux-image-2.6.32-36-generic
    linux-image-2.6.32-38-generic linux-image-2.6.32-39-generic
    linux-image-2.6.32-40-generic
    0 upgraded, 0 newly installed, 9 to remove and 5 not upgraded.
    18 not fully installed or removed.
    After this operation, 894 MB disk space will be freed.
    Do you want to continue [Y/n]? y
    (Reading database … 270647 files and directories currently installed.)
    Removing linux-image-2.6.32-28-generic …
    Running postrm hook script /usr/sbin/update-grub.
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    User postrm hook script [/usr/sbin/update-grub] exited with value 2
    Examining /etc/kernel/postrm.d .
    run-parts: executing /etc/kernel/postrm.d/initramfs-tools 2.6.32-28-generic /boot/vmlinuz-2.6.32-28-generic
    update-initramfs: Deleting /boot/initrd.img-2.6.32-28-generic
    run-parts: executing /etc/kernel/postrm.d/zz-update-grub 2.6.32-28-generic /boot/vmlinuz-2.6.32-28-generic
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 2
    Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-2.6.32-28-generic.postrm line 321.
    dpkg: error processing linux-image-2.6.32-28-generic (–remove):
    subprocess installed post-removal script returned error exit status 2
    No apport report written because MaxReports is reached already
    Removing linux-image-2.6.32-32-generic …
    Running postrm hook script /usr/sbin/update-grub.
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    User postrm hook script [/usr/sbin/update-grub] exited with value 2
    Examining /etc/kernel/postrm.d .
    run-parts: executing /etc/kernel/postrm.d/initramfs-tools 2.6.32-32-generic /boot/vmlinuz-2.6.32-32-generic
    update-initramfs: Deleting /boot/initrd.img-2.6.32-32-generic
    run-parts: executing /etc/kernel/postrm.d/zz-update-grub 2.6.32-32-generic /boot/vmlinuz-2.6.32-32-generic
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 2
    Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-2.6.32-32-generic.postrm line 321.
    dpkg: error processing linux-image-2.6.32-32-generic (–remove):
    subprocess installed post-removal script returned error exit status 2
    No apport report written because MaxReports is reached already
    Removing linux-image-2.6.32-33-generic …
    Running postrm hook script /usr/sbin/update-grub.
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    User postrm hook script [/usr/sbin/update-grub] exited with value 2
    Examining /etc/kernel/postrm.d .
    run-parts: executing /etc/kernel/postrm.d/initramfs-tools 2.6.32-33-generic /boot/vmlinuz-2.6.32-33-generic
    update-initramfs: Deleting /boot/initrd.img-2.6.32-33-generic
    run-parts: executing /etc/kernel/postrm.d/zz-update-grub 2.6.32-33-generic /boot/vmlinuz-2.6.32-33-generic
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 2
    Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-2.6.32-33-generic.postrm line 321.
    dpkg: error processing linux-image-2.6.32-33-generic (–remove):
    subprocess installed post-removal script returned error exit status 2
    No apport report written because MaxReports is reached already
    Removing linux-image-2.6.32-34-generic …
    Running postrm hook script /usr/sbin/update-grub.
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    User postrm hook script [/usr/sbin/update-grub] exited with value 2
    Examining /etc/kernel/postrm.d .
    run-parts: executing /etc/kernel/postrm.d/initramfs-tools 2.6.32-34-generic /boot/vmlinuz-2.6.32-34-generic
    update-initramfs: Deleting /boot/initrd.img-2.6.32-34-generic
    run-parts: executing /etc/kernel/postrm.d/zz-update-grub 2.6.32-34-generic /boot/vmlinuz-2.6.32-34-generic
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 2
    Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-2.6.32-34-generic.postrm line 321.
    dpkg: error processing linux-image-2.6.32-34-generic (–remove):
    subprocess installed post-removal script returned error exit status 2
    No apport report written because MaxReports is reached already
    Removing linux-image-2.6.32-35-generic …
    Running postrm hook script /usr/sbin/update-grub.
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    User postrm hook script [/usr/sbin/update-grub] exited with value 2
    Examining /etc/kernel/postrm.d .
    run-parts: executing /etc/kernel/postrm.d/initramfs-tools 2.6.32-35-generic /boot/vmlinuz-2.6.32-35-generic
    update-initramfs: Deleting /boot/initrd.img-2.6.32-35-generic
    run-parts: executing /etc/kernel/postrm.d/zz-update-grub 2.6.32-35-generic /boot/vmlinuz-2.6.32-35-generic
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 2
    Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-2.6.32-35-generic.postrm line 321.
    dpkg: error processing linux-image-2.6.32-35-generic (–remove):
    subprocess installed post-removal script returned error exit status 2
    No apport report written because MaxReports is reached already
    Removing linux-image-2.6.32-36-generic …
    Running postrm hook script /usr/sbin/update-grub.
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    User postrm hook script [/usr/sbin/update-grub] exited with value 2
    Examining /etc/kernel/postrm.d .
    run-parts: executing /etc/kernel/postrm.d/initramfs-tools 2.6.32-36-generic /boot/vmlinuz-2.6.32-36-generic
    update-initramfs: Deleting /boot/initrd.img-2.6.32-36-generic
    run-parts: executing /etc/kernel/postrm.d/zz-update-grub 2.6.32-36-generic /boot/vmlinuz-2.6.32-36-generic
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 2
    Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-2.6.32-36-generic.postrm line 321.
    dpkg: error processing linux-image-2.6.32-36-generic (–remove):
    subprocess installed post-removal script returned error exit status 2
    No apport report written because MaxReports is reached already
    Removing linux-image-2.6.32-38-generic …
    Running postrm hook script /usr/sbin/update-grub.
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    User postrm hook script [/usr/sbin/update-grub] exited with value 2
    Examining /etc/kernel/postrm.d .
    run-parts: executing /etc/kernel/postrm.d/initramfs-tools 2.6.32-38-generic /boot/vmlinuz-2.6.32-38-generic
    update-initramfs: Deleting /boot/initrd.img-2.6.32-38-generic
    run-parts: executing /etc/kernel/postrm.d/zz-update-grub 2.6.32-38-generic /boot/vmlinuz-2.6.32-38-generic
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 2
    Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-2.6.32-38-generic.postrm line 321.
    dpkg: error processing linux-image-2.6.32-38-generic (–remove):
    subprocess installed post-removal script returned error exit status 2
    No apport report written because MaxReports is reached already
    Removing linux-image-2.6.32-39-generic …
    Running postrm hook script /usr/sbin/update-grub.
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    User postrm hook script [/usr/sbin/update-grub] exited with value 2
    Examining /etc/kernel/postrm.d .
    run-parts: executing /etc/kernel/postrm.d/initramfs-tools 2.6.32-39-generic /boot/vmlinuz-2.6.32-39-generic
    update-initramfs: Deleting /boot/initrd.img-2.6.32-39-generic
    run-parts: executing /etc/kernel/postrm.d/zz-update-grub 2.6.32-39-generic /boot/vmlinuz-2.6.32-39-generic
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 2
    Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-2.6.32-39-generic.postrm line 321.
    dpkg: error processing linux-image-2.6.32-39-generic (–remove):
    subprocess installed post-removal script returned error exit status 2
    No apport report written because MaxReports is reached already
    Removing linux-image-2.6.32-40-generic …
    Running postrm hook script /usr/sbin/update-grub.
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    User postrm hook script [/usr/sbin/update-grub] exited with value 2
    Examining /etc/kernel/postrm.d .
    run-parts: executing /etc/kernel/postrm.d/initramfs-tools 2.6.32-40-generic /boot/vmlinuz-2.6.32-40-generic
    update-initramfs: Deleting /boot/initrd.img-2.6.32-40-generic
    run-parts: executing /etc/kernel/postrm.d/zz-update-grub 2.6.32-40-generic /boot/vmlinuz-2.6.32-40-generic
    /usr/sbin/grub-mkconfig: 4: /etc/default/grub: Syntax error: “(” unexpected
    run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 2
    Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-2.6.32-40-generic.postrm line 321.
    dpkg: error processing linux-image-2.6.32-40-generic (–remove):
    subprocess installed post-removal script returned error exit status 2
    No apport report written because MaxReports is reached already
    Errors were encountered while processing:
    linux-image-2.6.32-28-generic
    linux-image-2.6.32-32-generic
    linux-image-2.6.32-33-generic
    linux-image-2.6.32-34-generic
    linux-image-2.6.32-35-generic
    linux-image-2.6.32-36-generic
    linux-image-2.6.32-38-generic
    linux-image-2.6.32-39-generic
    linux-image-2.6.32-40-generic
    E: Sub-process /usr/bin/dpkg returned an error code (1)

Like us on Facebook

This week Top Posts

Write for us

Recent Comments

Nova

|

I wonder if there is a way to create your own themes.

Red Adaya

|

Thank you! This worked for me!!!

SK

|

Andrew look into your httpd.conf file at line no 350. There might be a syntax error.

andrew

|

hello I have this error

[root@cloud html]# /etc/init.d/httpd restart

then this appears

Starting httpd: httpd: Syntax error on line 350 of /etc/httpd/conf/httpd.conf: without matching section.

plz tell how to fix this.

 
IDG Tech Network
Copyright © 2008-2013 Unixmen.com .
Maintained by Anblik .