How to clean up /usr/lib/modules entirely?

sudo zypper purge-kernels does not work. But nvidia files remain:

    nvidia-drm.ko
    nvidia.ko
    nvidia-modeset.ko
    nvidia-peermem.ko
    nvidia-uvm.ko

I took the risk to delete them manually, and so far nothing went wrong. But is there a better way to do it?

Hello and welcome to the openSUSE forums.

A good problem description contains three things:

  • what one did;
  • what one expected to happen
  • what happened instead.
    No need to do that in a bulleted list or in that sequence, but those three should be there.

Now you say:

But we do not read what you expect it to do, nor what it did (and please do so by copy/paste the command and all the output you use to show us).

I am running Leap 15.5, but I do not think that Tumbleweed is that different and I do not have

henk@boven:~> ls -l /usr/lib/modules
ls: cannot access '/usr/lib/modules': No such file or directory
henk@boven:~> 

Is that because I do not use Nvidia?

From Tumbleweed:

bruno@LT-B:~> ls -l /usr/lib/modules/6.8.8-1-default/
total 41828
lrwxrwxrwx  1 root root       45 apr 29 07:21 build -> ../../../src/linux-6.8.8-1-obj/x86_64/default
-rw-r--r--  1 root root   279823 apr 29 07:21 config
drwxr-xr-x  2 root root     4096 mag  9 10:39 extra
drwxr-xr-x 14 root root     4096 mag  1 16:20 kernel
-rw-r--r--  1 root root  1396378 mag  9 10:39 modules.alias
-rw-r--r--  1 root root  1357587 mag  9 10:39 modules.alias.bin
-rw-r--r--  1 root root     6691 apr 29 07:21 modules.builtin
-rw-r--r--  1 root root     6868 mag  9 10:39 modules.builtin.alias.bin
-rw-r--r--  1 root root     8147 mag  9 10:39 modules.builtin.bin
-rw-r--r--  1 root root    58706 apr 29 07:21 modules.builtin.modinfo
-rw-r--r--  1 root root   701752 mag  9 10:39 modules.dep
-rw-r--r--  1 root root   924760 mag  9 10:39 modules.dep.bin
-rw-r--r--  1 root root      455 mag  9 10:39 modules.devname
-rw-r--r--  1 root root      713 apr 29 07:21 modules.fips
-rw-r--r--  1 root root   204266 apr 29 07:21 modules.order
-rw-r--r--  1 root root     2744 mag  9 10:39 modules.softdep
-rw-r--r--  1 root root   724458 mag  9 10:39 modules.symbols
-rw-r--r--  1 root root   870520 mag  9 10:39 modules.symbols.bin
lrwxrwxrwx  1 root root       26 apr 29 07:21 source -> ../../../src/linux-6.8.8-1
-rw-r--r--  1 root root  1618541 apr 29 07:21 symtypes.gz
-rw-r--r--  1 root root   371153 apr 29 07:21 symvers.gz
-rw-r--r--  1 root root      569 apr 29 07:21 sysctl.conf
-rw-r--r--  1 root root  7607956 apr 29 07:21 System.map
drwxr-xr-x  2 root root     4096 mag  1 16:20 updates
-rwxr-xr-x  1 root root 12175524 apr 29 07:21 vmlinux.xz
-rw-r--r--  1 root root 14457200 apr 29 07:21 vmlinuz
bruno@LT-B:~

Indeed apparently the “extra” folder (VirtualBox modules e.g.) and the “update” folder (Nvidia modules e.g.) are not removed by purge-kernels.

Then take some time to educate yourself.

If they belong to some package you can remove them by uninstalling this package. If these files were put there manually, you can only manually delete them. RPM will not remove files that do not belong to packages nor will it remove non-empty directories.

In Leap, you have “/lib/modules”. In Tumbleweed, this was moved to “/usr/lib/modules” and “/lib” is just a symlink to “/usr/lib”.

I don’t have any Nvidia device, so I don’t see that.

