Multiple kernels kver_cmd to return an incoherent string

Bug #2028092 reported by Peter Mattingly
18
This bug affects 4 people
Affects Status Importance Assigned to Milestone
curtin
New
Undecided
Unassigned

Bug Description

Hello,

A customer had contacted with an issue related to this bug. Taking a look at the stacktrace for the issue:

```
ls -la
total 16
drwxr-xr-x. 4 root root 4096 Feb 10 02:53 .
dr-xr-xr-x. 40 root root 4096 Feb 10 02:58 ..
drwxr-xr-x. 6 root root 4096 Feb 10 02:54 4.18.0-372.32.1.el8_6.x86_64
drwxr-xr-x. 6 root root 4096 Feb 10 02:49 4.18.0-372.9.1.el8.x86_64

<stack trace>
Running curthooks.builtin_curthooks...
Traceback (most recent call last):
File "/tmp/tmp1x5k7i8r/target/curtin/curtin-hooks", line 133, in <module>
main()
File "/tmp/tmp1x5k7i8r/target/curtin/curtin-hooks", line 129, in main
curthook(config, target, state)
File "/tmp/tmp1x5k7i8r/target/curtin/curtin-hooks", line 114, in curthook
curthooks.builtin_curthooks(cfg, target, state)
File "/curtin/curtin/commands/curthooks.py", line 1831, in builtin_curthooks
redhat_update_initramfs(target, cfg)
File "/curtin/curtin/commands/curthooks.py", line 1672, in redhat_update_initramfs
in_chroot.subp(dracut_cmd, capture=True)
File "/curtin/curtin/util.py", line 787, in subp
return subp(*args, **kwargs)
File "/curtin/curtin/util.py", line 275, in subp
return _subp(*args, **kwargs)
File "/curtin/curtin/util.py", line 139, in _subp
raise ProcessExecutionError(stdout=out, stderr=err,
curtin.util.ProcessExecutionError: Unexpected error while running command.
Command: ['unshare', '--fork', '--pid', '--', 'chroot', '/tmp/tmp1x5k7i8r/target', 'dracut', '-f', '/boot/initramfs-4.18.0-372.9.1.el8.x86_644.18.0-372.32.1.el8_6.x86_64.img', '4.18.0-372.9.1.el8.x86_644.18.0-372.32.1.el8_6.x86_64']
Exit code: 1
Reason: -
Stdout: ''
Stderr: dracut: Cannot find module directory /lib/modules/4.18.0-372.9.1.el8.x86_644.18.0-372.32.1.el8_6.x86_64/
dracut: and --no-kernel was not specified
```

Then following the stack trace, this line in the source can be found:

```
kver_cmd = ['rpm', '-q', '--queryformat', '%{VERSION}-%{RELEASE}.%{ARCH}', 'kernel']
```

Then, if this command is run on a system with at leas two kernels installed, the returned string is malformed:

```
rpm -q --queryformat='%{VERSION}-%{RELEASE}.%{ARCH}' kernel
4.18.0-477.10.1.el8_8.x86_64
```

Which causes an issue in the customer's use-case.

As this issue is time sensitive, would it be possible to request a workaround while a fix is developed?

Thank you.

Revision history for this message
Nicholas Fries (nicfries) wrote :

We have a workaround (we ensure only one kernel exists in our image). This issue can occur if a user builds and image and in the process runs a yum update. In this case, two kernels may exist in /boot causing this issue.

Revision history for this message
Dagmawi Biru (dagbiru) wrote (last edit ):
Revision history for this message
Peter Neal (peterneal) wrote :

Bringing this back to life,

Yes, on a system with two or more kernels present,

rpm -q --queryformat='%{VERSION}-%{RELEASE}.%{ARCH}' kernel

will output the results for both kernels concatenated together, i.e. if the system has both 'kernel-4.18.0-372.9.1.el8' and 'kernel-4.18.0-372.32.1.el8_6' present, this command returns `4.18.0-372.9.1.el8.x86_644.18.0-372.32.1.el8_6.x86_64`. This gets passed to dracut, fails, and fails the deployment.

I propose simply changing the query to `rpm -q --queryformat='%{VERSION}-%{RELEASE}.%{ARCH}\n' kernel`, capturing the output in some array $kvers, then proceed inside of something like `for(kver in kvers): dracut -f kver`.

This should also be applied to oracle linux but for the kernel-uek package.

It's not convenient to purge extra kernels during image build, and there are cases where we want > 1 kernels available on deployment.

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.