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