# Distributed under the GPL v2
# $Id$
+ 09 Feb 2012; Robin H. Johnson <robbat2@gentoo.org> defaults/initrd.scripts,
+ defaults/linuxrc:
+ Dogfooding of the /usr mount code with the matching OpenRC change to make the
+ mounts RW revealed some bugs and gotchas in our prior code, now fixed and
+ verified to work.
+
06 Feb 2012; Robin H. Johnson <robbat2@gentoo.org> arch/alpha/config.sh,
arch/arm/config.sh, arch/ia64/config.sh, arch/mips/config.sh,
arch/parisc/config.sh, arch/parisc64/config.sh, arch/ppc/config.sh,
' ${NEW_ROOT}/etc/initramfs.mounts
}
-get_mount_options()
+get_mount_fstype()
{
awk -v fs="$1" '
/^[[:blank:]]*#/ { next }
' ${NEW_ROOT}/etc/fstab
}
+get_mount_options()
+{
+ awk -v fs="$1" '
+ /^[[:blank:]]*#/ { next }
+ $2 == fs { print $4 }
+ ' ${NEW_ROOT}/etc/fstab
+}
+
get_mount_device()
{
awk -v fs="$1" '
' ${NEW_ROOT}/etc/fstab
}
+# If the kernel is handed a mount option is does not recognize, it WILL fail to
+# mount. util-linux handles auto/noauto, but busybox passes it straight to the kernel
+# which then rejects the mount.
+# To make like a little easier, busybox mount does not care about leading,
+# trailing or duplicate commas.
+strip_mount_options()
+{
+ sed -r 's/(,|^)(no)?auto(,|$)/,/g'
+}
# there is no isofs filesystem to worry about
break
else
- good_msg "Mounting root..."
+ good_msg "Mounting $REAL_ROOT as root..."
if [ "${ROOTFSTYPE}" = 'zfs' ]
then
# In this case, it's probably part of the filesystem
# and not a mountpoint
[ -z "$dev" ] && continue
- opts="ro,$(get_mount_options \"$fs\")"
- if ! mount -o ${opts} $dev ${NEW_ROOT}${fs}; then
- rescue_shell "Unable to mount $dev on $fs"
+ fstype=$(get_mount_fstype $fs)
+ # ro must be trailing, and the options will always contain at least 'defaults'
+ opts="$(get_mount_options $fs | strip_mount_options),ro"
+ mnt=${NEW_ROOT}${fs}
+ cmd="mount -t $fstype -o $opts $dev $mnt"
+ good_msg "Mounting $dev as ${fs}: $cmd"
+ if ! $cmd; then
+ bad_msg "Unable to mount $dev for $fs"
fi
done