Autoremove - linux-image

When updating (apt upgrade) this morning I did get this information:

The following package was automatically installed and is no longer required:
  linux-image-6.12.57+deb13-amd64
Use 'apt autoremove' to remove it.
Upgrading:
  base-files  exfatprogs  intel-microcode  libc6        libcom-err2      libgnutls30t64   linux-image-amd64  rsync
  bash        gpg         libc-bin         libcap2      libext2fs2t64    libmbedcrypto16  locales            sqv
  e2fsprogs   gpgconf     libc-l10n        libcap2-bin  libglib2.0-0t64  libss2           logsave

Installing dependencies:
  linux-image-6.12.63+deb13-amd64

Suggested packages:
  firmware-linux-free  linux-doc-6.12  debian-kernel-handbook

Recommended packages:
  apparmor

Summary:
  Upgrading: 23, Installing: 1, Removing: 0, Not Upgrading: 0
  Download size: 136 MB
  Space needed: 167 MB / 503 GB available

When using apt autoremov this warning came up:

REMOVING:
  linux-image-6.12.57+deb13-amd64

Summary:
  Upgrading: 0, Installing: 0, Removing: 1, Not Upgrading: 0
  Freed space: 111 MB

Continue? [Y/n]

 
                                                                                                               │
  │ You are running a kernel (version 6.12.57+deb13-amd64) and attempting to remove the same version.                │
  │                                                                                                                  │
  │ This can make the system unbootable as it will remove /boot/vmlinuz-6.12.57+deb13-amd64 and all modules under    │
  │ the directory /lib/modules/6.12.57+deb13-amd64. This can only be fixed with a copy of the kernel image and the   │
  │ corresponding modules.                                                                                           │
  │                                                                                                                  │
  │ It is highly recommended to abort the kernel removal unless you are prepared to fix the system after removal.    │
  │                                                                                                                  │
  │ Abort kernel removal?

On one hand the process tells me it linux-image-6.12.57+deb13-amd64 is no longer needed and on other hands it tells me that it is not a good idea to remove it.

You installed a newer kernel (linux-image-6.12.63+deb13-amd64) but did not restart the system.
It’s not recommended to remove the active kernel, that’s why the message appears.

After a restart there is nothing:

root@DietPi:~# apt autoremove
Summary:
  Upgrading: 0, Installing: 0, Removing: 0, Not Upgrading: 0
root@DietPi:~#

Its fine how it is now.

OK - but a bit strange

Why? This is plain Debian apt feature. It has nothing to do with DietPi. It will look like same on all Debian based systems if you install a new kernel and try to remove the binary afterwards without a reboot. Usually this is going to work, but you should reboot the system right after.

What kernel are you running now?

uname -r
root@DietPi:~# uname -r
6.12.63+deb13-amd64
root@DietPi:~#

Ok you could’ve also remove it without a reboot, see https://dietpi.com/forum/t/auto-removed-kernel-am-i-in-trouble/23179/12?u=jappe
dunno why it’s gone without the autoremove. Did you install it via dietpi-update?

I installed it with the command “apt upgrade”

old kernel image is left on storage for sure

just to be clear

ls -la /boot/
root@DietPi:~# ls -la /boot/
total 122233
drwxr-xr-x  5 root root     4096 Jan 18 07:00 .
drwxr-xr-x 18 root root     4096 Dec 14 20:59 ..
-rw-r--r--  1 root root       83 Nov  5 15:56 System.map-6.12.57+deb13-amd64
-rw-r--r--  1 root root       83 Dec 30 20:37 System.map-6.12.63+deb13-amd64
-rw-r--r--  1 root root   283279 Nov  5 15:56 config-6.12.57+deb13-amd64
-rw-r--r--  1 root root   283288 Dec 30 20:37 config-6.12.63+deb13-amd64
drwxr-xr-x  4 root root     4096 Dec 14 20:59 dietpi
-rw-r--r--  1 root root    18092 Oct 18  2024 dietpi-LICENSE.txt
-rw-r--r--  1 root root    16152 Oct 18  2024 dietpi-README.md
-rw-------  1 root root     3950 Oct 29  2024 dietpi-wifi.txt
-rw-r--r--  1 root root    18009 Sep 21 06:31 dietpi.txt
drwxr-xr-x  3 root root      512 Jan  1  1970 efi
drwxr-xr-x  5 root root     4096 Jan 18 06:59 grub
-rw-r--r--  1 root root 49310109 Nov 15 17:23 initrd.img-6.12.57+deb13-amd64
-rw-r--r--  1 root root 50972804 Jan 18 07:00 initrd.img-6.12.63+deb13-amd64
-rw-r--r--  1 root root 12101568 Nov  5 15:56 vmlinuz-6.12.57+deb13-amd64
-rw-r--r--  1 root root 12105664 Dec 30 20:37 vmlinuz-6.12.63+deb13-amd64
root@DietPi:~#

