Blame 0020-99base-init-try-to-mount-usr-if-init-lives-on-usr.patch

Harald Hoyer 428fde
From 40ee8c1814510bc95ab0d5dffd17af28c14df182 Mon Sep 17 00:00:00 2001
Harald Hoyer 428fde
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 428fde
Date: Fri, 22 Jul 2011 11:21:24 +0200
Harald Hoyer 428fde
Subject: [PATCH] 99base/init: try to mount /usr, if init lives on /usr
Harald Hoyer 428fde
Harald Hoyer 428fde
---
Harald Hoyer 428fde
 TODO                             |    1 +
Harald Hoyer 428fde
 modules.d/99base/init            |   27 +++++++++++++++++++++++++--
Harald Hoyer 428fde
 modules.d/99base/module-setup.sh |    2 +-
Harald Hoyer 428fde
 3 files changed, 27 insertions(+), 3 deletions(-)
Harald Hoyer 428fde
Harald Hoyer 428fde
diff --git a/TODO b/TODO
Harald Hoyer 428fde
index 7dcf8dc..e5abef0 100644
Harald Hoyer 428fde
--- a/TODO
Harald Hoyer 428fde
+++ b/TODO
Harald Hoyer 428fde
@@ -4,6 +4,7 @@ INITRAMFS TODO
Harald Hoyer 428fde
 - The hard-coded list of udev rules that we care about is kind of lame.
Harald Hoyer 428fde
 - automatic kexec fallback
Harald Hoyer 428fde
 - panic fallback
Harald Hoyer 428fde
+- fsck for $NEWROOT/usr
Harald Hoyer 428fde
 
Harald Hoyer 428fde
 GENERATOR TODO
Harald Hoyer 428fde
 
Harald Hoyer 428fde
diff --git a/modules.d/99base/init b/modules.d/99base/init
Harald Hoyer 428fde
index 5975b25..1fac580 100755
Harald Hoyer 428fde
--- a/modules.d/99base/init
Harald Hoyer 428fde
+++ b/modules.d/99base/init
Harald Hoyer 428fde
@@ -306,10 +306,33 @@ getarg 'rd.break=pre-pivot' 'rdbreak=pre-pivot' && emergency_shell -n pre-pivot
Harald Hoyer 428fde
 source_hook pre-pivot
Harald Hoyer 428fde
 
Harald Hoyer 428fde
 # by the time we get here, the root filesystem should be mounted.
Harald Hoyer 428fde
-# Try to find init.
Harald Hoyer 428fde
+# Try to find init and mount /usr, if needed to access init.
Harald Hoyer 428fde
+unset __usr_found
Harald Hoyer 428fde
 for i in "$(getarg real_init=)" "$(getarg init=)" /sbin/init /etc/init /init /bin/sh; do
Harald Hoyer 428fde
     [ -n "$i" ] || continue
Harald Hoyer 428fde
-    if ! [ -d "$NEWROOT$i" ] && [ -L "$NEWROOT$i" -o -x "$NEWROOT$i" ]; then
Harald Hoyer 428fde
+
Harald Hoyer 428fde
+    __p=$(readlink -m "$NEWROOT$i")
Harald Hoyer 428fde
+    if [ -n "$__p" ] \
Harald Hoyer 428fde
+        && [ "x$__usr_found" = "x" ] \
Harald Hoyer 428fde
+        && [ ! -x "$__p" ] \
Harald Hoyer 428fde
+        && strstr "$__p" "$NEWROOT/usr" \
Harald Hoyer 428fde
+        ; then
Harald Hoyer 428fde
+        # we have to mount /usr
Harald Hoyer 428fde
+        while read dev mp fs opts rest; do
Harald Hoyer 428fde
+            if [ "$mp" = "/usr" ]; then
Harald Hoyer 428fde
+                echo "$dev $NEWROOT$mp $fs ${opts},ro $rest"
Harald Hoyer 428fde
+                __usr_found="1"
Harald Hoyer 428fde
+                break
Harald Hoyer 428fde
+            fi
Harald Hoyer 428fde
+        done < "$NEWROOT/etc/fstab" >> /etc/fstab
Harald Hoyer 428fde
+        if [ "x$__usr_found" != "x" ]; then
Harald Hoyer 428fde
+            info "Mounting /usr"
Harald Hoyer 428fde
+            mount "$NEWROOT/usr" 2>&1 | vinfo
Harald Hoyer 428fde
+        fi
Harald Hoyer 428fde
+    fi
Harald Hoyer 428fde
+
Harald Hoyer 428fde
+    __p=$(readlink -f "$NEWROOT$i")
Harald Hoyer 428fde
+    if [ -x "$__p" ]; then
Harald Hoyer 428fde
         INIT="$i"
Harald Hoyer 428fde
         break
Harald Hoyer 428fde
     fi
Harald Hoyer 428fde
diff --git a/modules.d/99base/module-setup.sh b/modules.d/99base/module-setup.sh
Harald Hoyer 428fde
index 20454f9..40c94f6 100755
Harald Hoyer 428fde
--- a/modules.d/99base/module-setup.sh
Harald Hoyer 428fde
+++ b/modules.d/99base/module-setup.sh
Harald Hoyer 428fde
@@ -14,7 +14,7 @@ depends() {
Harald Hoyer 428fde
 install() {
Harald Hoyer 428fde
     local _d
Harald Hoyer 428fde
     dracut_install mount mknod mkdir modprobe pidof sleep chroot \
Harald Hoyer 428fde
-        sed ls flock cp mv dmesg rm ln rmmod mkfifo umount
Harald Hoyer 428fde
+        sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink
Harald Hoyer 428fde
     dracut_install -o less
Harald Hoyer 428fde
     if [ ! -e "${initdir}/bin/sh" ]; then
Harald Hoyer 428fde
         dracut_install bash