Yes, purge-kernels does work, but it leaves behind any modules that did not come with the kernel. And, as a result, some directories are not removed. These take up very little disk space, compared with the space used by the kernel.

Yes, you can manually remove those if you don’t need them. But sometimes, the modules for the new kernel are just symlinks to those for the old kernel. So check before you remove them. Back in the past, when I did have a Nvidia card, I used to manually remove those.

1 Like

Sorry, I should have been more clear… please excuse.

Here is my fixed question:

I have a tumbleweed system with proprietary Nvidia drivers. I have noticed that after every kernel upgrade, the older kernel modules at /usr/lib/modules do get removed, except the nvidia ones.

Now unfortunately since I have already deleted the older ones, I can’t exactly show the output.

@arvidjaar I have not manually put the files there, they were probably installed by nvidia proprietary driver from the nvidia repository (build.suse.de/Proprietary:X11:Drivers).

They were installed by nvidia-driver-G06-kmp-default (or another version depending on the installed GPU).

So, is it possible that devs include some sort of cleanup mechanism in this package so that older modules get removed when old kernel gets purged?

Yep:

3400g:~ # rpm -q --scripts kernel-default
preinstall scriptlet (using /bin/sh):
run_if_exists() { 
if [ -x "$1" ] ; then                   
  "$@"                                  
else                                    
  echo Cannot execute "$1" >&2          
fi                                      
}                                       
run_if_exists /usr/lib/module-init-tools/kernel-scriptlets/rpm-pre --name "kernel-default" \
  --version "6.8.1" --release "1.2" --kernelrelease "6.8.1-1" \
  --image "vmlinuz" --flavor "default" --variant "" \
  --usrmerged "1" --certs "1F673297" "$@"
postinstall scriptlet (using /bin/sh):
run_if_exists() { 
if [ -x "$1" ] ; then                   
  "$@"                                  
else                                    
  echo Cannot execute "$1" >&2          
fi                                      
}                                       
run_if_exists /usr/lib/module-init-tools/kernel-scriptlets/rpm-post --name "kernel-default" \
  --version "6.8.1" --release "1.2" --kernelrelease "6.8.1-1" \
  --image "vmlinuz" --flavor "default" --variant "" \
  --usrmerged "1" --certs "1F673297" "$@"
preuninstall scriptlet (using /bin/sh):
run_if_exists() { 
if [ -x "$1" ] ; then                   
  "$@"                                  
else                                    
  echo Cannot execute "$1" >&2          
fi                                      
}                                       
run_if_exists /usr/lib/module-init-tools/kernel-scriptlets/rpm-preun --name "kernel-default" \
  --version "6.8.1" --release "1.2" --kernelrelease "6.8.1-1" \
  --image "vmlinuz" --flavor "default" --variant "" \
  --usrmerged "1" --certs "1F673297" "$@"
postuninstall scriptlet (using /bin/sh):
run_if_exists() { 
if [ -x "$1" ] ; then                   
  "$@"                                  
else                                    
  echo Cannot execute "$1" >&2          
fi                                      
}                                       
run_if_exists /usr/lib/module-init-tools/kernel-scriptlets/rpm-postun --name "kernel-default" \
  --version "6.8.1" --release "1.2" --kernelrelease "6.8.1-1" \
  --image "vmlinuz" --flavor "default" --variant "" \
  --usrmerged "1" --certs "1F673297" "$@"
posttrans scriptlet (using /bin/sh):
run_if_exists() { 
if [ -x "$1" ] ; then                   
  "$@"                                  
else                                    
  echo Cannot execute "$1" >&2          
fi                                      
}                                       
run_if_exists /usr/lib/module-init-tools/kernel-scriptlets/rpm-posttrans --name "kernel-default" \
  --version "6.8.1" --release "1.2" --kernelrelease "6.8.1-1" \
  --image "vmlinuz" --flavor "default" --variant "" \
  --usrmerged "1" --certs "1F673297" "$@"
