Create generic mount framework
PATCH 1/2 Create generic mount framework
* Utilises fstab.{early,late} files in /etc
* Provides fs_add_mount function to mount in pre-mount (early) and pre-pivot (late) phases
* Code to mount a fstab file is moved over from 95fstab-sys
--- modules.d/95fstab-sys/mount-sys.sh | 22 --------------------- modules.d/99fs-lib/fs-lib.sh | 39 ++++++++++++++++++++++++++++++++++++++ modules.d/99fs-lib/module-setup.sh | 3 +++ modules.d/99fs-lib/mount-early.sh | 8 ++++++++ modules.d/99fs-lib/mount-late.sh | 8 ++++++++ 5 files changed, 58 insertions(+), 22 deletions(-) create mode 100755 modules.d/99fs-lib/mount-early.sh create mode 100755 modules.d/99fs-lib/mount-late.sh
modules.d/95fstab-sys/mount-sys.sh +0 -22
@@ -5,28 +5,6 @@ type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type det_fs >/dev/null 2>&1 || . /lib/fs-lib.sh -fstab_mount() { - local _dev _mp _fs _opts _dump _pass _rest - test -e "$1" || return 1 - info "Mounting from $1" - while read _dev _mp _fs _opts _dump _pass _rest; do - [ -z "${_dev%%#*}" ] && continue # Skip comment lines - ismounted $_mp && continue # Skip mounted filesystem - if [ "$_pass" -gt 0 ] && ! strstr "$_opts" _netdev; then - fsck_single "$_dev" "$_fs" "$_opts" - fi - _fs=$(det_fs "$_dev" "$_fs") - info "Mounting $_dev" - if [ -d "$NEWROOT/$_mp" ]; then - mount -v -t $_fs -o $_opts $_dev "$NEWROOT/$_mp" 2>&1 | vinfo - else - [ -d "$_mp" ] || mkdir -p "$_mp" - mount -v -t $_fs -o $_opts $_dev $_mp 2>&1 | vinfo - fi - done < $1 - return 0 -} - [ -f /etc/fstab ] && fstab_mount /etc/fstab # prefer $NEWROOT/etc/fstab.sys over local /etc/fstab.sys
modules.d/99fs-lib/fs-lib.sh +39 -0
@@ -248,3 +248,42 @@ write_fs_tab() { systemctl --no-block start initrd-root-fs.target fi } + +# fstab_mount FSTAB +# go through FSTAB and mount each line +# cannot be used to mount rootfs for 40network, because it will not create /dev/root +fstab_mount() { + local _dev _mp _fs _opts _dump _pass _rest + test -e "$1" || return 1 + info "Mounting from $1" + while read _dev _mp _fs _opts _dump _pass _rest; do + [ -z "${_dev%%#*}" ] && continue # Skip comment lines + ismounted $_mp && continue # Skip mounted filesystem + if [ "$_pass" -gt 0 ] && ! strstr "$_opts" _netdev; then + fsck_single "$_dev" "$_fs" "$_opts" + fi + _fs=$(det_fs "$_dev" "$_fs") + info "Mounting $_dev" + if [ -d "$NEWROOT/$_mp" ]; then + mount -v -t $_fs -o $_opts $_dev "$NEWROOT/$_mp" 2>&1 | vinfo + else + [ -d "$_mp" ] || mkdir -p "$_mp" + mount -v -t $_fs -o $_opts $_dev $_mp 2>&1 | vinfo + fi + done < $1 + return 0 +} + +# fs_add_mount PHASE FS MOUNTPOINT FSTYPE OPTIONS DUMP PASS +# add line to fstab used by pre-mount (PHASE=early) or pre-pivot (PHASE=late) hook +# FS is anything that could be found in the first column of fstab +fs_add_mount() { + local phase="$1" fs="$2" mountpoint="$3" fstype="$4" options="$5" dump="$6" pass="$7" + [ "${fs}" ] || die "FS passed to $0 is empty" + [ "${mountpoint}" ] || die "Mountpoint passed to $0 is empty" + [ "${fstype}" ] || fstype=auto + [ "${options}" ] || options=defaults + [ "${dump}" ] || dump=0 + [ "${pass}" ] || pass=0 + echo "${fs} ${mountpoint} ${fstype} ${options} ${dump} ${pass}" >> /etc/fstab."${phase}" +}
modules.d/99fs-lib/module-setup.sh +3 -0
@@ -60,6 +60,9 @@ install() { inst "$moddir/fs-lib.sh" "/lib/fs-lib.sh" > ${initdir}/etc/fstab.empty + inst_hook pre-mount 99 "$moddir/mount-early.sh" + inst_hook pre-pivot 99 "$moddir/mount-late.sh" + [[ "$nofscks" = "yes" ]] && return if [[ "$fscks" = "${fscks#*[^ ]*}" ]]; then
modules.d/99fs-lib/mount-early.sh new file +8 -0
@@ -0,0 +1,8 @@ +#!/bin/sh +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh + +type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh +type det_fs >/dev/null 2>&1 || . /lib/fs-lib.sh + +[ -f /etc/fstab.early ] && fstab_mount /etc/fstab.early
modules.d/99fs-lib/mount-late.sh new file +8 -0
@@ -0,0 +1,8 @@ +#!/bin/sh +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh + +type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh +type det_fs >/dev/null 2>&1 || . /lib/fs-lib.sh + +[ -f /etc/fstab.late ] && fstab_mount /etc/fstab.late
Signature · 1 line
1.8.1.5
A message that is not in the archive (sent off-list or not yet received): 1365694762-7806-1-git-send-email-devurandom-hi6Y0CQ0nG0@public.gmane.org
PATCH 1/2 Add variable parsing framework for network related variables
* Provides net_add_parse_vars function to install net_parse_vars hook when an interface comes online
* Provides net_parse_vars function to search and replace network related variables in a string
--- modules.d/40network/net-lib.sh | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
modules.d/40network/net-lib.sh +56 -0
@@ -366,3 +366,59 @@ linkup() { && wait_for_if_up $1 2>/dev/null } +# net_parse_vars STRING IFUP +# parse vars in STRING +# IFUP may contain the interface that came online, triggering this hook +net_parse_vars() { + local cur="$1" ifup="$2" var val iface + + var="${cur#*%\{}" + var="${var%%\}*}" + + while [ "${var}" != "${cur}" ] ; do + case "${var}" in + mac.*) + iface="${var##mac.}" + [ "${ifup}" = "${iface}" ] || exit + val="$(ip link show dev "${iface}" | sed -nre '/ether/s/^.*ether ([0-9a-f:]*) .*$/\1/' -e 's/://')" + ;; + hostname) + val="$(hostname)" + [ "${val}" = '(none)' ] && die 'No hostname (yet)' + ;; + *) + die "Unsupported cmdline variable '${var}'" + ;; + esac + + cur="$(echo "${cur}" | sed "s/%{${var}}/${val}/")" + unset val + + var="${cur#*%\{}" + var="${var%%\}*}" + done + + echo "${cur}" +} + +# net_add_parse_vars STRING LIB FUNCTION +# add initqueue/online hook to parse vars in STRING +# execute FUNCTION from LIB afterwards +net_add_parse_vars() { + local string="$1" lib="$2" func="$3" jobid="$(cat /proc/sys/kernel/random/uuid)" + + cat <<- EOF > "${hookdir}"/initqueue/online/40network.parse."${jobid}".sh + . /lib/"${lib}".sh + + string="\$(net_parse_vars "${string}" "\$@")" + ${func} "\${string}" + unset string + + > /tmp/40network.parse.finished."${jobid}" + EOF + + cat <<- EOF > "${hookdir}"/initqueue/finished/40network.parse.wait."${jobid}".sh + echo "Waiting for nfs_parse_vars (${jobid}) to complete ..." + [ -f /tmp/40network.parse.finished."${jobid}" ] + EOF +}
Signature · 1 line
1.8.2.1
A message that is not in the archive (sent off-list or not yet received): 1368807440-9207-1-git-send-email-devurandom-hi6Y0CQ0nG0@public.gmane.org
PATCH 2/2 Provide a hostname fallback function, in case there is no executable of this name
--- modules.d/40network/net-lib.sh | 5 +++++ 1 file changed, 5 insertions(+)
modules.d/40network/net-lib.sh +5 -0
@@ -422,3 +422,8 @@ net_add_parse_vars() { [ -f /tmp/40network.parse.finished."${jobid}" ] EOF } + +type hostname >/dev/null 2>&1 || \ +hostname() { + cat /proc/sys/kernel/hostname +}
Signature · 1 line
1.8.2.1
Re: [PATCH 1/2] [40network] Add variable parsing framework for network related variables
In reply to a message not in the archiveOups, sorry, these emails should have been referring to
Message-Id: <1365694853-7881-1-git-send-email-devurandom-hi6Y0CQ0nG0@public.gmane.org>
I will not resend them with the proper In-Reply-To in the hopes that this is not especially important and they will be considered for merging anyway.
Best regards,
Dennis
Am 11.04.2013 17:39, schrieb Dennis Schridde:
Quoted 4 lines
* Utilises fstab.{early,late} files in /etc
* Providesfs_add_mountfunction to mount in pre-mount (early) and pre-pivot (late) phases
* Code to mount a fstab file is moved over from 95fstab-sys
---
Why not make use of fstab and fstab of the real root?
/etc/fstab in the initramfs == fstab.early
$NEWROOT/etc/fstab == fstab.late
??
In systemd we introduced "x-initrd.mount" as a mount option, to mark those mount entries from $NEWROOT/etc/fstab to be mounted in pre-pivot.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Am Donnerstag, 11. April 2013, 17:48:16 schrieb Harald Hoyer:
Quoted 11 lines
Am 11.04.2013 17:39, schrieb Dennis Schridde:
Quoted 5 lines
* Utilises fstab.{early,late} files in /etc
* Providesfs_add_mountfunction to mount in pre-mount (early) and pre-pivot (late) phases * Code to mount a fstab file is moved over from 95fstab-sys
---Why not make use of fstab and fstab of the real root?
/etc/fstabin the initramfs == fstab.early
$NEWROOT/etc/fstab == fstab.late
I want to mount depending on the cmdline arguments of the kernel.
Basically, what I need is a way to guarantee certain devices/directories to be mounted before dracut tries to mount the rootfs.
Also, the mountpoints are inside the initramfs, not inside the rootfs. So having them in the rootfs' fstab (when the mountpoints do not exist there), seems wrong.
For testing it was extremely helpful that I could provide these devices on the cmdline, because the initramfs takes quite a while to build on my machines, so replacing a file inside them each time I tried to get the path right would have been cumbersome.
Quoted 2 lines
In systemd we introduced "x-initrd.mount" as a mount option, to mark those mount entries from $NEWROOT/etc/fstab to be mounted in pre-pivot.
I assume there is nothing (yet) that mounts entries before the rootfs gets mounted?
--Dennis
Hello!
These 99fs-lib patches are still needed by my aufs/nfs extensions that are about to be submitted once any issues with these patches are resolved.
Are there any issues with these patches? Can someone please merge them?
--Dennis
PATCH 2/2 Provide fs_mount_to_var utility function to parse /path:type:/dev,options style mountspecs
In reply to a message not in the archive--- modules.d/99fs-lib/fs-lib.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
modules.d/99fs-lib/fs-lib.sh +26 -0
@@ -287,3 +287,29 @@ fs_add_mount() { [ "${pass}" ] || pass=0 echo "${fs} ${mountpoint} ${fstype} ${options} ${dump} ${pass}" >> /etc/fstab."${phase}" } + +# fs_mount_to_var MOUNTSPEC +# use MOUNTSPEC to set $mountpoint, $fstype, $fs and $options. +# MOUNTSPEC is something like: [<mountpoint>]:<fstype>:<fs>[,<options>] +fs_mount_to_var() { + local arg="$1" + + options="${arg#*,}" + [ "${options}" = "${arg}" ] && unset options + arg="${arg%%,${options}}" + + mountpoint="${arg%%:*}" + [ "${mountpoint}" = "${arg}" ] && die "Unable to parse mountpoint out of $1" + arg="${arg##${mountpoint}:}" + + if [ "${mountpoint}" = "${mountpoint#/}" ] ; then + fstype="${mountpoint}" + mountpoint=/ + else + fstype="${arg%%:*}" + [ "${fstype}" = "${arg}" ] && die "Unable to parse fstype out of $1" + arg="${arg##${fstype}:}" + fi + + fs="${arg}" +}
Signature · 1 line
1.8.1.5
A message that is not in the archive (sent off-list or not yet received): 1365694762-7806-2-git-send-email-devurandom-hi6Y0CQ0nG0@public.gmane.org
Re: [PATCH 2/2] [99fs-lib] Provide fs_mount_to_var utility function to parse /path:type:/dev,options style mountspecs
Hello!
I will submit further patches that require these, once these are in a state where they will be accepted.
Please note that you can also have a look at these patches on github:
https://github.com/devurandom/dracut
--Dennis