Blame 0008-do-not-umount-root-remount-it.-do-not-mount-ro-if-no.patch

Harald Hoyer c4a5a0
From 7209df9e912c73318dcb380838bc1dbe24a43a4b Mon Sep 17 00:00:00 2001
Harald Hoyer c4a5a0
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer c4a5a0
Date: Sat, 30 Jun 2012 11:29:30 +0200
Harald Hoyer c4a5a0
Subject: [PATCH] do not umount root, remount it. do not mount ro if not
Harald Hoyer c4a5a0
 specified
Harald Hoyer c4a5a0
Harald Hoyer c4a5a0
also mount /usr readonly if "ro" is specified on the command line
Harald Hoyer c4a5a0
if /usr is a btrfs subvolume of root, use the same mount options
Harald Hoyer c4a5a0
---
Harald Hoyer c4a5a0
 modules.d/95rootfs-block/mount-root.sh |   20 +++++++++-----------
Harald Hoyer c4a5a0
 modules.d/98usrmount/mount-usr.sh      |    9 +++++++++
Harald Hoyer c4a5a0
 modules.d/99base/parse-root-opts.sh    |    6 ++++--
Harald Hoyer c4a5a0
 3 files changed, 22 insertions(+), 13 deletions(-)
Harald Hoyer c4a5a0
Harald Hoyer c4a5a0
diff --git a/modules.d/95rootfs-block/mount-root.sh b/modules.d/95rootfs-block/mount-root.sh
Harald Hoyer c4a5a0
index 19f59fa..932571a 100755
Harald Hoyer c4a5a0
--- a/modules.d/95rootfs-block/mount-root.sh
Harald Hoyer c4a5a0
+++ b/modules.d/95rootfs-block/mount-root.sh
Harald Hoyer c4a5a0
@@ -15,7 +15,6 @@ filter_rootopts() {
Harald Hoyer c4a5a0
     local v
Harald Hoyer c4a5a0
     while [ $# -gt 0 ]; do
Harald Hoyer c4a5a0
         case $1 in
Harald Hoyer c4a5a0
-            rw|ro);;
Harald Hoyer c4a5a0
             defaults);;
Harald Hoyer c4a5a0
             *)
Harald Hoyer c4a5a0
                 v="$v,${1}";;