preinstall scriptlet (using /bin/sh):
run_if_exists() { 
if [ -x "$1" ] ; then                   
  "$@"                                  
else                                    
  echo Cannot execute "$1" >&2          
fi                                      
}                                       
run_if_exists /usr/lib/module-init-tools/kernel-scriptlets/rpm-pre --name "kernel-default" \
  --version "6.8.8" --release "1.1" --kernelrelease "6.8.8-1" \
  --image "vmlinuz" --flavor "default" --variant "" \
  --usrmerged "1" --certs "1F673297" "$@"
postinstall scriptlet (using /bin/sh):
run_if_exists() { 
if [ -x "$1" ] ; then                   
  "$@"                                  
else                                    
  echo Cannot execute "$1" >&2          
fi                                      
}                                       
run_if_exists /usr/lib/module-init-tools/kernel-scriptlets/rpm-post --name "kernel-default" \
  --version "6.8.8" --release "1.1" --kernelrelease "6.8.8-1" \
  --image "vmlinuz" --flavor "default" --variant "" \
  --usrmerged "1" --certs "1F673297" "$@"
preuninstall scriptlet (using /bin/sh):
run_if_exists() { 
if [ -x "$1" ] ; then                   
  "$@"                                  
else                                    
  echo Cannot execute "$1" >&2          
fi                                      
}                                       
run_if_exists /usr/lib/module-init-tools/kernel-scriptlets/rpm-preun --name "kernel-default" \
  --version "6.8.8" --release "1.1" --kernelrelease "6.8.8-1" \
  --image "vmlinuz" --flavor "default" --variant "" \
  --usrmerged "1" --certs "1F673297" "$@"
postuninstall scriptlet (using /bin/sh):
run_if_exists() { 
if [ -x "$1" ] ; then                   
  "$@"                                  
else                                    
  echo Cannot execute "$1" >&2          
fi                                      
}                                       
run_if_exists /usr/lib/module-init-tools/kernel-scriptlets/rpm-postun --name "kernel-default" \
  --version "6.8.8" --release "1.1" --kernelrelease "6.8.8-1" \
  --image "vmlinuz" --flavor "default" --variant "" \
  --usrmerged "1" --certs "1F673297" "$@"
posttrans scriptlet (using /bin/sh):
run_if_exists() { 
if [ -x "$1" ] ; then                   
  "$@"                                  
else                                    
  echo Cannot execute "$1" >&2          
fi                                      
}                                       
run_if_exists /usr/lib/module-init-tools/kernel-scriptlets/rpm-posttrans --name "kernel-default" \
  --version "6.8.8" --release "1.1" --kernelrelease "6.8.8-1" \
  --image "vmlinuz" --flavor "default" --variant "" \
  --usrmerged "1" --certs "1F673297" "$@"
3400g:~ # 

The scripts delete what was created upon install of package kernel-default. They won’t mess with stuff created by other packages.

I too have leftover nVidia kernel modules and symlinks. Every time I get a new kernel, they get moved and/or symlinks get made, perhaps by dkms. I leave it all alone because it doesn’t take much space.

However, after I to a distribution upgrade, I go in there and manually clean out the old stuff. I’m running Leap, so there are clean breaks in kernel versions and I can be sure I won’t break anything.

It would be nice if the dkms/nVidia packages automatically took care of the orphans, especially for Tumbleweed. I consider it a minor maintenance problem because I choose to use the proprietary nVidia drivers.

It should

https://bugzilla.opensuse.org/show_bug.cgi?id=1180010

1 Like

it says its fixed… but it’s not right?
excuse me, i am very new to this so i am not sure.

May be. In this case one needs to collect the evidences - the content of /usr/lib/modules/$KERNEL_VERSION showing the modules you want to be removed, the full transcript of all commands and their output you used and the content of /usr/lib/modules again demonstrating that the modules have not been removed.

And you could start with posting this information here. Because it is quite possible that your expectations are wrong, but you never show what you did so we have no way to evaluate it.

To start with, the bug and the comment I replied to are about removing NVIDIA packages, not about removing kernel packages. So it has nothing to do with zypper purge-kernels which - as the command name suggests - removes kernel packages.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.