1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
From: Antonio Alvarez Feijoo <antonio.feijoo@suse.com>
Date: Wed, 25 Mar 2026 16:58:54 +0100
Subject: fix(dracut): properly detect kernel version with --sysroot
Both `uname -r` and `cd /lib/modules` do not give the proper kernel version of
the sysroot directory.
E.g. of the wrong behavior:
```
$ dracut -f --sysroot /srv/tw --no-kernel test.img
realpath: /srv/tw/lib/modules/6.19.6-1-default: No such file or directory
$ uname -r
6.19.6-1-default
$ ls -l /srv/tw/usr/lib/modules
total 0
drwxr-xr-x. 1 root root 630 Mar 25 16:30 6.19.8-1-default
```
Follow-up for 2b2debd7947b7d5a357c1a89691a75dfd3565747
Forwarded: https://github.com/dracut-ng/dracut-ng/pull/2317
---
dracut.sh | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/dracut.sh b/dracut.sh
index 34aa09a..e32e2ef 100755
--- a/dracut.sh
+++ b/dracut.sh
@@ -974,11 +974,12 @@ export DRACUT_LOG_LEVEL=warning
export add_dlopen_features="" omit_dlopen_features=""
if ! [[ $kernel ]] && [[ $regenerate_all_l != "yes" ]]; then
- if type -P systemd-detect-virt &> /dev/null && ! systemd-detect-virt -c &> /dev/null && ! systemd-detect-virt -r &> /dev/null; then
+ if [[ -z ${dracutsysrootdir-} ]] \
+ && type -P systemd-detect-virt &> /dev/null && ! systemd-detect-virt -c &> /dev/null && ! systemd-detect-virt -r &> /dev/null; then
kernel="$(uname -r)"
else
# shellcheck disable=SC2012
- kernel="$(cd /lib/modules && ls -1v | tail -1)"
+ kernel="$(cd "${dracutsysrootdir-}"/lib/modules && ls -1v | tail -1)"
fi
fi
|