Ubuntu – Why is it unsafe to delete old kernels

kernel

I have run out of space on my boot drive, so I decided to remove old kernels. I found this page which describes exactly what I should do: Lubuntu Documentation: Remove Old Kernels.

I have deleted the oldest kernel manually and now it is okay, but I don’t understand one thing: at the end of the article there is some code that can delete all old kernel versions, but it is marked as for advanced users only.

I don’t really understand what the danger is here. It sounds silly, but they seem to say that there might be more than one kernel used by a specific machine at the same time.

Is it possible that different applications on my Ubuntu machine can use different kernels simultaneously? Why is deleting all old kernels automatically considered to be dangerous?

Best Answer

Removing old kernels is not inherently unsafe, but if you remove all your kernels and reboot, you'll be left at an angry Grub screen. Fixing that takes significant know-how (like that but with an apt-get install linux-generic at the end).

The first time you do this is quite thrilling but the people looking to clean up their Grub menu or recover some disk space aren't looking for thrills.

The danger comes from users copy-pasting a block of code that —unbeknownst to them and without acknowledging the risks— doesn't apply. There are many examples of detecting old kernels and few are perfect. Even my latest effort still has its pitfalls. And we're talking about an issue that can be fixed; many posts on Ask Ubuntu could lead to permanent data loss if used incorrectly.

We try to safeguard against damage by signposting the risk to make users conscious of potential problems. In the best case scenarios, the user will be prepared and equipped to deal with a problem and in the worst case, at least they can't complain that they weren't warned.

Related Question