]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(squash): don't mount the mount points if already mounted
authorKairui Song <kasong@redhat.com>
Tue, 6 Apr 2021 18:11:41 +0000 (02:11 +0800)
committerJóhann B. Guðmundsson <johannbg@gmail.com>
Wed, 19 May 2021 08:46:34 +0000 (08:46 +0000)
It is possible that user setup some early mount in the rootfs even
earlier, so just be more robust and cover that case too.

Signed-off-by: Kairui Song <kasong@redhat.com>
modules.d/99squash/init-squash.sh
modules.d/99squash/module-setup.sh

index 3de6f819954074a8c41bce74de55f8c66de499b1..59769f621827c72cb7e77a71d3e85492f4bedc21 100755 (executable)
@@ -1,12 +1,17 @@
 #!/bin/sh
 PATH=/bin:/sbin
 
-# Basic mounts for mounting a squash image
-mkdir /proc /sys /dev /run
-mount -t proc -o nosuid,noexec,nodev proc /proc
-mount -t sysfs -o nosuid,noexec,nodev sysfs /sys
-mount -t devtmpfs -o mode=755,noexec,nosuid,strictatime devtmpfs /dev
-mount -t tmpfs -o mode=755,nodev,nosuid,strictatime tmpfs /run
+[ -e /proc/self/mounts ] \
+    || (mkdir -p /proc && mount -t proc -o nosuid,noexec,nodev proc /proc)
+
+grep -q '^sysfs /sys sysfs' /proc/self/mounts \
+    || (mkdir -p /sys && mount -t sysfs -o nosuid,noexec,nodev sysfs /sys)
+
+grep -q '^devtmpfs /dev devtmpfs' /proc/self/mounts \
+    || (mkdir -p /dev && mount -t devtmpfs -o mode=755,noexec,nosuid,strictatime devtmpfs /dev)
+
+grep -q '^tmpfs /run tmpfs' /proc/self/mounts \
+    || (mkdir -p /run && mount -t tmpfs -o mode=755,noexec,nosuid,strictatime tmpfs /run)
 
 # Load required modules
 modprobe loop
index 775200273ce2ff01db275094e122f9f26039b5e6..e3196213f96dd8030de8ef46cf2b492c6a8a85bb 100644 (file)
@@ -42,11 +42,11 @@ installpost() {
     # Install required modules and binaries for the squash image init script.
     if [[ $_busybox ]]; then
         inst "$_busybox" /usr/bin/busybox
-        for _i in sh echo mount modprobe mkdir switch_root; do
+        for _i in sh echo mount modprobe mkdir switch_root grep; do
             ln_r /usr/bin/busybox /usr/bin/$_i
         done
     else
-        DRACUT_RESOLVE_DEPS=1 inst_multiple sh mount modprobe mkdir switch_root
+        DRACUT_RESOLVE_DEPS=1 inst_multiple sh mount modprobe mkdir switch_root grep
     fi
 
     hostonly="" instmods "loop" "squashfs" "overlay"