Removal does not clean up after dkms, l-r-m(?)

Bug #300773 reported by Matt Zimmerman
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
dkms (Ubuntu)
Fix Released
Medium
Andy Whitcroft
linux (Ubuntu)
Fix Released
Medium
Andy Whitcroft

Bug Description

I just removed a bunch of obsolete kernels from my system, and noted that for each one, I saw this error:

rmdir: failed to remove `/lib/modules/2.6.27-6-generic': Directory not empty

The contents which remain are:

/lib/modules/2.6.26-4-generic:
updates volatile

/lib/modules/2.6.26-5-generic:
build updates volatile

/lib/modules/2.6.27-1-generic:
build updates

/lib/modules/2.6.27-2-generic:
build updates

/lib/modules/2.6.27-4-generic:
build updates

/lib/modules/2.6.27-5-generic:
build updates

/lib/modules/2.6.27-6-generic:
build updates

Related branches

Changed in linux:
assignee: nobody → ubuntu-kernel-team
importance: Undecided → Medium
status: New → Triaged
Andy Whitcroft (apw)
Changed in linux:
assignee: ubuntu-kernel-team → apw
status: Triaged → In Progress
Revision history for this message
Andy Whitcroft (apw) wrote :

When you say removed these kernels did that involve removing the kernel-image and the linux-headers for each? The build link seems to come from the linux-headers package. So could you confirm which were removed and in which order.

I have just tried this here, removing the image first and then the headers:

apw@dm$ sudo dpkg -r linux-image-2.6.28-1-ub-generic
[...]
apw@dm$ sudo dpkg -r linux-headers-2.6.28-1-ub-generic
(Reading database ... 171800 files and directories currently installed.)
Removing linux-headers-2.6.28-1-ub-generic ...
dpkg - warning: while removing linux-headers-2.6.28-1-ub-generic, directory `/lib/modules/2.6.28-1-ub-generic' not empty so not removed.

In my case I have a bunch of module files:

apw@dm$ ls /lib/modules/2.6.28-1-ub-generic/
modules.alias modules.inputmap modules.pcimap modules.usbmap
modules.ccwmap modules.isapnpmap modules.seriomap
modules.ieee1394map modules.ofmap modules.symbols

It does appear that the kernel postrm script is not cleaning out all of the depmod generated files. That would not explain the files reported by Matt, as he does not have these files too I assume this kernel was never booted?

Revision history for this message
Andy Whitcroft (apw) wrote :

Going through some experiments:

Simple install/deinstall:
$ sudo dpkg -i linux-image-2.6.28-1-ub-generic_2.6.28-1.1_amd64.deb
[...]
$ sudo dpkg -r linux-image-2.6.28-1-ub-generic
[...]
$ ls /lib/modules/2.6.28-1-ub-generic
modules.alias modules.inputmap modules.pcimap modules.usbmap
modules.ccwmap modules.isapnpmap modules.seriomap
modules.ieee1394map modules.ofmap modules.symbols

Simple install/Purge:
$ sudo dpkg -i linux-image-2.6.28-1-ub-generic_2.6.28-1.1_amd64.deb
[...]
$ sudo dpkg -P linux-image-2.6.28-1-ub-generic
[...]
rmdir: failed to remove `/lib/modules/2.6.28-1-ub-generic': Directory not empty
dpkg - warning: while removing linux-image-2.6.28-1-ub-generic, directory `/lib/modules/2.6.28-1-ub-generic' not empty so not removed.
$ ls /lib/modules/2.6.28-1-ub-generic
modules.seriomap

Fixing up the postrm so it purges the modules.seriomap:
$ sudo dpkg -i linux-image-2.6.28-1-ub-generic_2.6.28-1.1_amd64.deb
[...]
$ sudo dpkg -P linux-image-2.6.28-1-ub-generic
[...]
$ ls /lib/modules/2.6.28-1-ub-generic
ls: cannot access /lib/modules/2.6.28-1-ub-generic: No such file or directory

Something is clearly wrong with the postrm purge support. We are unconditionally removing the directory regardless of the fact its completely reasonable for there to be files from other packages (headers, source etc) in this directory. Looking at it closely it only seems to work that way because the dependancy map files modules.*map are treated as configuration files. But actually they are not. We are completely happy to remove the main member of this collection modules.map in the normal remove and on a reinstall we simply overwrite the lot of them, no user modification is expected; nor does it appear sensible.

Put together a patch to clean this lot up (attached).

With the patched prerm/postrm:

$ sudo dpkg -i linux-image-2.6.28-1-ub-generic_2.6.28-1.1_amd64.deb
[...]
$ sudo dpkg -i linux-headers-2.6.28-1-ub
[...]
$ ls /lib/modules/2.6.28-1-ub-generic
build modules.alias modules.ieee1394map modules.ofmap modules.symbols
initrd modules.ccwmap modules.inputmap modules.pcimap modules.usbmap
kernel modules.dep modules.isapnpmap modules.seriomap
$ sudo dpkg -P linux-image-2.6.28-1-ub-generic
[...]
$ ls /lib/modules/2.6.28-1-ub-generic
build
$ sudo dpkg -r linux-headers-2.6.28-1-ub-generic
[...]
$ ls /lib/modules/2.6.28-1-ub-generic
ls: cannot access /lib/modules/2.6.28-1-ub-generic: No such file or directory

