Blame 0050-ro_mnt-option-at-build-time-to-force-ro-mount-of-and.patch

Harald Hoyer 12f6cc
From ff3953efe1aec2229273cd59e7d35a540de0e476 Mon Sep 17 00:00:00 2001
Harald Hoyer 12f6cc
From: =?UTF-8?q?Amadeusz=20=C5=BBo=C5=82nowski?= <aidecoe@aidecoe.name>
Harald Hoyer 12f6cc
Date: Thu, 26 Jul 2012 16:44:09 +0200
Harald Hoyer 12f6cc
Subject: [PATCH] ro_mnt - option at build time to force ro mount of / and
Harald Hoyer 12f6cc
 /usr
Harald Hoyer 12f6cc
Harald Hoyer 12f6cc
---
Harald Hoyer 12f6cc
 dracut.conf                      | 3 +++
Harald Hoyer 12f6cc
 dracut.conf.5.asc                | 3 +++
Harald Hoyer 12f6cc
 dracut.sh                        | 6 +++++-
Harald Hoyer 12f6cc
 modules.d/99base/module-setup.sh | 3 +++
Harald Hoyer 12f6cc
 4 files changed, 14 insertions(+), 1 deletion(-)
Harald Hoyer 12f6cc
Harald Hoyer 12f6cc
diff --git a/dracut.conf b/dracut.conf
Harald Hoyer 12f6cc
index f47d571..f912acc 100644
Harald Hoyer 12f6cc
--- a/dracut.conf
Harald Hoyer 12f6cc
+++ b/dracut.conf
Harald Hoyer 12f6cc
@@ -43,6 +43,9 @@ lvmconf="yes"
Harald Hoyer 12f6cc
 # inhibit installation of any fsck tools
Harald Hoyer 12f6cc
 #nofscks="yes"
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
+# mount / and /usr read-only by default
Harald Hoyer 12f6cc
+#ro_mnt="no"
Harald Hoyer 12f6cc
+
Harald Hoyer 12f6cc
 # set the directory for temporary files
Harald Hoyer 12f6cc
 # default: /var/tmp
Harald Hoyer 12f6cc
 #tmpdir=/tmp
Harald Hoyer 12f6cc
diff --git a/dracut.conf.5.asc b/dracut.conf.5.asc
Harald Hoyer 12f6cc
index d17477d..89bbf61 100644
Harald Hoyer 12f6cc
--- a/dracut.conf.5.asc
Harald Hoyer 12f6cc
+++ b/dracut.conf.5.asc
Harald Hoyer 12f6cc
@@ -97,6 +97,9 @@ If chrooted to another root other than the real root device, use --fstab and pro
Harald Hoyer 12f6cc
 *nofscks=*"__{yes|no}__"::
Harald Hoyer 12f6cc
     If specified, inhibit installation of any fsck tools.
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
+*ro_mnt*
Harald Hoyer 12f6cc
+    Mount _/_ and _/usr_ read-only by default.
Harald Hoyer 12f6cc
+
Harald Hoyer 12f6cc
 *kernel_only=*"__{yes|no}__"::
Harald Hoyer 12f6cc
     Only install kernel drivers and firmware files. (default=no)
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
diff --git a/dracut.sh b/dracut.sh
Harald Hoyer 12f6cc
index d8b3354..eee829e 100755
Harald Hoyer 12f6cc
--- a/dracut.sh
Harald Hoyer 12f6cc
+++ b/dracut.sh
Harald Hoyer 12f6cc
@@ -101,6 +101,7 @@ Creates initial ramdisk images for preloading modules
Harald Hoyer 12f6cc
   --nolvmconf           Do not include local /etc/lvm/lvm.conf
Harald Hoyer 12f6cc
   --fscks [LIST]        Add a space-separated list of fsck helpers.
Harald Hoyer 12f6cc
   --nofscks             Inhibit installation of any fsck helpers.
Harald Hoyer 12f6cc
+  --ro-mnt              Mount / and /usr read-only by default.
Harald Hoyer 12f6cc
   -h, --help            This message
