Ubuntu does not clean out old kernel module files (in /lib/modules) when old kernels are removed

Bug #2007286 reported by corrado venturini
26
This bug affects 5 people
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Expired
Undecided
Unassigned

Bug Description

corrado@corrado-x-kinetic:~$ ls /lib/modules
5.19.0-23-generic 5.19.0-28-generic 5.19.0-29-generic 5.19.0-31-generic
corrado@corrado-x-kinetic:~$ ls /boot
config-5.19.0-29-generic memtest86+.elf
config-5.19.0-31-generic memtest86+_multiboot.bin
efi System.map-5.19.0-29-generic
grub System.map-5.19.0-31-generic
initrd.img vmlinuz
initrd.img-5.19.0-29-generic vmlinuz-5.19.0-29-generic
initrd.img-5.19.0-31-generic vmlinuz-5.19.0-31-generic
initrd.img.old vmlinuz.old
memtest86+.bin
corrado@corrado-x-kinetic:~$
see also https://discourse.ubuntu.com/t/ubuntu-does-not-clean-out-old-kernel-module-files-in-lib-modules-when-old-kernels-are-removed/33906

ProblemType: Bug
DistroRelease: Ubuntu 22.10
Package: apt 2.5.3
ProcVersionSignature: Ubuntu 5.19.0-31.32-generic 5.19.17
Uname: Linux 5.19.0-31-generic x86_64
ApportVersion: 2.23.1-0ubuntu3
Architecture: amd64
CasperMD5CheckResult: pass
CurrentDesktop: ubuntu:GNOME
Date: Tue Feb 14 16:23:49 2023
InstallationDate: Installed on 2022-11-28 (77 days ago)
InstallationMedia: Ubuntu 22.10 "Kinetic Kudu" - Release amd64 (20221020)
SourcePackage: apt
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
corrado venturini (corradoventu) wrote :
Revision history for this message
Artur Meinild (ameinild) wrote :

This is reproducible on both Ubuntu 20.04 and 22.04 Server, on both AMD64 and ARM64 (Raspberry Pi).

For AMD64 (Intel):

$ ls -l /lib/modules/5.4.0-xx-generic
-rw-r--r-- 1 root 143K 2022-04-28 18:36 modules.alias
-rw-r--r-- 1 root 154K 2022-04-28 18:36 modules.alias.bin
-rw-r--r-- 1 root 8.0K 2022-04-08 10:44 modules.builtin
-rw-r--r-- 1 root 25K 2022-04-28 18:36 modules.builtin.alias.bin
-rw-r--r-- 1 root 11K 2022-04-28 18:36 modules.builtin.bin
-rw-r--r-- 1 root 63K 2022-04-08 10:44 modules.builtin.modinfo
-rw-r--r-- 1 root 85K 2022-04-28 18:36 modules.dep
-rw-r--r-- 1 root 123K 2022-04-28 18:36 modules.dep.bin
-rw-r--r-- 1 root 268 2022-04-28 18:36 modules.devname
-rw-r--r-- 1 root 215K 2022-04-08 10:44 modules.order
-rw-r--r-- 1 root 489 2022-04-28 18:36 modules.softdep
-rw-r--r-- 1 root 279K 2022-04-28 18:36 modules.symbols
-rw-r--r-- 1 root 326K 2022-04-28 18:36 modules.symbols.bin

For ARM64 (RasPi):

$ ls -l /lib/modules/5.4.0-xxxx-raspi
-rw-r--r-- 1 root 859K 2022-04-25 17:31 modules.alias
-rw-r--r-- 1 root 893K 2022-04-25 17:31 modules.alias.bin
-rw-r--r-- 1 root 11K 2022-04-04 13:33 modules.builtin
-rw-r--r-- 1 root 27K 2022-04-25 17:31 modules.builtin.alias.bin
-rw-r--r-- 1 root 14K 2022-04-25 17:31 modules.builtin.bin
-rw-r--r-- 1 root 84K 2022-04-04 13:33 modules.builtin.modinfo
-rw-r--r-- 1 root 399K 2022-04-25 17:31 modules.dep
-rw-r--r-- 1 root 548K 2022-04-25 17:31 modules.dep.bin
-rw-r--r-- 1 root 250 2022-04-25 17:31 modules.devname
-rw-r--r-- 1 root 209K 2022-04-04 13:33 modules.order
-rw-r--r-- 1 root 950 2022-04-25 17:31 modules.softdep
-rw-r--r-- 1 root 354K 2022-04-25 17:31 modules.symbols
-rw-r--r-- 1 root 425K 2022-04-25 17:31 modules.symbols.bin

Revision history for this message
Julian Andres Klode (juliank) wrote :

There can be many reasons why files remain. Did you purge the packages for those Linux versions? Did you do any dkms modules.

This is not a bug in apt, apt is not responsible for those files.

Changed in apt (Ubuntu):
status: New → Invalid
affects: apt (Ubuntu) → linux (Ubuntu)
Changed in linux (Ubuntu):
status: Invalid → Incomplete
Revision history for this message
Julian Andres Klode (juliank) wrote :

Actually let me reassign to Linux and mark incomplete.

Revision history for this message
corrado venturini (corradoventu) wrote :

corrado@corrado-x-kinetic:~$ ls /lib/modules
5.19.0-23-generic 5.19.0-28-generic 5.19.0-29-generic 5.19.0-31-generic
corrado@corrado-x-kinetic:~$ sudo apt autoremove --purge
[sudo] password for corrado:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
corrado@corrado-x-kinetic:~$ ls /lib/modules
5.19.0-23-generic 5.19.0-28-generic 5.19.0-29-generic 5.19.0-31-generic
corrado@corrado-x-kinetic:~$

Revision history for this message
Artur Meinild (ameinild) wrote :

For the relevant kernels running:

sudo apt purge linux-image-5.15.0-xx-generic linux-modules-5.15.0-xx-generic linux-modules-extra-5.15.0-xx-generic

Or using this utility: https://git.launchpad.net/linux-purge

Then the leftover directories are correctly removed.

But I don't think you should have to rely on manual commands or 3rd party utilities to clean out after old kernels.

Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for linux (Ubuntu) because there has been no activity for 60 days.]

Changed in linux (Ubuntu):
status: Incomplete → Expired
Revision history for this message
Marius Gedminas (mgedmin) wrote :

AFAIU by default it's unattended-upgrades that takes care of removing old kernel (and kernel module packages). Apparently it doesn't pass --purge when it removes the old kernel packages. Should it?

Revision history for this message
DigiAngel (jlay) wrote :

Same here...none of these commands remove the old /lib/modules/ kernel dirs:

sudo apt-get clean
sudo apt-get autoclean
sudo apt-get autoremove
sudo apt-get purge

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.