Much more believable. Will push this up for review.

Revision history for this message
Matt Zimmerman (mdz) wrote : Re: [Bug 300773] Re: Removal does not clean up after dkms, l-r-m(?)

On Thu, Dec 04, 2008 at 02:24:53PM -0000, Andy Whitcroft wrote:
> Put together a patch to clean this lot up (attached).

This patch looks good and fixes several bugs, but not the exact issue I
reported. My apologies for not being clearer in the original report.

In my case, the modules.* files *were* removed, but probably only thanks to
bug 250511 (those kernels predated the fix, so the files were included in
the package and removed by dpkg).

The build links do in fact belong to linux-headers-* packages and so their
presence is not unexpected (though they do trigger the error message from
failing rmdir, which your patch addresses).

The crux of my problem is the "updates" directory, which contains modules
built by DKMS. Nothing cleans up these files when a kernel is removed, only
when the entire module package (e.g. nvidia-173-kernel-source) is removed.

I think what's needed is to add a "dkms remove" command to the kernel
package postrm which removes all modules installed by dkms for the specified
kernel version.

(FWIW, I think the maintainer scripts for the kernel package would probably
benefit from being stripped down to simpler shell scripts. We inherited
them from kernel-package, but don't use it anymore and could get by with
something much simpler I think.)

--
 - mdz

Revision history for this message
Andy Whitcroft (apw) wrote :
Download full text (6.8 KiB)

On Thu, Dec 04, 2008 at 03:01:47PM -0000, Matt Zimmerman wrote:

> The crux of my problem is the "updates" directory, which contains modules
> built by DKMS. Nothing cleans up these files when a kernel is removed, only
> when the entire module package (e.g. nvidia-173-kernel-source) is removed.
>
> I think what's needed is to add a "dkms remove" command to the kernel
> package postrm which removes all modules installed by dkms for the specified
> kernel version.