Harald Hoyer 12f6cc
   --debug               Output debug information of the build process
Harald Hoyer 12f6cc
   --profile             Output profile information of the build process
Harald Hoyer 12f6cc
@@ -261,6 +262,7 @@ TEMP=$(unset POSIXLY_CORRECT; getopt \
Harald Hoyer 12f6cc
     --long add-fstab: \
Harald Hoyer 12f6cc
     --long mount: \
Harald Hoyer 12f6cc
     --long nofscks: \
Harald Hoyer 12f6cc
+    --long ro-mnt \
Harald Hoyer 12f6cc
     --long kmoddir: \
Harald Hoyer 12f6cc
     --long conf: \
Harald Hoyer 12f6cc
     --long confdir: \
Harald Hoyer 12f6cc
@@ -326,6 +328,7 @@ while :; do
Harald Hoyer 12f6cc
         --add-fstab)   push add_fstab_l          "$2"; shift;;
Harald Hoyer 12f6cc
         --mount)       push fstab_lines          "$2"; shift;;
Harald Hoyer 12f6cc
         --nofscks)     nofscks_l="yes";;
Harald Hoyer 12f6cc
+        --ro-mnt)      ro_mnt_l="yes";;
Harald Hoyer 12f6cc
         -k|--kmoddir)  drivers_dir_l="$2"; shift;;
Harald Hoyer 12f6cc
         -c|--conf)     conffile="$2"; shift;;
Harald Hoyer 12f6cc
         --confdir)     confdir="$2"; shift;;
Harald Hoyer 12f6cc
@@ -558,6 +561,7 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
Harald Hoyer 12f6cc
 [[ $compress_l ]] && compress=$compress_l
Harald Hoyer 12f6cc
 [[ $show_modules_l ]] && show_modules=$show_modules_l
Harald Hoyer 12f6cc
 [[ $nofscks_l ]] && nofscks="yes"
Harald Hoyer 12f6cc
+[[ $ro_mnt_l ]] && ro_mnt="yes"
Harald Hoyer 12f6cc
 # eliminate IFS hackery when messing with fw_dir
Harald Hoyer 12f6cc
 fw_dir=${fw_dir//:/ }
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
@@ -779,7 +783,7 @@ fi
Harald Hoyer 12f6cc
 export initdir dracutbasedir dracutmodules drivers \
Harald Hoyer 12f6cc
     fw_dir drivers_dir debug no_kernel kernel_only \
Harald Hoyer 12f6cc
     add_drivers omit_drivers mdadmconf lvmconf filesystems \
Harald Hoyer 12f6cc
-    use_fstab fstab_lines libdirs fscks nofscks \
Harald Hoyer 12f6cc
+    use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
Harald Hoyer 12f6cc
     stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
Harald Hoyer 12f6cc
     debug host_fs_types host_devs sshkey add_fstab \
Harald Hoyer 12f6cc
     DRACUT_VERSION udevdir systemdutildir systemdsystemunitdir \
Harald Hoyer 12f6cc
diff --git a/modules.d/99base/module-setup.sh b/modules.d/99base/module-setup.sh
Harald Hoyer 12f6cc
index f20ca1a..dde1285 100755
Harald Hoyer 12f6cc
--- a/modules.d/99base/module-setup.sh
Harald Hoyer 12f6cc
+++ b/modules.d/99base/module-setup.sh
Harald Hoyer 12f6cc
@@ -50,6 +50,9 @@ install() {
Harald Hoyer 12f6cc
     fi
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
     ln -fs /proc/self/mounts "$initdir/etc/mtab"
Harald Hoyer 12f6cc
+    if [[ $ro_mnt = yes ]]; then
Harald Hoyer 12f6cc
+        echo ro >> "${initdir}/etc/cmdline.d/base.conf"
Harald Hoyer 12f6cc
+    fi
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
     if [ -e /etc/os-release ]; then
Harald Hoyer 12f6cc
         . /etc/os-release