Remove old Kernel's

Hi,

with every kernel-update dietpi/debian keeps the old kernel. How can I remove the old kernels?

Peter

Pls share some more information on your system

Required

  • DietPi version | cat /boot/dietpi/.version
  • Distro version | echo $G_DISTRO_NAME $G_RASPBIAN
  • Kernel version | uname -a
  • Architecture | dpkg --print-architecture
  • SBC model | echo $G_HW_MODEL_NAME or (EG: RPi3)

As well following information is needed

ls -la /boot

G_DIETPI_VERSION_CORE=9
G_DIETPI_VERSION_SUB=2
G_DIETPI_VERSION_RC=1
G_GITBRANCH=‘master’
G_GITOWNER=‘MichaIng’

bookworm

Linux DietPi 6.1.0-20-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.85-1 (2024-04-11) x86_64 GNU/Linux

amd 64

Native PC (x86_64)

insgesamt 662077
drwxr-xr-x  5 root root     4096 14. Apr 10:14 .
drwxr-xr-x 20 root root     4096 17. Mär 02:58 ..
-rw-r--r--  1 root root   236275 21. Okt 2022  config-5.10.0-19-amd64
-rw-r--r--  1 root root   236452 21. Jan 2023  config-5.10.0-21-amd64
-rw-r--r--  1 root root   236469 22. Apr 2023  config-5.10.0-22-amd64
-rw-r--r--  1 root root   259507 27. Jul 2023  config-6.1.0-10-amd64
-rw-r--r--  1 root root   259602  8. Aug 2023  config-6.1.0-11-amd64
-rw-r--r--  1 root root   259602  7. Sep 2023  config-6.1.0-12-amd64
-rw-r--r--  1 root root   259421 29. Sep 2023  config-6.1.0-13-amd64
-rw-r--r--  1 root root   259455 30. Nov 16:41 config-6.1.0-14-amd64
-rw-r--r--  1 root root   259455  9. Dez 16:48 config-6.1.0-15-amd64
-rw-r--r--  1 root root   259455 12. Dez 13:16 config-6.1.0-16-amd64
-rw-r--r--  1 root root   259420 30. Dez 10:31 config-6.1.0-17-amd64
-rw-r--r--  1 root root   259453  1. Feb 09:05 config-6.1.0-18-amd64
-rw-r--r--  1 root root   259525 11. Apr 23:17 config-6.1.0-20-amd64
-rw-r--r--  1 root root   259446  8. Mai 2023  config-6.1.0-9-amd64
drwxr-xr-x  4 root root     4096 17. Mär 02:58 dietpi
-rw-r--r--  1 root root    18092 23. Okt 2022  dietpi-LICENSE.txt
-rw-r--r--  1 root root    15251 23. Okt 2022  dietpi-README.md
-rw-r--r--  1 root root    16252 27. Aug 2023  dietpi.txt
drwxr-xr-x  3 root root      512  1. Jan 1970  efi
drwxr-xr-x  5 root root     4096 14. Apr 10:14 grub
-rw-r--r--  1 root root 35971064  6. Nov 2022  initrd.img-5.10.0-19-amd64
-rw-r--r--  1 root root 35975343 24. Jan 2023  initrd.img-5.10.0-21-amd64
-rw-r--r--  1 root root 37887403 30. Apr 2023  initrd.img-5.10.0-22-amd64
-rw-r--r--  1 root root 45884298 31. Jul 2023  initrd.img-6.1.0-10-amd64
-rw-r--r--  1 root root 45979422 13. Aug 2023  initrd.img-6.1.0-11-amd64
-rw-r--r--  1 root root 39564160 11. Sep 2023  initrd.img-6.1.0-12-amd64
-rw-r--r--  1 root root 39570221 24. Nov 07:28 initrd.img-6.1.0-13-amd64
-rw-r--r--  1 root root 39556905  9. Dez 14:14 initrd.img-6.1.0-14-amd64
-rw-r--r--  1 root root 39554518 11. Dez 22:11 initrd.img-6.1.0-15-amd64
-rw-r--r--  1 root root 39565503 17. Dez 10:30 initrd.img-6.1.0-16-amd64
-rw-r--r--  1 root root 39559017  1. Jan 21:46 initrd.img-6.1.0-17-amd64
-rw-r--r--  1 root root 39565398 11. Feb 10:58 initrd.img-6.1.0-18-amd64
-rw-r--r--  1 root root 39572650 14. Apr 10:14 initrd.img-6.1.0-20-amd64
-rw-r--r--  1 root root 45843056 27. Jun 2023  initrd.img-6.1.0-9-amd64
-rw-r--r--  1 root root       83 21. Okt 2022  System.map-5.10.0-19-amd64
-rw-r--r--  1 root root       83 21. Jan 2023  System.map-5.10.0-21-amd64
-rw-r--r--  1 root root       83 22. Apr 2023  System.map-5.10.0-22-amd64
-rw-r--r--  1 root root       83 27. Jul 2023  System.map-6.1.0-10-amd64
-rw-r--r--  1 root root       83  8. Aug 2023  System.map-6.1.0-11-amd64
-rw-r--r--  1 root root       83  7. Sep 2023  System.map-6.1.0-12-amd64
-rw-r--r--  1 root root       83 29. Sep 2023  System.map-6.1.0-13-amd64
-rw-r--r--  1 root root       83 30. Nov 16:41 System.map-6.1.0-14-amd64
-rw-r--r--  1 root root       83  9. Dez 16:48 System.map-6.1.0-15-amd64
-rw-r--r--  1 root root       83 12. Dez 13:16 System.map-6.1.0-16-amd64
-rw-r--r--  1 root root       83 30. Dez 10:31 System.map-6.1.0-17-amd64
-rw-r--r--  1 root root       83  1. Feb 09:05 System.map-6.1.0-18-amd64
-rw-r--r--  1 root root       83 11. Apr 23:17 System.map-6.1.0-20-amd64
-rw-r--r--  1 root root       83  8. Mai 2023  System.map-6.1.0-9-amd64
-rw-r--r--  1 root root  6963648 21. Okt 2022  vmlinuz-5.10.0-19-amd64
-rw-r--r--  1 root root  7019136 21. Jan 2023  vmlinuz-5.10.0-21-amd64
-rw-r--r--  1 root root  7035328 22. Apr 2023  vmlinuz-5.10.0-22-amd64
-rw-r--r--  1 root root  7977248 27. Jul 2023  vmlinuz-6.1.0-10-amd64
-rw-r--r--  1 root root  7971232  8. Aug 2023  vmlinuz-6.1.0-11-amd64
-rw-r--r--  1 root root  8139648  7. Sep 2023  vmlinuz-6.1.0-12-amd64
-rw-r--r--  1 root root  8135584 29. Sep 2023  vmlinuz-6.1.0-13-amd64
-rw-r--r--  1 root root  8168256 30. Nov 16:41 vmlinuz-6.1.0-14-amd64
-rw-r--r--  1 root root  8140672  9. Dez 16:48 vmlinuz-6.1.0-15-amd64
-rw-r--r--  1 root root  8148352 12. Dez 13:16 vmlinuz-6.1.0-16-amd64
-rw-r--r--  1 root root  8147424 30. Dez 10:31 vmlinuz-6.1.0-17-amd64
-rw-r--r--  1 root root  8152768  1. Feb 09:05 vmlinuz-6.1.0-18-amd64
-rw-r--r--  1 root root  8167616 11. Apr 23:17 vmlinuz-6.1.0-20-amd64
-rw-r--r--  1 root root  7962368  8. Mai 2023  vmlinuz-6.1.0-9-amd64

