From 470ee2d2149cc0622e7e0688cae3f7d11e0a0837 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Mon, 7 Nov 2011 08:52:03 +0100 Subject: [PATCH] 99base/init, 98usrmount: mount /usr if found in /sysroot/etc/fstab 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 | 1 + modules.d/98usrmount/module-setup.sh | 16 ++++++++++++++ modules.d/98usrmount/mount-usr.sh | 32 ++++++++++++++++++++++++++++ modules.d/99base/init | 27 +++-------------------- 4 files changed, 52 insertions(+), 24 deletions(-) create mode 100755 modules.d/98usrmount/module-setup.sh create mode 100755 modules.d/98usrmount/mount-usr.sh diff --git a/dracut.spec b/dracut.spec index eaa39a0e..43f09006 100644 --- a/dracut.spec +++ b/dracut.spec @@ -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 index 00000000..8f7be10d --- /dev/null +++ b/modules.d/98usrmount/module-setup.sh @@ -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 index 00000000..78bfbbc6 --- /dev/null +++ b/modules.d/98usrmount/mount-usr.sh @@ -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 diff --git a/modules.d/99base/init b/modules.d/99base/init index 36b21528..a8fd1f6f 100755 --- a/modules.d/99base/init +++ b/modules.d/99base/init @@ -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