Harald Hoyer c4a5a0
@@ -82,7 +81,7 @@ mount_root() {
Harald Hoyer c4a5a0
         # the root filesystem,
Harald Hoyer c4a5a0
         # remount it with the proper options
Harald Hoyer c4a5a0
         rootopts="defaults"
Harald Hoyer c4a5a0
-        while read dev mp fs opts rest; do
Harald Hoyer c4a5a0
+        while read dev mp fs opts dump fsck; do
Harald Hoyer c4a5a0
             # skip comments
Harald Hoyer c4a5a0
             [ "${dev%%#*}" != "$dev" ] && continue
Harald Hoyer c4a5a0
 
Harald Hoyer c4a5a0
@@ -90,6 +89,7 @@ mount_root() {
Harald Hoyer c4a5a0
                 # sanity - determine/fix fstype
Harald Hoyer c4a5a0
                 rootfs=$(det_fs "${root#block:}" "$fs")
Harald Hoyer c4a5a0
                 rootopts=$opts
Harald Hoyer c4a5a0
+                rootfsck=$fsck
Harald Hoyer c4a5a0
                 break
Harald Hoyer c4a5a0
             fi
Harald Hoyer c4a5a0
         done < "$NEWROOT/etc/fstab"
Harald Hoyer c4a5a0
@@ -99,28 +99,26 @@ mount_root() {
Harald Hoyer c4a5a0
 
Harald Hoyer c4a5a0
     # we want rootflags (rflags) to take precedence so prepend rootopts to
Harald Hoyer c4a5a0
     # them; rflags is guaranteed to not be empty
Harald Hoyer c4a5a0
-    rflags="${rootopts:+"${rootopts},"}${rflags}"
Harald Hoyer c4a5a0
+    rflags="${rootopts:+${rootopts},}${rflags}"
Harald Hoyer c4a5a0
 
Harald Hoyer c4a5a0
     # backslashes are treated as escape character in fstab
Harald Hoyer c4a5a0
     # esc_root=$(echo ${root#block:} | sed 's,\\,\\\\,g')
Harald Hoyer c4a5a0
     # printf '%s %s %s %s 1 1 \n' "$esc_root" "$NEWROOT" "$rootfs" "$rflags" >/etc/fstab
Harald Hoyer c4a5a0
 
Harald Hoyer c4a5a0
     ran_fsck=0
Harald Hoyer c4a5a0
-    if [ -z "$fastboot" -a "$READONLY" != "yes" ] && \
Harald Hoyer c4a5a0
-            ! strstr "${rflags},${rootopts}" _netdev && \
Harald Hoyer c4a5a0
+    if [ "$rootfsck" != "0" -a -z "$fastboot" -a "$READONLY" != "yes" ] && \
Harald Hoyer c4a5a0
+            ! strstr "${rflags}" _netdev && \
Harald Hoyer c4a5a0
             ! getargbool 0 rd.skipfsck; then
Harald Hoyer c4a5a0
-        umount "$NEWROOT"
Harald Hoyer c4a5a0
         fsck_single "${root#block:}" "$rootfs" "$rflags" "$fsckoptions"
Harald Hoyer c4a5a0
         _ret=$?
Harald Hoyer c4a5a0
         [ $_ret -ne 255 ] && echo $_ret >/run/initramfs/root-fsck
Harald Hoyer c4a5a0
         ran_fsck=1
Harald Hoyer c4a5a0
     fi
Harald Hoyer c4a5a0
 
Harald Hoyer c4a5a0
-    if [ -n "$rootopts" -o "$ran_fsck" = "1" ]; then
Harald Hoyer c4a5a0
-        info "Remounting ${root#block:} with -o ${rflags}"
Harald Hoyer c4a5a0
-        umount "$NEWROOT" &>/dev/null
Harald Hoyer c4a5a0
-        mount -t "$rootfs" -o "$rflags" "${root#block:}" "$NEWROOT" 2>&1 | vinfo
Harald Hoyer c4a5a0
-    fi
Harald Hoyer c4a5a0
+    echo "${root#block:} $NEWROOT $rootfs ${rflags:-defaults} 0 $rootfsck" >> /etc/fstab
Harald Hoyer c4a5a0
+
Harald Hoyer c4a5a0
+    info "Remounting ${root#block:} with -o ${rflags}"
Harald Hoyer c4a5a0
+    mount -o remount "$NEWROOT" 2>&1 | vinfo
Harald Hoyer c4a5a0
 
Harald Hoyer c4a5a0
     [ -f "$NEWROOT"/forcefsck ] && rm -f "$NEWROOT"/forcefsck 2>/dev/null
Harald Hoyer c4a5a0
     [ -f "$NEWROOT"/.autofsck ] && rm -f "$NEWROOT"/.autofsck 2>/dev/null
Harald Hoyer c4a5a0
diff --git a/modules.d/98usrmount/mount-usr.sh b/modules.d/98usrmount/mount-usr.sh
Harald Hoyer c4a5a0
index 5798777..5cf4eb8 100755
Harald Hoyer c4a5a0
--- a/modules.d/98usrmount/mount-usr.sh
Harald Hoyer c4a5a0
+++ b/modules.d/98usrmount/mount-usr.sh
Harald Hoyer c4a5a0
@@ -52,6 +52,15 @@ mount_usr()
Harald Hoyer c4a5a0
                     _dev="/dev/disk/by-uuid/${_dev#UUID=}"
Harald Hoyer c4a5a0
                     ;;
Harald Hoyer c4a5a0
             esac
Harald Hoyer c4a5a0
+            if strstr "$_opts" "subvol=" && \
Harald Hoyer c4a5a0
+                [ "${root#block:}" -ef $_dev ]
Harald Hoyer c4a5a0
+                [ -n "$rflags" ]; then
Harald Hoyer c4a5a0
+                # for btrfs subvolumes we have to mount /usr with the same rflags
Harald Hoyer c4a5a0
+                _opts="${_opts:+${_opts},}${rflags}"
Harald Hoyer c4a5a0
+            elif getarg ro; then
Harald Hoyer c4a5a0
+                # if "ro" is specified, we want /usr to be readonly, too
Harald Hoyer c4a5a0
+                _opts="${_opts:+${_opts},}ro"
Harald Hoyer c4a5a0
+            fi
Harald Hoyer c4a5a0
             echo "$_dev ${NEWROOT}${_mp} $_fs ${_opts} $_freq $_passno"
Harald Hoyer c4a5a0
             _usr_found="1"
Harald Hoyer c4a5a0
             break
Harald Hoyer c4a5a0
diff --git a/modules.d/99base/parse-root-opts.sh b/modules.d/99base/parse-root-opts.sh
Harald Hoyer c4a5a0
index 2f427aa..44dcc09 100755
Harald Hoyer c4a5a0
--- a/modules.d/99base/parse-root-opts.sh
Harald Hoyer c4a5a0
+++ b/modules.d/99base/parse-root-opts.sh
Harald Hoyer c4a5a0
@@ -5,9 +5,11 @@
Harald Hoyer c4a5a0
 root=$(getarg root=)
Harald Hoyer c4a5a0
 
Harald Hoyer c4a5a0
 if rflags="$(getarg rootflags=)"; then
Harald Hoyer c4a5a0
-    getarg rw && rflags="${rflags},rw" || rflags="${rflags},ro"
Harald Hoyer c4a5a0
+    getarg rw && rflags="${rflags},rw"
Harald Hoyer c4a5a0
+    getarg ro && rflags="${rflags},ro"
Harald Hoyer c4a5a0
 else
Harald Hoyer c4a5a0
-    getarg rw && rflags=rw || rflags=ro
Harald Hoyer c4a5a0
+    getarg rw && rflags=rw
Harald Hoyer c4a5a0
+    getarg ro && rflags=ro
Harald Hoyer c4a5a0
 fi
Harald Hoyer c4a5a0
 
Harald Hoyer c4a5a0
 fstype="$(getarg rootfstype=)"