ab92d3
From 3f7410e7f3c08866c84e01ccfb423d7cff4eb5a3 Mon Sep 17 00:00:00 2001
ab92d3
From: Kairui Song <kasong@redhat.com>
ab92d3
Date: Wed, 7 Apr 2021 02:11:41 +0800
ab92d3
Subject: [PATCH] fix(squash): don't mount the mount points if already mounted
ab92d3
ab92d3
It is possible that user setup some early mount in the rootfs even
ab92d3
earlier, so just be more robust and cover that case too.
ab92d3
ab92d3
Signed-off-by: Kairui Song <kasong@redhat.com>
ab92d3
(cherry picked from commit 636d6df3134dde1dac72241937724bc59deb9303)
ab92d3
ab92d3
Resolves: #1959336
ab92d3
---
ab92d3
 modules.d/99squash/init-squash.sh  | 17 +++++++++++------
ab92d3
 modules.d/99squash/module-setup.sh |  4 ++--
ab92d3
 2 files changed, 13 insertions(+), 8 deletions(-)
ab92d3
ab92d3
diff --git a/modules.d/99squash/init-squash.sh b/modules.d/99squash/init-squash.sh
ab92d3
index 3de6f819..59769f62 100755
ab92d3
--- a/modules.d/99squash/init-squash.sh
ab92d3
+++ b/modules.d/99squash/init-squash.sh
ab92d3
@@ -1,12 +1,17 @@
ab92d3
 #!/bin/sh
ab92d3
 PATH=/bin:/sbin
ab92d3
 
ab92d3
-# Basic mounts for mounting a squash image
ab92d3
-mkdir /proc /sys /dev /run
ab92d3
-mount -t proc -o nosuid,noexec,nodev proc /proc
ab92d3
-mount -t sysfs -o nosuid,noexec,nodev sysfs /sys
ab92d3
-mount -t devtmpfs -o mode=755,noexec,nosuid,strictatime devtmpfs /dev
ab92d3
-mount -t tmpfs -o mode=755,nodev,nosuid,strictatime tmpfs /run
ab92d3
+[ -e /proc/self/mounts ] \
ab92d3
+    || (mkdir -p /proc && mount -t proc -o nosuid,noexec,nodev proc /proc)
ab92d3
+
ab92d3
+grep -q '^sysfs /sys sysfs' /proc/self/mounts \
ab92d3
+    || (mkdir -p /sys && mount -t sysfs -o nosuid,noexec,nodev sysfs /sys)
ab92d3
+
ab92d3
+grep -q '^devtmpfs /dev devtmpfs' /proc/self/mounts \
ab92d3
+    || (mkdir -p /dev && mount -t devtmpfs -o mode=755,noexec,nosuid,strictatime devtmpfs /dev)
ab92d3
+
ab92d3
+grep -q '^tmpfs /run tmpfs' /proc/self/mounts \
ab92d3
+    || (mkdir -p /run && mount -t tmpfs -o mode=755,noexec,nosuid,strictatime tmpfs /run)
ab92d3
 
ab92d3
 # Load required modules
ab92d3
 modprobe loop
ab92d3
diff --git a/modules.d/99squash/module-setup.sh b/modules.d/99squash/module-setup.sh
ab92d3
index 72cc83ad..81a5b3f7 100644
ab92d3
--- a/modules.d/99squash/module-setup.sh
ab92d3
+++ b/modules.d/99squash/module-setup.sh
ab92d3
@@ -42,11 +42,11 @@ installpost() {
ab92d3
     # Install required modules and binaries for the squash image init script.
ab92d3
     if [[ $_busybox ]]; then
ab92d3
         inst "$_busybox" /usr/bin/busybox
ab92d3
-        for _i in sh echo mount modprobe mkdir switch_root; do
ab92d3
+        for _i in sh echo mount modprobe mkdir switch_root grep; do
ab92d3
             ln_r /usr/bin/busybox /usr/bin/$_i
ab92d3
         done
ab92d3
     else
ab92d3
-        DRACUT_RESOLVE_DEPS=1 inst_multiple sh mount modprobe mkdir switch_root
ab92d3
+        DRACUT_RESOLVE_DEPS=1 inst_multiple sh mount modprobe mkdir switch_root grep
ab92d3
     fi
ab92d3
 
ab92d3
     hostonly="" instmods "loop" "squashfs" "overlay"
ab92d3