File: fix-dracut-do-not-call-uname-r-in-chroot-environments.patch

package info (click to toggle)
dracut 108-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,420 kB
  • sloc: sh: 25,011; ansic: 5,202; makefile: 348; perl: 186; python: 28; javascript: 19
file content (43 lines) | stat: -rw-r--r-- 1,634 bytes parent folder | download
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
From: Benjamin Drung <benjamin.drung@canonical.com>
Date: Mon, 4 Aug 2025 14:41:41 +0200
Subject: fix(dracut): do not call uname -r in chroot environments

Running dracut in a schroot environment (even with `systemd-detect-virt`
installed) will pick `uname -r` as kernel version despite that kernel
not being available.

So also check `systemd-detect-virt --chroot` before relying on
`uname -r`.

Forwarded: https://github.com/dracut-ng/dracut-ng/pull/1483
---
 dracut.sh   | 2 +-
 lsinitrd.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/dracut.sh b/dracut.sh
index e6adffe..d0d8bf2 100755
--- a/dracut.sh
+++ b/dracut.sh
@@ -969,7 +969,7 @@ 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; then
+    if 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
diff --git a/lsinitrd.sh b/lsinitrd.sh
index 86b2c5a..af7233a 100755
--- a/lsinitrd.sh
+++ b/lsinitrd.sh
@@ -97,7 +97,7 @@ while (($# > 0)); do
 done
 
 if ! [[ $KERNEL_VERSION ]]; then
-    if type -P systemd-detect-virt &> /dev/null && ! systemd-detect-virt -c &> /dev/null; then
+    if type -P systemd-detect-virt &> /dev/null && ! systemd-detect-virt -c &> /dev/null && ! systemd-detect-virt -r &> /dev/null; then
         KERNEL_VERSION="$(uname -r)"
     else
         # shellcheck disable=SC2012