Autoremove - linux-image

THX @Jappe

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
+++-========================================-============-============-===================================
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:~#

We remove /etc/apt/apt.conf.d/01autoremove from our images, but it is coming back by times. /etc/apt/apt.conf.d/01autoremove.dpkg-dist should actually not be effective, is it? The .dpkg-dist suffix indicates that dpkg added this since the actual “config file” was manually removed. So it does not restore removed configs by default, but installs them with a suffix, same as if a config file is manually edited, it does not just overwrite it. But if /etc/apt/apt.conf.d/01autoremove.dpkg-dist was effectively used by APT, that would be a problem :smile:.

Anyway:

sudo rm -v /etc/apt/apt.conf.d/*autoremove*
sudo apt autopurge

Generally it is true that a kernel should better not be removed before the new one got loaded (after a reboot), but it is not critical. When removing the currently loaded kernel, of course kernel modules for that kernel cannot be loaded anymore. But unless specific new software is installed, like container engines, firewalls, VPN servers or such, this is rarely the case. And then you will get a moreless clear error message that the kernel module does not exist (for the loaded kernel). And e.g. dietpi-software will warn you in the first place that no kernel modules were found and that a reboot is most likely needed.

Most SBCs come with non-versioned kernel packages, i.e. linux-image-<branch>-<vendor> is upgraded, implying the removal of old kernel and modules. So that “safety” feature keeping old kernels is x86_64, and was only recently added to RPi packaging, with the release of the RPi 5. And there it is possibe only due to separation of /boot and /boot/firmware, otherwise the limited RPi boot partition would be full quickly, especially with autoremove-protection in place :sweat_smile:.

If I look at

/etc/apt/apt.conf.d

it only contains this:

Torben

Did linux-image-6.12.57+deb13-amd64 autoremove now, or is it still kept? It is not marked hold, right?

apt-mark showhold

It is still kept

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
+++-========================================-============-============-===================================
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:~#

Is it among those lists?

apt-mark showhold
apt-mark showmanual

No, to the first

root@DietPi:~# apt-mark showhold
root@DietPi:~#

Yes to the second

root@DietPi:~# apt-mark showmanual
7zip
acpi-support-base
alsa-utils
apt
bash-completion
bzip2
ca-certificates
cifs-utils
console-setup
cron
curl
dbus-user-session
dosfstools
dropbear
e2fsprogs
ethtool
exfatprogs
fake-hwclock
fdisk
ffmpeg
firmware-ath9k-htc
firmware-atheros
firmware-brcm80211
firmware-carl9170
firmware-intel-graphics
firmware-intel-sound
firmware-iwlwifi
firmware-mediatek
firmware-realtek
firmware-sof-signed
flac
gdisk
gpg
grub-efi-amd64
grub-efi-amd64-signed
hdparm
htop
i965-va-driver
ifupdown
initramfs-tools
intel-microcode
iputils-ping
isc-dhcp-client
iw
kmod
libicu76
libpci3
linux-base
linux-image-6.12.57+deb13-amd64
linux-image-amd64
locales
mawk
mesa-vulkan-drivers
nano
nfs-common
os-prober
parted
procps
psmisc
rsync
samba
shim-signed
smartmontools
smbclient
sudo
systemd-sysv
systemd-timesyncd
tzdata
udev
unzip
usbutils
wget
whiptail
wireless-regdb
wireless-tools
wpasupplicant
x11-utils
x11-xserver-utils
xfonts-base
xinit
xserver-xorg-core
xserver-xorg-input-libinput
zstd
root@DietPi:~#

Just installed Kernel : 6.12.74+deb13+1-amd64 and did a reboot. Than used

apt autoremove

This removed the old version.

But there are still leftovers that need to be removed manually:

root@DietPi:~# dpkg --list | grep linux-image
rc  linux-image-6.12.73+deb13-amd64   6.12.73-1                            amd64        Linux 6.12 for 64-bit PCs (signed)
ii  linux-image-6.12.74+deb13+1-amd64 6.12.74-2                            amd64        Linux 6.12 for 64-bit PCs (signed)
ii  linux-image-amd64                 6.12.74-2                            amd64        Linux for 64-bit PCs (meta-package)
root@DietPi:~#

Using:

apt purge linux-image-6.12.73+deb13-amd64

than it looks like:

root@DietPi:~# dpkg --list | grep linux-image
ii  linux-image-6.12.74+deb13+1-amd64 6.12.74-2                            amd64        Linux 6.12 for 64-bit PCs (signed)
ii  linux-image-amd64                 6.12.74-2                            amd64        Linux for 64-bit PCs (meta-package)
root@DietPi:~#

Torben