So the autoremove message appeared because of apt’s dependency logic, but kernels are exluded from autoremove because of this:

root@RPi4:~# cat /etc/apt/apt.conf.d/01autoremove.dpkg-dist 
APT
{
  NeverAutoRemove
  {
	"^firmware-linux.*";
	"^linux-firmware$";
	"^linux-image-[a-z0-9]*$";
	"^linux-image-[a-z0-9]*-[a-z0-9]*$";
  };

  VersionedKernelPackages
  {
	# kernels
	"linux-.*";
	"kfreebsd-.*";
	"gnumach-.*";
	# (out-of-tree) modules
	".*-modules";
	".*-kernel";
  };

  Never-MarkAuto-Sections
  {
	"metapackages";
	"tasks";
  };

  Move-Autobit-Sections
  {
	"oldlibs";
  };
};

You would need to remove them manually, but it’s recommended to keep at least one older kernel on which your system ran stable.

You can list them with

dpkg --list | grep linux-image

and then just use apt or dpkg to remove them

THX :slight_smile:

root@DietPi:~# dpkg --list | grep linux-image
rc  linux-image-6.12.41+deb13-amd64 6.12.41-1                            amd64        Linux 6.12 for 64-bit PCs (signed)
rc  linux-image-6.12.43+deb13-amd64 6.12.43-1                            amd64        Linux 6.12 for 64-bit PCs (signed)
rc  linux-image-6.12.48+deb13-amd64 6.12.48-1                            amd64        Linux 6.12 for 64-bit PCs (signed)
ii  linux-image-6.12.57+deb13-amd64 6.12.57-1                            amd64        Linux 6.12 for 64-bit PCs (signed)
ii  linux-image-6.12.63+deb13-amd64 6.12.63-1                            amd64        Linux 6.12 for 64-bit PCs (signed)
ii  linux-image-amd64               6.12.63-1                            amd64        Linux for 64-bit PCs (meta-package)
root@DietPi:~#

But how to remove them? The first 3 on the list?

Also worth noting that the entries with rc are just config leftovers and not installed and functional kernels.
ii are installed and configured kernels.

https://askubuntu.com/questions/18804/what-do-the-various-dpkg-flags-like-ii-rc-mean

can you run following again

apt update
apt autoremove

No impact

root@DietPi:~# apt update
Hit:1 https://deb.debian.org/debian trixie InRelease
Hit:2 https://deb.debian.org/debian trixie-updates InRelease
Hit:3 https://deb.debian.org/debian-security trixie-security InRelease
Hit:4 https://deb.debian.org/debian trixie-backports InRelease
Hit:5 https://dietpi.com/apt trixie InRelease
All packages are up to date.
root@DietPi:~# apt autoremove
Summary:
  Upgrading: 0, Installing: 0, Removing: 0, Not Upgrading: 0
root@DietPi:~#

apt autoremove is not working - no impact

root@DietPi:~# dpkg -l linux-image*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                     Version      Architecture Description
+++-========================================-============-============-===================================
rc  linux-image-6.12.41+deb13-amd64          6.12.41-1    amd64        Linux 6.12 for 64-bit PCs (signed)
un  linux-image-6.12.41+deb13-amd64-unsigned <none>       <none>       (no description available)
rc  linux-image-6.12.43+deb13-amd64          6.12.43-1    amd64        Linux 6.12 for 64-bit PCs (signed)
un  linux-image-6.12.43+deb13-amd64-unsigned <none>       <none>       (no description available)
rc  linux-image-6.12.48+deb13-amd64          6.12.48-1    amd64        Linux 6.12 for 64-bit PCs (signed)
un  linux-image-6.12.48+deb13-amd64-unsigned <none>       <none>       (no description available)
ii  linux-image-6.12.57+deb13-amd64          6.12.57-1    amd64        Linux 6.12 for 64-bit PCs (signed)
un  linux-image-6.12.57+deb13-amd64-unsigned <none>       <none>       (no description available)
ii  linux-image-6.12.63+deb13-amd64          6.12.63-1    amd64        Linux 6.12 for 64-bit PCs (signed)
un  linux-image-6.12.63+deb13-amd64-unsigned <none>       <none>       (no description available)
ii  linux-image-amd64                        6.12.63-1    amd64        Linux for 64-bit PCs (meta-package)
un  linux-image-generic                      <none>       <none>       (no description available)
root@DietPi:~#

it seems that the only way to remove the old versions is:

root@DietPi:~# apt purge linux-image-6.12.41+deb13-amd64
REMOVING:
  linux-image-6.12.41+deb13-amd64*

Summary:
  Upgrading: 0, Installing: 0, Removing: 1, Not Upgrading: 0
  Space needed: 0 B / 503 GB available

Continue? [Y/n]

Would it be safe to remove 41, 43 and 48?

THX

Kernel images are exluded from autoremove functionality

Yes