mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-18 02:20:59 +03:00
420b44488f
Basenames that remain, in cmd/zed/zed.d/statechange-led.sh: dev=$(basename "$(echo "$therest" | awk '{print $(NF-1)}')") vdev=$(basename "$ZEVENT_VDEV_PATH") I don't wanna interfere with #11988 scripts/zfs-tests.sh: SINGLETESTFILE=$(basename "$SINGLETEST") tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib: ACTUAL=$(basename $dataset) ACTUAL=$(basename $dataset) tests/zfs-tests/tests/functional/cli_user/zpool_iostat/ zpool_iostat_-c_homedir.ksh: typeset USER_SCRIPT=$(basename "$USER_SCRIPT_FULL") tests/zfs-tests/tests/functional/cli_user/zpool_iostat/ zpool_iostat_-c_searchpath.ksh: typeset CMD_1=$(basename "$SCRIPT_1") typeset CMD_2=$(basename "$SCRIPT_2") tests/zfs-tests/tests/functional/cli_user/zpool_status/ zpool_status_-c_homedir.ksh: typeset USER_SCRIPT=$(basename "$USER_SCRIPT_FULL") tests/zfs-tests/tests/functional/cli_user/zpool_status/ zpool_status_-c_searchpath.ksh typeset CMD_1=$(basename "$SCRIPT_1") typeset CMD_2=$(basename "$SCRIPT_2") tests/zfs-tests/tests/functional/migration/migration.cfg: export BNAME=`basename $TESTFILE` tests/zfs-tests/tests/perf/perf.shlib: typeset logbase="$(get_perf_output_dir)/$(basename \ tests/zfs-tests/tests/perf/perf.shlib: typeset logbase="$(get_perf_output_dir)/$(basename \ These are potentially Of Directories, where basename is actually useful Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: John Kennedy <john.kennedy@delphix.com> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #12652
120 lines
3.8 KiB
Bash
Executable File
120 lines
3.8 KiB
Bash
Executable File
#!/bin/sh
|
|
# shellcheck disable=SC2016,SC1004
|
|
|
|
grep -wq debug /proc/cmdline && debug=1
|
|
[ -n "$debug" ] && echo "zfs-generator: starting" >> /dev/kmsg
|
|
|
|
GENERATOR_DIR="$1"
|
|
[ -n "$GENERATOR_DIR" ] || {
|
|
echo "zfs-generator: no generator directory specified, exiting" >> /dev/kmsg
|
|
exit 1
|
|
}
|
|
|
|
[ -f /lib/dracut-lib.sh ] && dracutlib=/lib/dracut-lib.sh
|
|
[ -f /usr/lib/dracut/modules.d/99base/dracut-lib.sh ] && dracutlib=/usr/lib/dracut/modules.d/99base/dracut-lib.sh
|
|
command -v getarg >/dev/null 2>&1 || {
|
|
[ -n "$debug" ] && echo "zfs-generator: loading Dracut library from $dracutlib" >> /dev/kmsg
|
|
. "$dracutlib"
|
|
}
|
|
|
|
. /lib/dracut-zfs-lib.sh
|
|
|
|
[ -z "$root" ] && root=$(getarg root=)
|
|
[ -z "$rootfstype" ] && rootfstype=$(getarg rootfstype=)
|
|
[ -z "$rootflags" ] && rootflags=$(getarg rootflags=)
|
|
|
|
# If root is not ZFS= or zfs: or rootfstype is not zfs
|
|
# then we are not supposed to handle it.
|
|
[ "${root##zfs:}" = "${root}" ] &&
|
|
[ "${root##ZFS=}" = "${root}" ] &&
|
|
[ "$rootfstype" != "zfs" ] &&
|
|
exit 0
|
|
|
|
case ",${rootflags}," in
|
|
*,zfsutil,*) ;;
|
|
,,) rootflags=zfsutil ;;
|
|
*) rootflags="zfsutil,${rootflags}" ;;
|
|
esac
|
|
|
|
if [ "${root}" != "zfs:AUTO" ]; then
|
|
root="${root##zfs:}"
|
|
root="${root##ZFS=}"
|
|
fi
|
|
|
|
[ -n "$debug" ] && echo "zfs-generator: writing extension for sysroot.mount to $GENERATOR_DIR/sysroot.mount.d/zfs-enhancement.conf" >> /dev/kmsg
|
|
|
|
|
|
mkdir -p "$GENERATOR_DIR"/sysroot.mount.d "$GENERATOR_DIR"/initrd-root-fs.target.requires "$GENERATOR_DIR"/dracut-pre-mount.service.d
|
|
{
|
|
echo "[Unit]"
|
|
echo "Before=initrd-root-fs.target"
|
|
echo "After=zfs-import.target"
|
|
echo
|
|
echo "[Mount]"
|
|
if [ "${root}" = "zfs:AUTO" ]; then
|
|
echo "PassEnvironment=BOOTFS"
|
|
echo 'What=${BOOTFS}'
|
|
else
|
|
echo "What=${root}"
|
|
fi
|
|
echo "Type=zfs"
|
|
echo "Options=${rootflags}"
|
|
} > "$GENERATOR_DIR"/sysroot.mount.d/zfs-enhancement.conf
|
|
ln -fs ../sysroot.mount "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount
|
|
|
|
|
|
if [ "${root}" = "zfs:AUTO" ]; then
|
|
{
|
|
echo "[Unit]"
|
|
echo "Before=initrd-root-fs.target"
|
|
echo "After=sysroot.mount"
|
|
echo "DefaultDependencies=no"
|
|
echo
|
|
echo "[Service]"
|
|
echo "Type=oneshot"
|
|
echo "PassEnvironment=BOOTFS"
|
|
echo "ExecStart=/bin/sh -c '" ' \
|
|
. /lib/dracut-zfs-lib.sh; \
|
|
_zfs_nonroot_necessities_cb() { \
|
|
zfs mount | grep -m1 -q "^$1 " && return 0; \
|
|
echo "Mounting $1 on /sysroot$2"; \
|
|
mount -o zfsutil -t zfs "$1" "/sysroot$2"; \
|
|
}; \
|
|
for_relevant_root_children "${BOOTFS}" _zfs_nonroot_necessities_cb;' \
|
|
"'"
|
|
} > "$GENERATOR_DIR"/zfs-nonroot-necessities.service
|
|
ln -fs ../zfs-nonroot-necessities.service "$GENERATOR_DIR"/initrd-root-fs.target.requires/zfs-nonroot-necessities.service
|
|
else
|
|
# We can solve this statically at generation time, so do!
|
|
_zfs_generator_cb() {
|
|
dset="${1}"
|
|
mpnt="${2}"
|
|
unit="sysroot$(echo "$mpnt" | tr '/' '-').mount"
|
|
|
|
{
|
|
echo "[Unit]"
|
|
echo "Before=initrd-root-fs.target"
|
|
echo "After=sysroot.mount"
|
|
echo
|
|
echo "[Mount]"
|
|
echo "Where=/sysroot${mpnt}"
|
|
echo "What=${dset}"
|
|
echo "Type=zfs"
|
|
echo "Options=zfsutil"
|
|
} > "$GENERATOR_DIR/${unit}"
|
|
ln -fs ../"${unit}" "$GENERATOR_DIR"/initrd-root-fs.target.requires/"${unit}"
|
|
}
|
|
|
|
for_relevant_root_children "${root}" _zfs_generator_cb
|
|
fi
|
|
|
|
|
|
{
|
|
echo "[Unit]"
|
|
echo "After=zfs-import.target"
|
|
} > "$GENERATOR_DIR"/dracut-pre-mount.service.d/zfs-enhancement.conf
|
|
|
|
[ -n "$debug" ] && echo "zfs-generator: finished" >> /dev/kmsg
|
|
|
|
exit 0
|