can you try following

apt autoremove

Usually this should remove not needed packages

There should be a similar message while running apt upgrade

root@DietPi:~# apt upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following package was automatically installed and is no longer required:
  linux-image-6.1.0-18-amd64
Use 'apt autoremove' to remove it.
The following NEW packages will be installed:
  linux-image-6.1.0-20-amd64

Autoremove does not remove the unused kernerl’s. This is part of my Alias in bash to run an update/upgrade.

Testing on a VM is working quite well

root@DietPi:~# apt autoremove
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  linux-image-6.1.0-18-amd64
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 408 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 23597 files and directories currently installed.)
Removing linux-image-6.1.0-18-amd64 (6.1.76-1) ...
/etc/kernel/postrm.d/zz-update-grub:
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.1.0-20-amd64
Found initrd image: /boot/initrd.img-6.1.0-20-amd64
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
done
root@DietPi:~#

Did you tried running apt autoremove after a reboot?

And what is the output of following

dpkg -l linux-image*

A reboot give the same result for auto remove.

dietpi@DietPi:~$ dpkg -l linux-image*
Gewünscht=Unbekannt/Installieren/R=Entfernen/P=Vollständig Löschen/Halten
| Status=Nicht/Installiert/Config/U=Entpackt/halb konFiguriert/
         Halb installiert/Trigger erWartet/Trigger anhängig
