Old Kernels not getting purged: mkinitrd compiles them, still in boot

I’m trying to clean up my Tumbleweed system. I noticed after recent updates (zypper dup) that kernels that should not be installed get compiled, they still show up in the boot menu and I can still find them in the /boot directory and in /lib/modules directory.

For example,

# rpm -qa kern* 

returns:


kernel-default-devel-4.15.13-2.4.x86_64
kernel-syms-4.15.13-2.4.x86_64
kernel-devel-4.15.13-2.4.noarch
kernel-syms-4.15.13-1.6.x86_64
kernel-firmware-20180320-1.1.noarch
kernel-default-4.15.13-2.4.x86_64
kernel-default-devel-4.15.13-1.6.x86_64
kernel-devel-4.15.13-1.6.noarch
kernel-macros-4.15.13-2.4.noarch
kernel-default-4.15.13-1.6.x86_64
 

but

# ls /boot

returns:


.vmlinuz-4.15.13-1-default.hmac  boot.readme               initrd                         symtypes-4.15.9-1-default.gz   sysctl.conf-4.15.9-1-default  vmlinuz-4.15.13-2-default
.vmlinuz-4.15.13-2-default.hmac  config-4.15.13-1-default  initrd-4.15.13-1-default       symvers-4.15.13-1-default.gz   vmlinux-4.15.13-1-default.gz  vmlinuz-4.15.9-1-default
.vmlinuz-4.15.9-1-default.hmac   config-4.15.13-2-default  initrd-4.15.13-2-default       symvers-4.15.13-2-default.gz   vmlinux-4.15.13-2-default.gz
System.map-4.15.13-1-default     config-4.15.9-1-default   initrd-4.15.9-1-default        symvers-4.15.9-1-default.gz    vmlinux-4.15.9-1-default.gz
System.map-4.15.13-2-default     efi                       symtypes-4.15.13-1-default.gz  sysctl.conf-4.15.13-1-default  vmlinuz
System.map-4.15.9-1-default      grub2                     symtypes-4.15.13-2-default.gz  sysctl.conf-4.15.13-2-default  vmlinuz-4.15.13-1-default

and

# ls /lib/modules

returns:


4.11.6-1-default  4.11.8-2-default   4.12.7-1-default  4.13.10-1-default  4.13.3-1-default  4.13.9-1-default   4.15.0-1-default   4.15.13-1-default  4.15.3-1-default
4.11.8-1-default  4.12.11-1-default  4.12.8-1-default  4.13.12-1-default  4.13.6-1-default  4.14.11-1-default  4.15.10-1-default  4.15.13-2-default  4.15.9-1-default

when…

# rpm -qa *default

returns:


virtualbox-host-kmp-default-5.2.8_k4.15.13_2-2.3.x86_64
kernel-default-4.15.13-2.4.x86_64
icewm-default-1.4.2-6.1.x86_64
ghc-data-default-0.7.1.1-2.5.x86_64
bbswitch-kmp-default-0.8_k4.15.13_2-28.88.x86_64
kernel-default-4.15.13-1.6.x86_64

Yast only shows 4.15.13-2 and 4.15.13-1 being installed.

If I do

mkinitrd

I get:


