99base/init: try to mount /usr, if init lives on /usr
authorHarald Hoyer <harald@redhat.com>
Fri, 22 Jul 2011 09:21:24 +0000 (11:21 +0200)
committerHarald Hoyer <harald@redhat.com>
Fri, 22 Jul 2011 13:17:00 +0000 (15:17 +0200)
TODO
modules.d/99base/init
modules.d/99base/module-setup.sh

diff --git a/TODO b/TODO
index 7dcf8dc..e5abef0 100644 (file)
--- a/TODO
+++ b/TODO
@@ -4,6 +4,7 @@ INITRAMFS TODO
 - The hard-coded list of udev rules that we care about is kind of lame.
 - automatic kexec fallback
 - panic fallback
+- fsck for $NEWROOT/usr
 
 GENERATOR TODO
 
index 5975b25..1fac580 100755 (executable)
@@ -306,10 +306,33 @@ getarg 'rd.break=pre-pivot' 'rdbreak=pre-pivot' && emergency_shell -n pre-pivot
 source_hook pre-pivot
 
 # by the time we get here, the root filesystem should be mounted.
-# Try to find init.
+# Try to find init and mount /usr, if needed to access init.
+unset __usr_found
 for i in "$(getarg real_init=)" "$(getarg init=)" /sbin/init /etc/init /init /bin/sh; do
     [ -n "$i" ] || continue
-    if ! [ -d "$NEWROOT$i" ] && [ -L "$NEWROOT$i" -o -x "$NEWROOT$i" ]; then
+
+    __p=$(readlink -m "$NEWROOT$i")
+    if [ -n "$__p" ] \
+        && [ "x$__usr_found" = "x" ] \
+        && [ ! -x "$__p" ] \
+        && strstr "$__p" "$NEWROOT/usr" \
+        ; then
+        # we have to mount /usr
+        while read dev mp fs opts rest; do
+            if [ "$mp" = "/usr" ]; then
+                echo "$dev $NEWROOT$mp $fs ${opts},ro $rest"
+                __usr_found="1"
+                break
+            fi
+        done < "$NEWROOT/etc/fstab" >> /etc/fstab
+        if [ "x$__usr_found" != "x" ]; then
+            info "Mounting /usr"
+            mount "$NEWROOT/usr" 2>&1 | vinfo
+        fi
+    fi
+
+    __p=$(readlink -f "$NEWROOT$i")
+    if [ -x "$__p" ]; then
         INIT="$i"
         break
     fi
index 20454f9..40c94f6 100755 (executable)
@@ -14,7 +14,7 @@ depends() {
 install() {
     local _d
     dracut_install mount mknod mkdir modprobe pidof sleep chroot \
-        sed ls flock cp mv dmesg rm ln rmmod mkfifo umount
+        sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink
     dracut_install -o less
     if [ ! -e "${initdir}/bin/sh" ]; then
         dracut_install bash