On Sun, Dec 18, 2011 at 03:38:20AM +0100, Marco d'Itri wrote: > On Dec 17, Roger Leigh <rle...@debian.org> wrote: > > > 1) Generation of /etc/fstab in the initramfs, including the rootfs > > and all the filesystems desired to be mounted > This is highly suboptimal, because it suddenly makes the initramfs not > generic anymore. > The initramfs should: > - mount / as usual > - look at the rootfs fstab > - mount /usr using the information from the rootfs fstab
The attached patch does this. Note that the patch isn't complete; it won't mount an LVM VG because it lacks the LV activation performed for the root in "scripts/local-top/lvm2". I haven't included this in the patch because I'm not sure of the best approach to take here. Maybe it would make sense to make the existing scripts a bit more generic, to permit setup of devices other than $ROOT? Maybe if the scripts were idempotent, they could be invoked multiple times (once per device)? I didn't want to do this without discussing it with you, so hope the patch is useful as a basis for a complete solution. Regarding mounting of /etc; I think this would be useful in a number of uncommon situations. I'll look at (separately) implementing an --etc/etc= option similar to the existing root options which would permit this to work, and keep the initramfs generic at the same time. As for /usr above, having the ability to generically activate devices other than $ROOT would also be useful here. Regards, Roger -- .''`. Roger Leigh : :' : Debian GNU/Linux http://people.debian.org/~rleigh/ `. `' Printing on GNU/Linux? http://gutenprint.sourceforge.net/ `- GPG Public Key: 0x25BFB848 Please GPG sign your mail.
>From 02574bd223ac21ad18e5c4fa801766e7eaa7c00a Mon Sep 17 00:00:00 2001 From: Roger Leigh <Roger Leigh rle...@debian.org> Date: Sat, 17 Dec 2011 11:47:59 +0000 Subject: [PATCH] scripts/local: Add parse_initramfs_fstab function and mount /usr This parses /etc/fstab and /etc/fstab.d/*.fstab on the rootfs, in order to obtain the mount information for /usr (if available). If an entry for /usr exists, mount /usr immediately after mounting the rootfs. --- scripts/local | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 51 insertions(+), 0 deletions(-) diff --git a/scripts/local b/scripts/local index 521e69a..fc70c02 100644 --- a/scripts/local +++ b/scripts/local @@ -1,5 +1,54 @@ # Local filesystem mounting -*- shell-script -*- +# Find a specific fstab entry from the mounted rootfs +# $1=mountpoint +# $2=fstype (optional) +# returns 0 on success, 1 on failure (not found or no fstab) +parse_initramfs_fstab () { + local found + found=1 + for file in ${rootmnt}/etc/fstab ${rootmnt}/etc/fstab.d/*.fstab; do + if [ -f "${file}" ]; then + while read MNT_FSNAME MNT_DIR MNT_TYPE MNT_OPTS MNT_FREQ MNT_PASS MNT_JUNK + do + case "${MNT_FSNAME}" in + ""|\#*) + continue;; + esac + + if [ "$MNT_DIR" = "$1" ]; then + if [ -n "$2" ]; then + [ "$MNT_TYPE" = "$2" ] || continue; + fi + found=0; + break 2 + fi + + done < "${file}" + fi + done + return $found +} + +# /usr mounting +mountusr() +{ + if parse_initramfs_fstab /usr; then + if [ "${readonly}" = "y" ]; then + roflag=-r + else + roflag=-w + fi + + # FIXME This has no error checking + modprobe ${MNT_TYPE} + + # FIXME This has no error checking + # Mount /usr + mount ${roflag} -t "${MNT_TYPE}" -o "${MNT_OPTS}" "${MNT_FSNAME}" "${rootmnt}${MNT_DIR}" + fi +} + pre_mountroot() { [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-top" @@ -106,6 +155,8 @@ mountroot() mount ${roflag} ${ROOTFLAGS} ${ROOT} ${rootmnt} fi + mountusr + [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom" run_scripts /scripts/local-bottom [ "$quiet" != "y" ] && log_end_msg -- 1.7.7.3