Total break down after running apt-get autoremove

The running kernel should not be an autoremove candidate, that means that something has gone wrong with the apt state on your system, possibly due to manually installing a kernel at some point in the past. (It’s hard to know without seeing the apt logs)

Another possibility is that you upgraded OSMC manually using dist-upgrade and then tried to run autoremove before rebooting while the old kernel is still running. If you waited until after a reboot to run autoremove the problem wouldn’t happen. (But there’s no need to run autoremove for old kernels if you use the standard OSMC updater, see below)

The way we install kernels is by using a meta package, for example on the vero4k it is called vero364-kernel-osmc, the current version of which is 3.5.6. This meta package declares a dependency on the actual desired kernel image file, which is currently vero364-image-3.14.29-17-osmc version 17.

This causes the kernel image package to be automatically installed. So the package is marked as “automatic”, however because it is depended on by another installed package it will never be an autoremove candidate, as only automatic packages which have no other packages depending on them are candidates.

When we push out a new kernel we update the package version of *-kernel-osmc to cause the package to be upgraded, and the new version of this package has its kernel image dependency updated to point to the name of the new kernel image package - this causes the new kernel to be installed, which also makes the new kernel the active kernel.

At this point the old kernel is still in memory until a reboot, and the old kernel package is still installed but is not the active kernel.

We don’t actually rely on apt autoremove at all to remove kernels, mainly because we don’t want to trigger a system wide autoremove just to remove an old kernel.

Instead we have some custom scripting which finds all installed kernel images, and explicitly attempts to remove all of them except for the currently running in memory kernel (via uname -a) and the kernel image that is specified in the *-kernel-osmc package.

This means that when up upgrade all old kernels except the most recent kernel are removed - the most recent kernel is skipped because it is the currently running kernel.

This script only runs when you use the My OSMC updater (blue update screen) not when you manually run dist-upgrade, so if you want to remove old kernels after a manual dist-upgrade reboot first and then run autoremove afterwards.

An idea.

Let’s touch /tmp/kernel-updated.
Our wrapper for apt-get can check for existence and recommend reboot before upgrade first.
My OSMC remains unaffected because it recommends reboot already.

Idea added in:

So now we need to handle that in apt-get wrapper and My OSMC>