Harald Hoyer fe68ba
From 740e41b84380bfccf1dd93278f8b89f1403e89ec Mon Sep 17 00:00:00 2001
Harald Hoyer fe68ba
From: Colin Walters <walters@verbum.org>
Harald Hoyer fe68ba
Date: Wed, 2 May 2018 11:11:59 -0400
Harald Hoyer fe68ba
Subject: [PATCH] Suppress sync/fsfreeze if not running on a live system
Harald Hoyer fe68ba
Harald Hoyer fe68ba
It's possible for e.g. `kernel` to be installed as an RPM BuildRequires or equivalent,
Harald Hoyer fe68ba
and there's no reason to sync, and *definitely* no reason to fsfreeze.
Harald Hoyer fe68ba
Harald Hoyer fe68ba
Another case where this happens is rpm-ostree, which performs its own sync/fsfreeze
Harald Hoyer fe68ba
globally.  See e.g. https://github.com/ostreedev/ostree/commit/8642ef5ab3fec3ac8eb8f193054852f83a8bc4d0
Harald Hoyer fe68ba
---
Harald Hoyer fe68ba
 dracut.sh | 23 +++++++++++++++--------
Harald Hoyer fe68ba
 1 file changed, 15 insertions(+), 8 deletions(-)
Harald Hoyer fe68ba
Harald Hoyer fe68ba
diff --git a/dracut.sh b/dracut.sh
Harald Hoyer fe68ba
index 8b0465df..f52d38ac 100755
Harald Hoyer fe68ba
--- a/dracut.sh
Harald Hoyer fe68ba
+++ b/dracut.sh
Harald Hoyer fe68ba
@@ -1832,15 +1832,22 @@ fi
Harald Hoyer fe68ba
 
Harald Hoyer fe68ba
 command -v restorecon &>/dev/null && restorecon -- "$outfile"
Harald Hoyer fe68ba
 
Harald Hoyer fe68ba
-if ! sync "$outfile" 2> /dev/null; then
Harald Hoyer fe68ba
-    dinfo "dracut: sync operation on newly created initramfs $outfile failed"
Harald Hoyer fe68ba
-    exit 1
Harald Hoyer fe68ba
-fi
Harald Hoyer fe68ba
+# We sync/fsfreeze only if we're operating on a live booted system.
Harald Hoyer fe68ba
+# It's possible for e.g. `kernel` to be installed as an RPM BuildRequires or equivalent,
Harald Hoyer fe68ba
+# and there's no reason to sync, and *definitely* no reason to fsfreeze.
Harald Hoyer fe68ba
+# Another case where this happens is rpm-ostree, which performs its own sync/fsfreeze
Harald Hoyer fe68ba
+# globally.  See e.g. https://github.com/ostreedev/ostree/commit/8642ef5ab3fec3ac8eb8f193054852f83a8bc4d0
Harald Hoyer fe68ba
+if test -d /run/systemd/system; then
Harald Hoyer fe68ba
+    if ! sync "$outfile" 2> /dev/null; then
Harald Hoyer fe68ba
+        dinfo "dracut: sync operation on newly created initramfs $outfile failed"
Harald Hoyer fe68ba
+        exit 1
Harald Hoyer fe68ba
+    fi
Harald Hoyer fe68ba
 
Harald Hoyer fe68ba
-# use fsfreeze only if we're not writing to /
Harald Hoyer fe68ba
-if [[ "$(stat -c %m -- "$outfile")" != "/" && "$(stat -f -c %T -- "$outfile")" != "msdos" ]]; then
Harald Hoyer fe68ba
-    if ! $(fsfreeze -f $(dirname "$outfile") 2>/dev/null && fsfreeze -u $(dirname "$outfile") 2>/dev/null); then
Harald Hoyer fe68ba
-        dinfo "dracut: warning: could not fsfreeze $(dirname "$outfile")"
Harald Hoyer fe68ba
+    # use fsfreeze only if we're not writing to /
Harald Hoyer fe68ba
+    if [[ "$(stat -c %m -- "$outfile")" != "/" && "$(stat -f -c %T -- "$outfile")" != "msdos" ]]; then
Harald Hoyer fe68ba
+        if ! $(fsfreeze -f $(dirname "$outfile") 2>/dev/null && fsfreeze -u $(dirname "$outfile") 2>/dev/null); then
Harald Hoyer fe68ba
+            dinfo "dracut: warning: could not fsfreeze $(dirname "$outfile")"
Harald Hoyer fe68ba
+        fi
Harald Hoyer fe68ba
     fi
Harald Hoyer fe68ba
 fi
Harald Hoyer fe68ba
 
Harald Hoyer fe68ba