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?


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:


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).

  • 1
    Nearly four years later, your warnings remain true. I was just a lazy -y away from... a headache day, when I read the confirmation a bit more closely than I normally would. What a close call! – Fissure King Apr 6 '16 at 11:26
  • You can recover from it, it's just a pain in the bottom when you're not expecting it. – Oli Apr 6 '16 at 11:34

Uninstalling Mainline Kernels

The mainline kernels have their own ABI namespace so they install side by side with the stock Ubuntu kernels (each kernel has a separate directory under /lib/modules/VERSION for example). This means that you can keep several mainline and Ubuntu stock kernels installed at the same time and select the one you need from the GRUB boot menu.

If you would like to uninstall a mainline kernel anyway, first use:

dpkg -l | grep "linux\-[a-z]*\-"

to find the exact name of the kernel packages you want to uninstall, and then do:

sudo apt-get remove KERNEL_PACKAGES_TO_REMOVE

Remember that several packages belong to one kernel version: common headers, architecture specific headers and the architecture specific image.

Source: https://wiki.ubuntu.com/Kernel/MainlineBuilds#Uninstalling_Mainline_Kernels

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.