Ubuntu – How to remove a mainline kernel and move back to a supported kernel

bootkernel

I recently upgraded to kernel 3.4 in my Ubuntu 12.04. After that the computer is not booting up. So I used a previous kernel to boot up. Actually I don't want 3.4 kernel. So how can I remove it and use the previous one itself?

Best Answer

How did you install it? If you just grabbed a load of deb files and installed them, getting rid of it is as simple as just finding the packages and running apt-get remove for each of them.

I've just had a cup of coffee so you get to bare the full brunt of my bashfu this morning... This should tell you what kernels are installed:

dpkg -l | awk '/linux-[^ ]+-[0-9]/ {print $2}'

Go through those and note the versions you want to nuke. Take care to also note your current install (uname -a) or any new kernels you have installed since booting. You don't want to remove the newest ones.

Anyway when you've got an idea, you can bulk-remove them by adapting this command:

sudo apt-get purge linux-{headers,image,image-extra}-3.5.0-{7,8,9}.*

The words and numbers in the braces will be expanded at runtime so the packages this will actually target are:

linux-headers-3.5.0-7*
linux-headers-3.5.0-8*
linux-headers-3.5.0-9*
linux-image-3.5.0-7*
linux-image-3.5.0-8*
linux-image-3.5.0-9*
linux-image-extra-3.5.0-7*
linux-image-extra-3.5.0-8*
linux-image-extra-3.5.0-9*

You can mess around with this but for cleaning up I find this much safer than a wide-wildcard (as I currently on a 3.5.* kernel).

Either way, read what apt-get is going to do before you say yes. Removing current kernels and all kernels is a surprisingly common predicament that Ubuntu users find themselves in. It's not unfixable but yeah, don't do it!

Be especially careful with wildcards and apt-get. If you don't believe me run apt-get -s remove linux-image-3.4* and see what it selects (yeah - all the kernels). Don't worry that command is in "simulate mode" so it won't do anything (and so doesn't need root).