Question about zypper dist-upgrade

Learning about OpenSuse Tumbleweed and Linux
I ran

zypper dist-upgrade

and the result is a bit surprising to me. It wants to remove the main kernel in use. Is it normal behavior ? I mainly use Yast but though would see what this command line would return.

The following 3 packages are going to be REMOVED:
kernel-default-5.14.14-1.1 kernel-default-devel-5.14.14-1.1 kernel-devel-5.14.14-1.1

It is probably okay.

Normally, it leaves the old kernel when a new one is installed. And cleanup occurs later.

However there is a special case, and I think that’s what you saw. You were using 5.14.14-1.1. But a new kernel (version 5.14.14-1.3, if I recall) was being installed. When just the last digit changes, this is usually a recompile of the same sources.

The reason this happens, is that although the kernel version is [FONT=monospace]5.14.14-1.1, file name for kernel and related files just uses [/FONT][FONT=monospace][FONT=monospace]5.14.14-1 (without the last “.1”). So you would then have two kernels with the same file name – one overwrites the other. And you would get a file conflict message. So zypper dup removes the previous kernel to avoid this issue.[/FONT]
[/FONT]

thank you.
Could I go ahead and remove those kernels ?

Let zypper or yast do the removal as a part of the process up dist-upgrading to include the current kernel.

Yes, I agree with mrmazda that you should leave it to “zypper” to handle the kernel removal.

But I want to add that you should only use zypper dist-upgrade (or zypper dup) for updating Tumbleweed. Yast is likely to miss some of what “zypper” does.

Done.
Thank you.
Being new to Linux I am distro hopping a lot. OpenSuse Tumbleweed is one of the most stable Distro I have used to this day.

This is default behavior:

**erlangen:~ #** grep multiversion.kernels /etc/zypp/zypp.conf 
**multiversion.kernels** = latest,latest-1,running 
**erlangen:~ #**

‘zypper dist-upgrade’ removes everything but the above. I use it since ever.

Beware in case of trouble: You may want to keep the old kernels.

I understand the concept of keeping the old kernel but isn’t the boot partition a bit small to be keeping a large amount of old (older) kernels ?

I do have the same result as you. Probably standard ?

grep multiversion.kernels /etc/zypp/zypp.conf 
**multiversion.kernels** = latest,latest-1,running

Yes, I meant default = standard or vendor.

Two kernels:

**erlangen:~ #** du -chd1 /usr/lib/modules/ /boot/ 
117M    /usr/lib/modules/5.14.11-2-default 
119M    /usr/lib/modules/5.14.14-1-default 
236M    /usr/lib/modules/ 
8.4M    /boot/efi 
8.7M    /boot/grub2 
116M    /boot/ 
351M    total 
**erlangen:~ #**

I have lot more than n -1

103M /usr/lib/modules/5.14.5-1-default
103M /usr/lib/modules/5.14.6-1-default
103M /usr/lib/modules/5.14.6-2-default
103M /usr/lib/modules/5.14.9-1-default
103M /usr/lib/modules/5.14.11-1-default
103M /usr/lib/modules/5.14.11-2-default
222M /usr/lib/modules/5.14.14-1-default

What is the best process to clean those up and make sure I have only n -1

Use:

zypper purge-kernels

How did you install? Normally, the “purge-kernels” service is enabled, and should automatically clean up the older kernels. But it is possible that it is not enabled for some people. There was a time when it was broken, but that was maybe a year ago.

rpm -qa kern*

kernel-macros-5.14.14-1.3.noarch
kernel-default-5.14.14-1.3.x86_64
kernel-devel-5.14.14-1.3.noarch
kernel-default-devel-5.14.14-1.3.x86_64

I guess from the command I do not have too many kernels.

du -chd1 /usr/lib/modules/ /boot/ 

103M /usr/lib/modules/5.14.5-1-default
103M /usr/lib/modules/5.14.6-1-default
103M /usr/lib/modules/5.14.6-2-default
103M /usr/lib/modules/5.14.9-1-default
103M /usr/lib/modules/5.14.11-1-default
103M /usr/lib/modules/5.14.11-2-default
222M /usr/lib/modules/5.14.14-1-default

This gives me a lot more apparent kernels in /usr/lib/modules

zypper purge-kernels

Preparing to purge obsolete kernels…
Configuration: latest,latest-1,running
Running kernel release: 5.14.14-1-default
Running kernel arch: x86_64

Resolving package dependencies…
Nothing to do.

I guess zypper is correlating with zypp.conf and sees that I have indeed n-1 and running the latest kernel.

Rephrasing the first question, what would be the simplest way to purge old kernels in /usr/lib/modules/ ?

Please use tags [noparse]

...

[/noparse], not quotes, when posting computer output. Otherwise text you posted is not included in reply and it is impossible to comment it in context.

Anyway, rpm only removes directories when they are empty; so you have some files in all these directories that are not part of kernel rpm. You need to check these files.

what would be the simplest way to purge old kernels in /usr/lib/modules/ ?

rm -rf, but I would check what is inside first.

If you look inside those “/usr/lib/modules” directories for older kernels, you will probably find that they are mostly empty.

I used to see that on an older computer with an Nvidia graphics card. The module used by the Nvidia driver does not come with the kernel. So when the kernel is removed, the corresponding “/usr/lib/modules” directory is not empty so not removed.

I also saw that back when my network card required a driver that did not come with the kernel.

The answer then – those old directories are not actually using much space. And you get to decide whether it is save to manually remove them.

Well, each directory is 100M vs. 200M of currently running kernel. I would not call it “not much”.

They are taking some space on my disk. The reason is I need to optimize my disk space as much as I can.
If something is not of use, it needs to be removed.
From what I gather, they weren’t removed because not empty ? Looks like I am going to have to use the ‘rm’ command which I do not like very much as it nukes everything. As a user (not an admin or IT guy) I did make mistakes removing stuff I should not have :stuck_out_tongue: Learnt the hard way that the ‘rm’ command has no mercy

Instead of RM, try MC, which makes it easy to first examine what may or may not need to be F8’d, and harder to make a mistake.

Purging old kernels is fully automatic:

erlangen:~ # systemctl list-unit-files purge-kernels.service
UNIT FILE             STATE   VENDOR PRESET
purge-kernels.service enabled enabled      

1 unit files listed.
erlangen:~ # journalctl -b -1 -u purge-kernels.service 
-- Journal begins at Tue 2021-11-02 20:16:01 CET, ends at Wed 2021-11-10 20:32:48 CET. --
Nov 06 19:14:13 erlangen systemd[1]: Starting Purge old kernels...
Nov 06 19:14:14 erlangen zypper[731]: Installierte Pakete werden gelesen...
Nov 06 19:14:14 erlangen zypper[731]: Säuberung von veralteten Kerneln wird vorbereitet...
Nov 06 19:14:14 erlangen zypper[731]: Konfiguration: latest,latest-1,running
Nov 06 19:14:14 erlangen zypper[731]: Kernel Release läuft: 5.14.14-1-default
Nov 06 19:14:14 erlangen zypper[731]: Kernel arch läuft: x86_64
Nov 06 19:14:14 erlangen zypper[731]: Paketabhängigkeiten werden aufgelöst...
Nov 06 19:14:14 erlangen zypper[731]: Keine auszuführenden Aktionen.
Nov 06 19:14:14 erlangen systemd[1]: purge-kernels.service: Deactivated successfully.
Nov 06 19:14:14 erlangen systemd[1]: Finished Purge old kernels.
erlangen:~ #