Removing dkms-built modules for old kernel versions

Asked by Ralph Corderoy on 2012-01-23

I'm aware that as new kernels are installed on `apt-get dist-upgrade'
old ones aren't removed and must be done manually, e.g.

    sudo apt-get purge linux-image-2.6.35-{22,27,28,30}-generic \
        linux-headers-2.6.35-{22,27,28,30} \
        linux-headers-2.6.35-{22,27,28,30}-generic

However, this doesn't clean up modules that dkms has built for those
kernels.

    $ dkms status
    nvidia-current, 260.19.06, 2.6.35-31-generic, x86_64: installed
    nvidia-current, 260.19.06, 2.6.35-32-generic, x86_64: installed
    nvidia-current, 260.19.06, 2.6.35-30-generic, x86_64: built
    nvidia-current, 260.19.06, 2.6.35-28-generic, x86_64: built
    nvidia-current, 260.19.06, 2.6.35-27-generic, x86_64: built
    nvidia-current, 260.19.06, 2.6.35-22-generic, x86_64: built
    $

What's the right, clean, complete way to purge these too? Is it

    sudo dkms remove -m nvidia-current -v 260.19.06 \
        $(printf -- '-k %s\n' 2.6.35-{22,27,28,30}-generic)

Aside: Is there anything else that may linger for each old kernel that
needs manual clean-up? I didn't find much suggesting the `dkms remove'
was needed amongst the `remove your old kernel' blog posts and HOWTOs so
perhaps there are other non-dkms things you happen to know of.

Also, it seems a shame there's not a package one can install and
configure to keep the last N kernels and purge older ones as new ones
are installed. Then only it would need to know of all the things that
need doing.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu dkms Edit question
Assignee:
No assignee Edit question
Solved by:
Ralph Corderoy
Solved:
2012-01-29
Last query:
2012-01-29
Last reply:
2012-01-28
Sam_ (and-sam) said : #1

Afaik, Oneiric and Precise dkms modules are removed when purging a kernel image. Will post the exact wording from Precise.

Sam_ (and-sam) said : #2

Removal of linux-image-3.2.0-7-generic ...
Examining /etc/kernel/prerm.d.
run-parts: executing /etc/kernel/prerm.d/dkms 3.2.0-7-generic /boot/vmlinuz-3.2.0-7-generic
dkms: removing: bcmwl 5.100.82.38+bdcom (3.2.0-7-generic) (x86_64)

-------- Uninstall Beginning --------
Module: bcmwl
Version: 5.100.82.38+bdcom
Kernel: 3.2.0-7-generic (x86_64)
-------------------------------------

Status: Before uninstall, this module version was ACTIVE on this kernel.

wl.ko:
 - Uninstallation
   - Deleting from: /lib/modules/3.2.0-7-generic/updates/dkms/
 - Original module
   - No original module was found for this module on this kernel.
   - Use the dkms install command to reinstall any previous module version.

depmod.........

DKMS: uninstall completed.

Thanks Sam_, good news on it happening as part of kernel removal in
later releases. I'm on 10.10 so it doesn't. So is my proposed

    sudo dkms remove -m nvidia-current -v 260.19.06 \
        $(printf -- '-k %s\n' 2.6.35-{22,27,28,30}-generic)

the right thing?

Sam_ (and-sam) said : #4

Not sure about nvidia since I don't use it, isn't it in /lib/modules/ somewhere?

Well, /var/lib/dkms/nvidia-current too and possibly elsewhere, that's why I'm after the correct dkms incantation to avoid messing things up and only finding out when nvidia is upgraded in the future.

Sam_ (and-sam) said : #6

When a kernel-image is removed there shouldn't be an issue by removing the regarding module when the next kernel brings it's own module again.
Looking at manpage the dkms_rm cmd looks rather simple and saying in case it'll error out.

Rather unsure though how the /etc/kernel/prerm.d cooperates with manual remove in earlier kernel-images regarding interference of upgrades. Maybe try websearch or ask on #ubuntu-kernel.

I asked on #ubuntu-kernel but no reply.

I've run my proposed `sudo dkms remove' given above when I opened this question and it seems to have worked fine. The old files have been removed. However, each depmod reported

    Status: This module version was INACTIVE for this kernel.
    depmod....(bad exit status: 1)

We'll see if everything pans out OK on the next kernel upgrade. I expect so, it would just be nice to know for certain it's the correct way rather than suck it and see. :-)

Sam_ (and-sam) said : #8

If it says: was INACTIVE for *this* kernel, maybe depmod is complaining about 'inactive' or rather it couldn't examine the already purged kernel.
Anyway an exit status '1' doesn't implicate something dramatically. A websearch on 'bad exit 1' reveals some posts where user rather compiled their own kernel, e.g. bug 292606, instead of running it on stock kernel.
Maybe:
sudo depmod -a
gives a hint?
http://manpages.ubuntu.com/manpages/oneiric/en/man8/depmod.8.html

Sam_ (and-sam) said : #9

Is there perhaps a log in /var/lib/dkms?

Removal cmd is also mentioned there.
https://wiki.ubuntu.com/Kernel/Dev/DKMSPackaging

Exploring Dynamic Kernel Module Support (DKMS)
http://www.linuxjournal.com/article/6896?page=0,0

> Is there perhaps a log in /var/lib/dkms?

No. But looking at dkms (it's a shell script) I suspect it may be
because the kernel version no longer exists.