Creating initrd: /boot/initrd-4.15.13-1-default
dracut: Executing: /usr/bin/dracut --logfile /var/log/YaST2/mkinitrd.log --force /boot/initrd-4.15.13-1-default 4.15.13-1-default
dracut: *** Including module: bash ***
dracut: *** Including module: systemd ***
dracut: *** Including module: warpclock ***
dracut: *** Including module: systemd-initrd ***
dracut: *** Including module: i18n ***
dracut: Could not find FONT_MAP none!
dracut: *** Including module: drm ***
dracut: *** Including module: plymouth ***
dracut: *** Including module: btrfs ***
dracut: *** Including module: kernel-modules ***
dracut: *** Including module: resume ***
dracut: *** Including module: rootfs-block ***
dracut: *** Including module: suse-xfs ***
dracut: *** Including module: terminfo ***
dracut: *** Including module: udev-rules ***
dracut: Skipping udev rule: 40-redhat.rules
dracut: Skipping udev rule: 50-firmware.rules
dracut: Skipping udev rule: 50-udev.rules
dracut: Skipping udev rule: 91-permissions.rules
dracut: Skipping udev rule: 80-drivers-modprobe.rules
dracut: Skipping udev rule: 61-persistent-storage-compat.rules
dracut: *** Including module: biosdevname ***
dracut: *** Including module: dracut-systemd ***
dracut: *** Including module: haveged ***
dracut: *** Including module: usrmount ***
dracut: *** Including module: base ***
dracut: *** Including module: fs-lib ***
dracut: *** Including module: shutdown ***
dracut: *** Including module: suse ***
dracut: *** Including modules done ***
dracut: *** Installing kernel module dependencies and firmware ***
dracut: *** Installing kernel module dependencies and firmware done ***
dracut: *** Resolving executable dependencies ***
dracut: *** Resolving executable dependencies done***
dracut: *** Hardlinking files ***
dracut: *** Hardlinking files done ***
dracut: *** Stripping files ***
dracut: *** Stripping files done ***
dracut: *** Generating early-microcode cpio image ***
dracut: *** Constructing GenuineIntel.bin ****
dracut: *** Store current command line parameters ***
dracut: Stored kernel commandline:
dracut:  resume=UUID=71befdee-3245-42f0-a4b5-a6bd95ada3e8
dracut:  root=UUID=e957e756-905d-4b97-8239-34bae6f2d47c rootfstype=btrfs rootflags=rw,relatime,ssd,space_cache,subvolid=259,subvol=/@/.snapshots/1/snapshot,subvol=@/.snapshots/1/snapshot
dracut: *** Creating image file '/boot/initrd-4.15.13-1-default' ***
dracut: *** Creating initramfs image file '/boot/initrd-4.15.13-1-default' done ***
Creating initrd: /boot/initrd-4.15.13-2-default
dracut: Executing: /usr/bin/dracut --logfile /var/log/YaST2/mkinitrd.log --force /boot/initrd-4.15.13-2-default 4.15.13-2-default
dracut: *** Including module: bash ***
dracut: *** Including module: systemd ***
dracut: *** Including module: warpclock ***
dracut: *** Including module: systemd-initrd ***
dracut: *** Including module: i18n ***
dracut: Could not find FONT_MAP none!
dracut: *** Including module: drm ***
dracut: *** Including module: plymouth ***
dracut: *** Including module: btrfs ***
dracut: *** Including module: kernel-modules ***
dracut: *** Including module: resume ***
dracut: *** Including module: rootfs-block ***
dracut: *** Including module: suse-xfs ***
dracut: *** Including module: terminfo ***
dracut: *** Including module: udev-rules ***
dracut: Skipping udev rule: 40-redhat.rules
dracut: Skipping udev rule: 50-firmware.rules
dracut: Skipping udev rule: 50-udev.rules
dracut: Skipping udev rule: 91-permissions.rules
dracut: Skipping udev rule: 80-drivers-modprobe.rules
dracut: Skipping udev rule: 61-persistent-storage-compat.rules
dracut: *** Including module: biosdevname ***
dracut: *** Including module: dracut-systemd ***
dracut: *** Including module: haveged ***
dracut: *** Including module: usrmount ***
dracut: *** Including module: base ***
dracut: *** Including module: fs-lib ***
dracut: *** Including module: shutdown ***
dracut: *** Including module: suse ***
dracut: *** Including modules done ***
dracut: *** Installing kernel module dependencies and firmware ***
dracut: *** Installing kernel module dependencies and firmware done ***
dracut: *** Resolving executable dependencies ***
dracut: *** Resolving executable dependencies done***
dracut: *** Hardlinking files ***
dracut: *** Hardlinking files done ***
dracut: *** Stripping files ***
dracut: *** Stripping files done ***
dracut: *** Generating early-microcode cpio image ***
dracut: *** Constructing GenuineIntel.bin ****
dracut: *** Store current command line parameters ***
dracut: Stored kernel commandline:
dracut:  resume=UUID=71befdee-3245-42f0-a4b5-a6bd95ada3e8
dracut:  root=UUID=e957e756-905d-4b97-8239-34bae6f2d47c rootfstype=btrfs rootflags=rw,relatime,ssd,space_cache,subvolid=259,subvol=/@/.snapshots/1/snapshot,subvol=@/.snapshots/1/snapshot
dracut: *** Creating image file '/boot/initrd-4.15.13-2-default' ***
dracut: *** Creating initramfs image file '/boot/initrd-4.15.13-2-default' done ***
Creating initrd: /boot/initrd-4.15.9-1-default
dracut: Executing: /usr/bin/dracut --logfile /var/log/YaST2/mkinitrd.log --force /boot/initrd-4.15.9-1-default 4.15.9-1-default
dracut: *** Including module: bash ***
dracut: *** Including module: systemd ***
dracut: *** Including module: warpclock ***
dracut: *** Including module: systemd-initrd ***
dracut: *** Including module: i18n ***
dracut: Could not find FONT_MAP none!
dracut: *** Including module: drm ***
dracut: *** Including module: plymouth ***
dracut: *** Including module: btrfs ***
dracut: *** Including module: kernel-modules ***
dracut: *** Including module: resume ***
dracut: *** Including module: rootfs-block ***
dracut: *** Including module: suse-xfs ***
dracut: *** Including module: terminfo ***
dracut: *** Including module: udev-rules ***
dracut: Skipping udev rule: 40-redhat.rules
dracut: Skipping udev rule: 50-firmware.rules
dracut: Skipping udev rule: 50-udev.rules
dracut: Skipping udev rule: 91-permissions.rules
dracut: Skipping udev rule: 80-drivers-modprobe.rules
dracut: Skipping udev rule: 61-persistent-storage-compat.rules
dracut: *** Including module: biosdevname ***
dracut: *** Including module: dracut-systemd ***
dracut: *** Including module: haveged ***
dracut: *** Including module: usrmount ***
dracut: *** Including module: base ***
dracut: *** Including module: fs-lib ***
dracut: *** Including module: shutdown ***
dracut: *** Including module: suse ***
dracut: *** Including modules done ***
dracut: *** Installing kernel module dependencies and firmware ***
dracut: *** Installing kernel module dependencies and firmware done ***
dracut: *** Resolving executable dependencies ***
dracut: *** Resolving executable dependencies done***
dracut: *** Hardlinking files ***
dracut: *** Hardlinking files done ***
dracut: *** Stripping files ***
dracut: *** Stripping files done ***
dracut: *** Generating early-microcode cpio image ***
dracut: *** Constructing GenuineIntel.bin ****
dracut: *** Store current command line parameters ***
dracut: Stored kernel commandline:
dracut:  resume=UUID=71befdee-3245-42f0-a4b5-a6bd95ada3e8
dracut:  root=UUID=e957e756-905d-4b97-8239-34bae6f2d47c rootfstype=btrfs rootflags=rw,relatime,ssd,space_cache,subvolid=259,subvol=/@/.snapshots/1/snapshot,subvol=@/.snapshots/1/snapshot
dracut: *** Creating image file '/boot/initrd-4.15.9-1-default' ***
dracut: *** Creating initramfs image file '/boot/initrd-4.15.9-1-default' done ***

