LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Ubuntu (https://www.linuxquestions.org/questions/ubuntu-63/)
-   -   Need to remove old versions of Ubuntu kernel (https://www.linuxquestions.org/questions/ubuntu-63/need-to-remove-old-versions-of-ubuntu-kernel-466660/)

sparker1 11-30-2010 04:24 PM

Thank you Totn. This was a very annoying problem for me as my grub list went over two pages. ubuntu tweak could not find these kernels nor did they show up in the package manager. Your solution worked.

tedy58 12-28-2010 11:11 AM

Thanks to all for this helpful topic, but especially @totn,

I did it his way, but before that I do the
$ sudo su
Enter the apssword
cd /boot
update-grub
where it gave me all previously installed kernels and so on, so I easily use firstly
remove all the unwanted staff and then rebuild the grub again and Ohhh miracle all now is clean and ordered.

Thank U m8s.

itismike 09-07-2011 04:38 PM

Thanks for the tips guys. I had six unneeded kernels sitting around and cleaned them up with:
Code:

$ sudo update-grub
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.32-33-server
Found initrd image: /boot/initrd.img-2.6.32-33-server
Found linux image: /boot/vmlinuz-2.6.32-32-server
Found initrd image: /boot/initrd.img-2.6.32-32-server
Found linux image: /boot/vmlinuz-2.6.32-31-server
Found initrd image: /boot/initrd.img-2.6.32-31-server
Found linux image: /boot/vmlinuz-2.6.32-30-server
Found initrd image: /boot/initrd.img-2.6.32-30-server
Found linux image: /boot/vmlinuz-2.6.32-29-server
Found initrd image: /boot/initrd.img-2.6.32-29-server
Found linux image: /boot/vmlinuz-2.6.32-28-server
Found initrd image: /boot/initrd.img-2.6.32-28-server
Found linux image: /boot/vmlinuz-2.6.32-24-server
Found initrd image: /boot/initrd.img-2.6.32-24-server
Found memtest86+ image: /boot/memtest86+.bin
done

Although this step was unnecessary, it was good to see what was currently installed.

Then identify the current version:
Code:

$ uname -a
Linux ubuntu-fog2 2.6.32-33-server #72-Ubuntu SMP Fri Jul 29 21:21:55 UTC 2011 x86_64 GNU/Linux

Note the current version: 2.6.32-33

Code:

ls -aFl
-rw-r--r--  1 root root 8507004 2011-01-31 11:38 initrd.img-2.6.32-24-server
-rw-r--r--  1 root root 8509929 2011-03-01 06:47 initrd.img-2.6.32-28-server
-rw-r--r--  1 root root 8510166 2011-03-02 06:32 initrd.img-2.6.32-29-server
-rw-r--r--  1 root root 8509649 2011-03-18 06:56 initrd.img-2.6.32-30-server
-rw-r--r--  1 root root 8507911 2011-04-29 16:52 initrd.img-2.6.32-31-server
-rw-r--r--  1 root root 8506423 2011-05-30 06:44 initrd.img-2.6.32-32-server
-rw-r--r--  1 root root 8540373 2011-08-22 16:12 initrd.img-2.6.32-33-server
...

Note versions range between 32-24 and 32-32

plus there was an entry for each for:
abi
config
initrd.img
System.map
vmcoreinfo
and vmlinuz


To delete all kernels and associated code I issued the following commands (type carefully!):
Code:

$ sudo rm *2.6.32-2*
$ sudo rm *2.6.32-3[0,1,2]*

Then cleaned up grub:
Code:

$ sudo update-grub
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.32-33-server
Found initrd image: /boot/initrd.img-2.6.32-33-server
Found memtest86+ image: /boot/memtest86+.bin
done
$


oneillkza 09-10-2011 11:47 AM

@itismike I would not choose to do it that way myself. The problem is that, while you may (or may not) have gotten everything deleted for each kernel, apt will not know that you have done so. So your system will have packages which apt thinks are installed (the old kernels) but which are actually in a broken state.

It may not matter too much, since they're old kernels which may not get touched in the future anyway, but it may cause problems, say, when you upgrade the distribution, and it tries to clean them up itself.

It would be much better to use apt to remove each kernel's package (as per the first few posts), so apt and the state of the system are in agreement. I would trust the scripts Canonical or the Debian team have written to clean the kernels up more thoroughly than if you did it by hand. It's also less work and less dangerous.

linuso 02-16-2012 01:24 PM

removing old versions of Ubuntu kernels{solved}2012
 
see method here
Google tuxtweaks.com/2010/10/remove-old-kernels-in-ubuntu-with-one-command/

and the line of code is

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge

tested on 64bit and working

AOINEKO 01-20-2013 01:57 AM

Quote:

Originally Posted by linuso (Post 4604353)
see method here
Google tuxtweaks.com/2010/10/remove-old-kernels-in-ubuntu-with-one-command/

and the line of code is

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge

tested on 64bit and working

careful, this command will uninstall "linux-libc-dev" if you have it installed, this modified version solves that:

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | grep -v lib | xargs sudo apt-get -y purge


All times are GMT -5. The time now is 03:00 AM.