Harald Hoyer b7366e
From 7275c6f6a0f6808cd939ea5bdf1244c7bd13ba44 Mon Sep 17 00:00:00 2001
Harald Hoyer b7366e
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer b7366e
Date: Mon, 17 May 2021 14:22:10 +0200
Harald Hoyer b7366e
Subject: [PATCH] feat(dracut.sh): detect running in a container
Harald Hoyer b7366e
Harald Hoyer b7366e
Don't try to `mknod` by setting DRACUT_NO_MKNOD.
Harald Hoyer b7366e
Don't try to `cp` extended attributrs by setting DRACUT_NO_XATTR.
Harald Hoyer b7366e
---
Harald Hoyer b7366e
 dracut.sh | 9 ++++++++-
Harald Hoyer b7366e
 1 file changed, 8 insertions(+), 1 deletion(-)
Harald Hoyer b7366e
Harald Hoyer b7366e
diff --git a/dracut.sh b/dracut.sh
Harald Hoyer b7366e
index bfb7a1ac..24e1c2e7 100755
Harald Hoyer b7366e
--- a/dracut.sh
Harald Hoyer b7366e
+++ b/dracut.sh
Harald Hoyer b7366e
@@ -1171,6 +1171,13 @@ if [[ -f $dracutbasedir/dracut-version.sh ]]; then
Harald Hoyer b7366e
     . "$dracutbasedir"/dracut-version.sh
Harald Hoyer b7366e
 fi
Harald Hoyer b7366e
 
Harald Hoyer b7366e
+if systemd-detect-virt -c &> /dev/null; then
Harald Hoyer b7366e
+    export DRACUT_NO_MKNOD=1 DRACUT_NO_XATTR=1
Harald Hoyer b7366e
+    if [[ $hostonly ]]; then
Harald Hoyer b7366e
+        printf "%s\n" "dracut: WARNING: running in hostonly mode in a container!!"
Harald Hoyer b7366e
+    fi
Harald Hoyer b7366e
+fi
Harald Hoyer b7366e
+
Harald Hoyer b7366e
 if [[ -f $dracutbasedir/dracut-init.sh ]]; then
Harald Hoyer b7366e
     # shellcheck source=./dracut-init.sh
Harald Hoyer b7366e
     . "$dracutbasedir"/dracut-init.sh
Harald Hoyer b7366e
@@ -1888,7 +1895,7 @@ if [[ $kernel_only != yes ]]; then
Harald Hoyer b7366e
         # shellcheck disable=SC2174
Harald Hoyer b7366e
         mkdir -m 0755 -p "${initdir}/lib/dracut/hooks/$_d"
Harald Hoyer b7366e
     done
Harald Hoyer b7366e
-    if [[ $EUID == "0" ]]; then
Harald Hoyer b7366e
+    if [[ $EUID == "0" ]] && ! [[ $DRACUT_NO_MKNOD ]]; then
Harald Hoyer b7366e
         [[ -c ${initdir}/dev/null ]] || mknod "${initdir}"/dev/null c 1 3
Harald Hoyer b7366e
         [[ -c ${initdir}/dev/kmsg ]] || mknod "${initdir}"/dev/kmsg c 1 11
Harald Hoyer b7366e
         [[ -c ${initdir}/dev/console ]] || mknod "${initdir}"/dev/console c 5 1
Harald Hoyer 8db2b6