If I install the nvidia-173-kernel-source module on my system here then
I get a dkms postinstall script for both the headers and the kernel:

    $ ls -l /etc/kernel/*/dkms
    -rwxr-xr-x 1 root root 185 2008-07-08 16:19 /etc/kernel/header_postinst.d/dkms
    -rwxr-xr-x 1 root root 185 2008-07-08 16:19 /etc/kernel/postinst.d/dkms
    -rwxr-xr-x 1 root root 502 2008-07-08 16:19 /etc/kernel/prerm.d/dkms

When both kernel and headers are installed then the driver seems to get
built correctly:

    $ sudo dpkg -i linux-image-2.6.27-7-generic_2.6.27-7.16_amd64.deb
    Selecting previously deselected package linux-image-2.6.27-7-generic.
    (Reading database ... 161177 files and directories currently installed.)
    Unpacking linux-image-2.6.27-7-generic (from
    linux-image-2.6.27-7-generic_2.6.27-7.16_amd64.deb) ...
    Done.
    Setting up linux-image-2.6.27-7-generic (2.6.27-7.16) ...
    Running depmod.
    update-initramfs: Generating /boot/initrd.img-2.6.27-7-generic
    Running postinst hook script /sbin/update-grub.
    Searching for GRUB installation directory ... found: /boot/grub
    Searching for default file ... found: /boot/grub/default
    Testing for an existing GRUB menu.lst file ... found:
    /boot/grub/menu.lst
    Searching for splash image ... none found, skipping ...
    Found kernel: /boot/vmlinuz-TEST
    Found kernel: /boot/vmlinuz-2.6.27-10-generic
    Found kernel: /boot/vmlinuz-2.6.27-9-generic
    Found kernel: /boot/vmlinuz-2.6.27-8-generic
    Found kernel: /boot/vmlinuz-2.6.27-7-generic
    Found kernel: /boot/vmlinuz-2.6.24-21-generic
    Found kernel: /boot/memtest86+.bin
    Replacing config file /var/run/grub/menu.lst with new version
    Updating /boot/grub/menu.lst ... done

    Examining /etc/kernel/postinst.d.
    run-parts: executing /etc/kernel/postinst.d/dkms
     * Running DKMS auto installation service for kernel 2.6.27-7-generic
     * nvidia (173.14.12)...
     * nvidia (173.14.12): Installing module.
      Kernel source for 2.6.27-7-generic not installed. Cannot install this module.
             [fail]
    run-parts: executing /etc/kernel/postinst.d/nvidia-common

    (reverse-i-search)`0': less
    ./ubuntu-intrepid/debian/linux-image-2.6.27-10-generic/DEBIAN/postrm
    (reverse-i-search)`-r': sudo dpkg -r
    linux-restricted-modules-2.6.27-7-generic$ sudo dpkg -i
    linux-headers-2.6.27-7-generic_2.6.27-7.16_amd64.deb Selecting
    previously deselected package linux-headers-2.6.27-7-generic.
    (Reading database ... 163749 files and directories currently installed.)
    Unpacking linux-headers-2.6.27-7-generic (from
    linux-headers-2.6.27-7-generic_2.6.27-7.16_amd64.deb) ...
    Setting up linux-headers-2.6.27-7-ge...

Read more...

Revision history for this message
Andy Whitcroft (apw) wrote :

Ok this seems pretty simple to clear up in dkms itself. When removing a kernel we envoke a dkms remove on every installed dkms package for that kernel. Once we have done that we can simply remove the the updates/dkms directory.

With the attached debdiff applied to dkms it will attempt to 'gently' remove the updates/dkms hierachy. Where all of the dkms packages are gone the directories can be removed and the normal cleanup of the /lib/modules/<version> directory will occur.

Changed in dkms:
assignee: nobody → apw
importance: Undecided → Medium
status: New → In Progress
Revision history for this message
Mario Limonciello (superm1) wrote :

Thanks for the patch. I've s/intrepid/jaunty and uploaded it to Jaunty and added it to git head.

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

This bug was fixed in the package dkms - 2.0.20.4-0ubuntu3

---------------
dkms (2.0.20.4-0ubuntu3) jaunty; urgency=low

  * Ensure that the /lib/modules/<version>/updates/dkms directory is
    removed if it is empty after a removal. This allows the modules
    directory to be removed as it becomes empty. (LP: #300773)

 -- Andy Whitcroft <email address hidden> Thu, 04 Dec 2008 16:48:10 +0000

Changed in dkms:
status: In Progress → Fix Released
Andy Whitcroft (apw)
Changed in linux:
status: In Progress → Fix Committed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package linux - 2.6.28-4.5

---------------
linux (2.6.28-4.5) jaunty; urgency=low

  [ Andy Whitcroft ]

  * clean up module dependancy information on package removal/purge
    - LP: #300773

  [ Tim Gardner ]

  * Update iscsitarget to 0.4.17
  * Build in ext{234}
  * Build in Crypto modules AES, CBC, ECB
  * Build in ACPI AC,BATTERY,BUTTON,FAN,PCI_SLOT,PROCESSOR,SBS,THERMAL,WMI
  * Build in AGP intel,via,sis,ali,amd,amd64,efficeon,nvidia,sworks
  * Build in ata,dev_dm,dev_loop,dev_md,dev_sd,dev_sr
  * Build in BT l2cap,rfcomm,sco
  * Reduce CONFIG_LEGACY_PTY_COUNT to 0
  * Build in CDROM_PKTCDVD and CHR_DEV_SG
  * Build in CPU_FREQ
    GOV_CONSERVATIVE,GOV_ONDEMAND,GOV_POWERSAVE,GOV_USERSPACE,STAT,TABLE
  * Build in DM CRYPT,MIRROR,MULTIPATH,SNAPSHOT
  * Build in DRM
  * Build in HID
  * Build in HOTPLUG PCI,PCIE
  * Build in I2C
  * Build in IEEE1394 OHCI1394
  * Build in INPUT EVDEV
  * Build in IPV6
  * Build in MMC
  * Build in PACKET
  * Enable both IEEE1394 (Firewire) stacks as modules
    - LP: #276463
  * Disable SUNRPC_REGISTER_V4
    - LP: #306016
  * Enable dm-raid4-5
    - LP: #309378
  * Build in PPP
  * Build in RFKILL
  * Build in USB SERIAL

  [ Upstream Kernel Changes ]

  * Rebased to v2.6.28

 -- Tim Gardner <email address hidden> Thu, 18 Dec 2008 21:18:44 -0700

Changed in linux:
status: Fix Committed → Fix Released
Revision history for this message
Hans Deragon (deragon) wrote :

I have this problem on 12.04. The fix has been lost. Should I reopen this bug report?

Revision history for this message
Rik (riksoft) wrote :

I have a similar problem on Mint 18/Ubuntu 16:

sudo apt-get purge linux-image-4.4.0-xx-generic linux-headers-4.4.0-xx

and it shows the message: dpkg: warning: while removing linux-image-4.4.0-xx-generic, directory '/lib/modules/4.4.0-xx-generic' not empty so not removed

In /lib/modules/
4.4.0-21-generic 4.4.0-45-generic 4.4.0-62-generic
4.4.0-34-generic 4.4.0-47-generic 4.4.0-64-generic
4.4.0-36-generic 4.4.0-59-generic 4.4.0-66-generic

and in ever such dirs there is only the subdir updates with inside:
vboxguest.ko vboxsf.ko vboxvideo.ko

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.