|/ Fehler?=(kein)/R=Neuinstallation notwendig (Status, Fehler: GROSS=schlecht)
||/ Name                                 Version      Architektur  Beschreibung
+++-====================================-============-============-===================================
ii  linux-image-5.10.0-19-amd64          5.10.149-2   amd64        Linux 5.10 for 64-bit PCs (signed)
un  linux-image-5.10.0-19-amd64-unsigned <keine>      <keine>      (keine Beschreibung vorhanden)
rc  linux-image-5.10.0-20-amd64          5.10.158-2   amd64        Linux 5.10 for 64-bit PCs (signed)
un  linux-image-5.10.0-20-amd64-unsigned <keine>      <keine>      (keine Beschreibung vorhanden)
ii  linux-image-5.10.0-21-amd64          5.10.162-1   amd64        Linux 5.10 for 64-bit PCs (signed)
un  linux-image-5.10.0-21-amd64-unsigned <keine>      <keine>      (keine Beschreibung vorhanden)
ii  linux-image-5.10.0-22-amd64          5.10.178-3   amd64        Linux 5.10 for 64-bit PCs (signed)
un  linux-image-5.10.0-22-amd64-unsigned <keine>      <keine>      (keine Beschreibung vorhanden)
ii  linux-image-6.1.0-10-amd64           6.1.38-2     amd64        Linux 6.1 for 64-bit PCs (signed)
un  linux-image-6.1.0-10-amd64-unsigned  <keine>      <keine>      (keine Beschreibung vorhanden)
ii  linux-image-6.1.0-11-amd64           6.1.38-4     amd64        Linux 6.1 for 64-bit PCs (signed)
un  linux-image-6.1.0-11-amd64-unsigned  <keine>      <keine>      (keine Beschreibung vorhanden)
ii  linux-image-6.1.0-12-amd64           6.1.52-1     amd64        Linux 6.1 for 64-bit PCs (signed)
un  linux-image-6.1.0-12-amd64-unsigned  <keine>      <keine>      (keine Beschreibung vorhanden)
ii  linux-image-6.1.0-13-amd64           6.1.55-1     amd64        Linux 6.1 for 64-bit PCs (signed)
un  linux-image-6.1.0-13-amd64-unsigned  <keine>      <keine>      (keine Beschreibung vorhanden)
ii  linux-image-6.1.0-14-amd64           6.1.64-1     amd64        Linux 6.1 for 64-bit PCs (signed)
un  linux-image-6.1.0-14-amd64-unsigned  <keine>      <keine>      (keine Beschreibung vorhanden)
ii  linux-image-6.1.0-15-amd64           6.1.66-1     amd64        Linux 6.1 for 64-bit PCs (signed)
un  linux-image-6.1.0-15-amd64-unsigned  <keine>      <keine>      (keine Beschreibung vorhanden)
ii  linux-image-6.1.0-16-amd64           6.1.67-1     amd64        Linux 6.1 for 64-bit PCs (signed)
un  linux-image-6.1.0-16-amd64-unsigned  <keine>      <keine>      (keine Beschreibung vorhanden)
ii  linux-image-6.1.0-17-amd64           6.1.69-1     amd64        Linux 6.1 for 64-bit PCs (signed)
un  linux-image-6.1.0-17-amd64-unsigned  <keine>      <keine>      (keine Beschreibung vorhanden)
ii  linux-image-6.1.0-18-amd64           6.1.76-1     amd64        Linux 6.1 for 64-bit PCs (signed)
un  linux-image-6.1.0-18-amd64-unsigned  <keine>      <keine>      (keine Beschreibung vorhanden)
ii  linux-image-6.1.0-20-amd64           6.1.85-1     amd64        Linux 6.1 for 64-bit PCs (signed)
un  linux-image-6.1.0-20-amd64-unsigned  <keine>      <keine>      (keine Beschreibung vorhanden)
ii  linux-image-6.1.0-9-amd64            6.1.27-1     amd64        Linux 6.1 for 64-bit PCs (signed)
un  linux-image-6.1.0-9-amd64-unsigned   <keine>      <keine>      (keine Beschreibung vorhanden)
ii  linux-image-amd64                    6.1.85-1     amd64        Linux for 64-bit PCs (meta-package)
un  linux-image-generic                  <keine>      <keine>      (keine Beschreibung vorhanden)

looks like all the kernel packages are still installed. Therefore apt autoremove did not have any effect.

Can you try to remove one of the packages manually? Like

apt purge linux-image-5.10.0-19-amd64

That worked. So I have to do that with the other kernel’s too.

yes this time. Usually it should happen automatically. At least it is removing old kernel on my demo VM.

When upgrading the kernel, a window always opens and you are asked whether you want to delete the currently active kernel. Can this be done safely?

can you share that message?

I will come back on this next kernel update :wink: