Bug#848181: initramfs-tools-core: support mounting of more complex setups
Package: initramfs-tools-core
Version: 0.125
Severity: wishlist
Tags: patch
Hi,
I have the following antries in /etc/fstab:
/dev/mapper/tobias4-home /home ext3 defaults 0 2
/home/usr /usr none bind 0 0
Currently /usr is not mounted automatically. However, with the attached patches
the mountfs function is able mount everything read-only. Tested manually with
the “kernel parameter” break=bottom.
Currently this script mounts only /usr, but not /usr/lib (if necessary) but
this can be easily added.
-- System Information:
Debian Release: stretch/sid
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386, mingw64-amd64, mingw64-i386
Kernel: Linux 4.8.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=de_DE.utf8, LC_CTYPE=de_DE.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
Versions of packages initramfs-tools-core depends on:
ii cpio 2.11+dfsg-6
ii klibc-utils 2.0.4-9
ii kmod 23-1
ii udev 232-7
Versions of packages initramfs-tools-core recommends:
ii busybox 1:1.22.0-19
Versions of packages initramfs-tools-core suggests:
ii bash-completion 1:2.1-4.3
-- Configuration Files:
/etc/initramfs-tools/initramfs.conf changed:
MODULES=most
BUSYBOX=y
KEYMAP=n
COMPRESS=gzip
DEVICE=
NFSROOT=auto
-- no debconf information
--- functions 2016-12-14 20:32:54.256138631 +0100
+++ functions.ts 2016-12-14 22:29:53.295389926 +0100
@@ -420,6 +420,55 @@
done
}
+# mount a directory in a subshell
+# this won't clobber the local variables
+# $1 mount point
+submountfs()
+{
+ echo submountfs "$*"
+ (
+ . ${rootmnt}/root/functions.ts
+ . ${rootmnt}/root/local.ts
+ mountfs "$1"
+ )
+}
+
+
+# find mountpoints for complicated setups.
+# this function tries to guess the mount point for directory
+# and recursively mounts the necessary super-dirs.
+# $1 mount point
+mountmount()
+{
+ echo mountmount "$*"
+ target="$1"
+ if [ -s "${target}" ]
+ then
+ newmount="$(readlink "${rootfs}${target}")"
+ else
+ newmount="${target}"
+ fi
+ for file in ${rootmnt}/etc/fstab; do
+ if [ -f "${file}" ]; then
+ while read fs dir garbage; do
+ case "${fs}" in
+ ""|\#*)
+ continue;
+ ;;
+ esac
+ echo "checking ${newmount} in ${dir}"
+ case "${newmount}" in
+ ${dir}/*)
+ mounting "${dir}"
+ submountfs "${dir}"
+ ;;
+ esac
+ done < "${file}"
+ fi
+ done
+}
+
+
# Mount a file system. We parse the information from the fstab. This
# should be overridden by any boot script which can mount arbitrary
# filesystems such as /usr. This default implementation delegates to
@@ -429,9 +478,21 @@
{
type=local
read_fstab_entry "$1"
- if [ "${MNT_TYPE}" = "nfs" ] || [ "${MNT_TYPE}" = "nfs4" ]; then
+ echo "got fstab entry ${MNT_FSNAME} ${MNT_DIR} ${MNT_TYPE} ${MNT_OPTS}"
+ case "${MNT_TYPE}" in
+ nfs|nfs4)
+# if [ "${MNT_TYPE}" = "nfs" ] || [ "${MNT_TYPE}" = "nfs4" ]; then
type=nfs
- fi
+# fi
+ ;;
+ none)
+ mountmount "${MNT_FSNAME}"
+ MNT_FSNAME="${rootmnt}${MNT_FSNAME}"
+ mountmount "${MNT_DIR}"
+ ;;
+ "")
+ mountmount "$1"
+ esac
${type}_mount_fs "$1"
}
--- local 2016-12-14 20:32:41.156138419 +0100
+++ local.ts 2016-12-14 22:24:23.683384595 +0100
@@ -163,7 +163,12 @@
fi
# FIXME This has no error checking
- modprobe "${MNT_TYPE}"
+ if [ "${MNT_TYPE}" = "none" ]
+ then
+ MNT_FSNAME="${rootmnt}${MNT_FSNAME}"
+ else
+ modprobe "${MNT_TYPE}"
+ fi
if [ "$MNT_PASS" != 0 ]; then
checkfs "$MNT_FSNAME" "$MNT_DIR" "${MNT_TYPE}"
Reply to: