]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
fix(dracut): consolidate reporting running in a container
authorJo Zzsi <jozzsicsataban@gmail.com>
Sat, 19 Jul 2025 03:05:58 +0000 (23:05 -0400)
committerBenjamin Drung <bdrung@ubuntu.com>
Sun, 20 Jul 2025 11:32:56 +0000 (13:32 +0200)
dinfo call to report running in a container does not work as expected
as dinfo is not yet defined in the first code block.

In addition we're already reporting running in a container in some
other conditions, which would lead to reporting it twice.

Consolidate reporting running in a container into one single place
and make it work, and reporting is as information and not as a warning
as using dracut inside container is common.

Reordered two code blocks to enable the usage of dinfo to simplify
reporting.

Follow-up to 2b2debd .

dracut.sh

index 909eac6f9535f84c7e5393b8ff5605ca1155edf3..0576a7f254a877aaa6ba389df1142dba692550be 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -1073,8 +1073,7 @@ if [[ $regenerate_all == "yes" ]]; then
 fi
 
 if ! [[ $kernel ]]; then
-    if type -P systemd-detect-virt &> /dev/null && container=$(systemd-detect-virt -c) &> /dev/null; then
-        dinfo "*** Detected container: $container ***"
+    if type -P systemd-detect-virt &> /dev/null && systemd-detect-virt -c &> /dev/null; then
         # shellcheck disable=SC2012
         kernel="$(cd /lib/modules && ls -1v | tail -1)"
         # shellcheck disable=SC2012
@@ -1422,13 +1421,6 @@ if [[ -f $dracutbasedir/dracut-version.sh ]]; then
     . "$dracutbasedir"/dracut-version.sh
 fi
 
-if systemd-detect-virt -c &> /dev/null; then
-    export DRACUT_NO_MKNOD=1
-    if [[ ${hostonly-} ]]; then
-        printf "%s\n" "dracut[W]: Running in hostonly mode in a container!" >&2
-    fi
-fi
-
 if [[ -f $dracutbasedir/dracut-init.sh ]]; then
     # shellcheck source=./dracut-init.sh
     . "$dracutbasedir"/dracut-init.sh
@@ -1439,6 +1431,11 @@ else
     exit 1
 fi
 
+if container=$(systemd-detect-virt -c) &> /dev/null; then
+    export DRACUT_NO_MKNOD=1
+    dinfo "Detected $container container."
+fi
+
 if [[ $persistent_policy == "mapper" ]]; then
     unset persistent_policy
 elif [[ -n $persistent_policy && ! -d "/dev/disk/${persistent_policy}" ]]; then