Wednesday, July 27, 2016

apt - How to remove kernels from previous release


See question How to remove kernels from previous release? which is marked as duplicate. I ask this again, because the question is special case and not handled in the answers for the related question. I upgraded from 15.10 to 16.04 using an installation media. Kernels from 15.10 are there at /boot, but the package management system seems to be unaware of this after upgrade. Related bug report is here. I do not know, if this happens, if you choose to upgrade in Software Updater.



If the kernels are not known to dpkg, you can remove them by hand by deleting all their files (I do this to remove locally compiled kernels: How can I remove compiled kernel?)


First check which kernel is running with uname -r


DO NOT DELETE THE RUNNING KERNEL


Let's say you want to delete kernel release 3.19.0-56 from your system.


You can use the release string to locate all of its files and directories. locate -b -e 3.19.0-56 will find existing (-e) files & directories with the string 3.19.0-56 without listing all the files in all the directories (-b)


Having located them, you can append the command to remove them rm -r with xargs. Let's use the -p flag to make xargs interactive, so that we can see the targets and confirm before the command is executed. Here's the whole command:


locate -b -e 3.19.0-56 | xargs -p sudo rm -r

Then type y to really execute rm -r on the targets shown


(this throws some errors complaining that everything that is not a directory does not exist because you're attempting to delete it recursively with -r, but it still works and the files are really gone - check again with sudo updatedb && locate -b -e 3.19.0-56 and nothing will be found)


Finally, to clean the boot menu, run


sudo update-grub

No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...