From: Jo Zzsi Date: Sat, 19 Jul 2025 03:05:58 +0000 (-0400) Subject: fix(dracut): consolidate reporting running in a container X-Git-Tag: 108~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=000f5dbfb6539d03fc90165d04de88b49ff6bedb;p=thirdparty%2Fdracut-ng.git fix(dracut): consolidate reporting running in a container 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 . --- diff --git a/dracut.sh b/dracut.sh index 909eac6f9..0576a7f25 100755 --- 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