21

I installed 14.10 on my laptop Lenovo E455.

And compiled kernel 3.19 with following order

since it seemed that 14.10 doesn't want to work with mine.(I saw slow motions)

Downloaded current kernel from http://www.kernel.org/

make oldconfig
make
sudo make install

Finally, failed to boot with new kernel.

How can I remove the compiled kernel from grub and get recovered?

  • What did you try so far to remove it and where did it go wrong? Where there any warning or error messages? – David Foerster Mar 9 '15 at 18:21
  • Thanks to your help. Got recovered and waiting for Ubuntu 15.XX. – Ohmygirl Mar 10 '15 at 9:56
33

The easy method:

If compiled via the debian method, you can see the installed kernel with the following:

dpkg --list | grep kernel-image

And then uninstall the desired kernel package with apt-get:

sudo apt-get remove kernel-image-your-kernel-image

The hard method:

If compiled and installed via make install, you will need to manually remove the following entries:

/boot/vmlinuz*KERNEL-VERSION*
/boot/initrd*KERNEL-VERSION*
/boot/System-map*KERNEL-VERSION*
/boot/config-*KERNEL-VERSION*
/lib/modules/*KERNEL-VERSION*/
/var/lib/initramfs/*KERNEL-VERSION*/

Then update the grub configuration:

sudo update-grub2
  • 1
    I do not have /var/lib/initramfs/ directory, but is it because I do not have compiled kernels in my system? – jarno Apr 3 '17 at 11:35
  • 1
    /var/lib/initramfs-tools/*KERNEL-VERSION* on Debian – Csaba Toth Mar 29 '18 at 20:49
  • 1
    Consider an edit for newer kernels (year 2018) containing: /boot/abi*KERNEL-VERSION* and /boot/retpoline*KERNEL-VERSION* – WinEunuuchs2Unix Jan 1 '19 at 15:13
10

Thanks to jarno's question here I worked out a way of implementing Mudit Kapil's answer that requires very little typing and catches any extra bits lying around

Since all that is needed to remove the kernel is to delete all its files & directories, and all those files and directories will have the kernel release string in their paths, we can use locate to find all the files with the kernel release string and delete them to remove the kernel.

(First check uname -r to find the name of the currently running kernel & be sure not to delete it)

Say you want to remove a kernel called 4.4.6-my-kernel. You can find all its existing files & directories (without listing the files in all the named directories) with locate -b -e 4.4.6-my-kernel. Appending rm -r to this with xargs allows you to delete the files too. I add -p to make xargs display targets and ask for confirmation before executing

locate -b -e 4.4.6-my-kernel | xargs -p sudo rm -r

then type y to execute rm -r on the targets shown. It will complain that files that are not directories don't exist because you're trying to delete them recursively (-r) but that's OK, they will still be removed along with the directories and their contents. When done, just run

sudo update-grub

et voila.

  • +1 because this catches more files than accepted answer. For example all the dkms stuff. I would run it first without the rm option just to see everything that would be deleted. – WinEunuuchs2Unix Jan 1 '19 at 15:10
  • Why shouldn't I delete the currently running kernel? What if that is the kernel I want to delete? Is it possible to delete the currently running kernel without first restarting the machine with another kernel? – Liran Funaro Jan 15 '19 at 15:12
  • 1
    @LiranFunaro it is possible yes. See my answer How do I uninstall the running kernel by command only? which also explains why it is probably not a good idea – Zanna Jan 15 '19 at 15:24

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.