I’ve tried rebuilding the rpmdb but not manually removing these old files and directories. I don’t know where all the pieces are and I’m afraid to get things misaligned. I really don’t want to leave so much extra stuff on the drive (SSD, space will eventually be an issue) and the problem of compiling kernels that shouldn’t even be installed bothers me.

It looks to me as if kernel 4.15.9-1 is not in the rpm database, but the corresponding files still exist on disk.

As for that list of directories under “/lib/modules”, many of those are probably almost empty. When you remove a kernel, the corresponding entries under “/lib/modules” are removed, except that a directory cannot be removed if it is not empty. You probably have some third party software, such as an nVidia driver, which puts modules there keeping those directories from being removed. It’s probably okay to manually remove module directories and content for kernels no longer installed.

As for kernel 4.15.9-1: I suppose you could manually remove everything related to that.

It looks to me as if the purging of old kernels is working properly, with the exception of 4.15.9-1.

Drawing the same conslusions.
@OP: I think you’re misunderstanding things. There is no kernel being compiled at boot, none. As no initrd is made during boot. The kernel is compiled in OBS, packaged and distributed. Installing a kernel will trigger mkinitrd to create a RAMdisk used to boot the system. The entries in the GRUB2 boot menu allow you to boot previous kernels, which can be very helpful in some cases.
Another thing: be careful in attempts to ‘clean up’ your system. Do you have any solid reasons / needs to do so?

Thanks, both of you. The nvidia drivers do seem to be the culprit in the modules directory.

It does seem odd, though that doing mkinitrd [FONT=arial]would build (I thought it was recompiling the kernel with the required modules) kernels that are supposedly not installed.

@Knurpht, There’s no immediate problem, but I’ve gotten stuck fixing a system that couldn’t boot or build because the root or boot partitions were full before. I’ve got room now, but want to be mindful of what’s going on so that I’m not fixing a broken system a year from now when I’ve stopped paying attention. That just sucks, mostly because it happens at the least convenient time.[/FONT]

mkinitrd doesn’t compile/build anything.

It just creates a filesystem image for each installed kernel that contains the necessary kernel modules for booting (taken from your actual system partition), that the corresponding kernel can use before the actual system partitions are mounted (which may require to load drivers/modules first that cannot be done without loading those drivers/modules first of course :wink: ).

Btw, it will create an initrd for all kernels found in /boot/, regardless of what the rpm database says about the installed packages.
Just like the boot menu shows all kernels found in /boot/.

You can compile a kernel yourself and use it, without installing a package.