99base/init, 98usrmount: mount /usr if found in /sysroot/etc/fstab
authorHarald Hoyer <harald@redhat.com>
Mon, 7 Nov 2011 07:52:03 +0000 (08:52 +0100)
committerHarald Hoyer <harald@redhat.com>
Tue, 15 Nov 2011 08:47:17 +0000 (09:47 +0100)
We cannot boot correctly without /usr, because of
http://www.freedesktop.org/wiki/Software/systemd/separate-usr-is-broken
so, we mount /usr readonly.

dracut.spec
modules.d/98usrmount/module-setup.sh [new file with mode: 0755]
modules.d/98usrmount/mount-usr.sh [new file with mode: 0755]
modules.d/99base/init

index eaa39a0..43f0900 100644 (file)
@@ -257,6 +257,7 @@ rm -rf $RPM_BUILD_ROOT
 %{_datadir}/dracut/modules.d/98integrity
 %{_datadir}/dracut/modules.d/98selinux
 %{_datadir}/dracut/modules.d/98syslog
+%{_datadir}/dracut/modules.d/98usrmount
 %{_datadir}/dracut/modules.d/99base
 %{_datadir}/dracut/modules.d/99fs-lib
 %{_datadir}/dracut/modules.d/99shutdown
diff --git a/modules.d/98usrmount/module-setup.sh b/modules.d/98usrmount/module-setup.sh
new file mode 100755 (executable)
index 0000000..8f7be10
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+
+check() {
+    return 0
+}
+
+depends() {
+    return 0
+}
+
+install() {
+    inst_hook pre-pivot 50 "$moddir/mount-usr.sh"
+}
+
diff --git a/modules.d/98usrmount/mount-usr.sh b/modules.d/98usrmount/mount-usr.sh
new file mode 100755 (executable)
index 0000000..78bfbbc
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/sh
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+
+type info >/dev/null 2>&1 || . /lib/dracut-lib.sh
+type fsck_single >/dev/null 2>&1 || . /lib/fs-lib.sh
+
+mount_usr()
+{
+    local _dev _mp _fs _opts _rest _usr_found _ret
+    # check, if we have to mount the /usr filesystem
+    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
+        # we have to mount /usr
+        fsck_single "$_dev" "$_fs" "$_opts"
+        _ret=$?
+        echo $_ret >/run/initramfs/usr-fsck
+        if [ $_ret -ne 255 ]; then
+            info "Mounting /usr"
+            mount "$NEWROOT/usr" 2>&1 | vinfo
+        fi
+    fi
+}
+
+mount_usr
\ No newline at end of file
index 36b2152..a8fd1f6 100755 (executable)
@@ -314,33 +314,12 @@ done
 getarg 'rd.break=pre-pivot' 'rdbreak=pre-pivot' && emergency_shell -n pre-pivot "Break pre-pivot"
 source_hook pre-pivot
 
-# by the time we get here, the root filesystem should be mounted.
-# Try to find init and mount /usr, if needed to access init.
-unset __usr_found
+# By the time we get here, the root filesystem should be mounted.
+# Try to find init. 
 for i in "$(getarg real_init=)" "$(getarg init=)" /sbin/init /etc/init /init /bin/sh; do
     [ -n "$i" ] || continue
 
-    __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")
+    __p=$(readlink -f "${NEWROOT}/${i}")
     if [ -x "$__p" ]; then
         INIT="$i"
         break