You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

131 lines
4.7 KiB

From e42ab58a70ae646d09c319c125154e970e25a994 Mon Sep 17 00:00:00 2001
From: Lukas Nykryn <lnykryn@redhat.com>
Date: Thu, 25 Apr 2019 10:11:58 +0200
Subject: [PATCH] rootfs-generator: rebase to upstream version
Resolves: #1640866
---
modules.d/98systemd/rootfs-generator.sh | 87 ++++++++++++++++++++-----
1 file changed, 70 insertions(+), 17 deletions(-)
diff --git a/modules.d/98systemd/rootfs-generator.sh b/modules.d/98systemd/rootfs-generator.sh
index a7bffdfd..4ae693bb 100755
--- a/modules.d/98systemd/rootfs-generator.sh
+++ b/modules.d/98systemd/rootfs-generator.sh
@@ -1,6 +1,4 @@
#!/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
@@ -10,32 +8,81 @@ generator_wait_for_dev()
local _timeout
_name="$(str_replace "$1" '/' '\x2f')"
+ _timeout=$(getarg rd.timeout)
+ _timeout=${_timeout:-0}
- [ -e "$hookdir/initqueue/finished/devexists-${_name}.sh" ] && return 0
+ if ! [ -e "$hookdir/initqueue/finished/devexists-${_name}.sh" ]; then
- printf '[ -e "%s" ]\n' $1 \
- >> "$hookdir/initqueue/finished/devexists-${_name}.sh"
- {
- printf '[ -e "%s" ] || ' $1
- printf 'warn "\"%s\" does not exist"\n' $1
- } >> "$hookdir/emergency/80-${_name}.sh"
+ printf '[ -e "%s" ]\n' $1 \
+ >> "$hookdir/initqueue/finished/devexists-${_name}.sh"
+ {
+ printf '[ -e "%s" ] || ' $1
+ printf 'warn "\"%s\" does not exist"\n' $1
+ } >> "$hookdir/emergency/80-${_name}.sh"
+ fi
_name=$(dev_unit_name "$1")
- if ! [ -L /run/systemd/generator/initrd.target.wants/${_name}.device ]; then
- [ -d /run/systemd/generator/initrd.target.wants ] || mkdir -p /run/systemd/generator/initrd.target.wants
- ln -s ../${_name}.device /run/systemd/generator/initrd.target.wants/${_name}.device
+ if ! [ -L "$GENERATOR_DIR"/initrd.target.wants/${_name}.device ]; then
+ [ -d "$GENERATOR_DIR"/initrd.target.wants ] || mkdir -p "$GENERATOR_DIR"/initrd.target.wants
+ ln -s ../${_name}.device "$GENERATOR_DIR"/initrd.target.wants/${_name}.device
fi
- if ! [ -f /run/systemd/generator/${_name}.device.d/timeout.conf ]; then
- _timeout=$(getarg rd.device.timeout || printf "0")
- mkdir -p /run/systemd/generator/${_name}.device.d
+ if ! [ -f "$GENERATOR_DIR"/${_name}.device.d/timeout.conf ]; then
+ mkdir -p "$GENERATOR_DIR"/${_name}.device.d
{
echo "[Unit]"
echo "JobTimeoutSec=$_timeout"
- } > /run/systemd/generator/${_name}.device.d/timeout.conf
+ echo "JobRunningTimeoutSec=$_timeout"
+ } > "$GENERATOR_DIR"/${_name}.device.d/timeout.conf
+ fi
+}
+
+generator_mount_rootfs()
+{
+ local _type=$2
+ local _flags=$3
+ local _name
+
+ [ -z "$1" ] && return 0
+
+ _name=$(dev_unit_name "$1")
+ [ -d "$GENERATOR_DIR" ] || mkdir -p "$GENERATOR_DIR"
+ if ! [ -f "$GENERATOR_DIR"/sysroot.mount ]; then
+ {
+ echo "[Unit]"
+ echo "Before=initrd-root-fs.target"
+ echo "Requires=systemd-fsck@${_name}.service"
+ echo "After=systemd-fsck@${_name}.service"
+ echo "[Mount]"
+ echo "Where=/sysroot"
+ echo "What=$1"
+ echo "Options=${_flags}"
+ echo "Type=${_type}"
+ } > "$GENERATOR_DIR"/sysroot.mount
+ fi
+ if ! [ -L "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount ]; then
+ [ -d "$GENERATOR_DIR"/initrd-root-fs.target.requires ] || mkdir -p "$GENERATOR_DIR"/initrd-root-fs.target.requires
+ ln -s ../sysroot.mount "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount
fi
}
+generator_fsck_after_pre_mount()
+{
+ local _name
+
+ [ -z "$1" ] && return 0
+
+ _name=$(dev_unit_name "$1")
+ [ -d /run/systemd/generator/systemd-fsck@${_name}.service.d ] || mkdir -p /run/systemd/generator/systemd-fsck@${_name}.service.d
+ if ! [ -f /run/systemd/generator/systemd-fsck@${_name}.service.d/after-pre-mount.conf ]; then
+ {
+ echo "[Unit]"
+ echo "After=dracut-pre-mount.service"
+ } > /run/systemd/generator/systemd-fsck@${_name}.service.d/after-pre-mount.conf
+ fi
+
+}
+
root=$(getarg root=)
case "$root" in
block:LABEL=*|LABEL=*)
@@ -62,6 +109,12 @@ case "$root" in
rootok=1 ;;
esac
-[ "${root%%:*}" = "block" ] && generator_wait_for_dev "${root#block:}"
+GENERATOR_DIR="$1"
+
+if [ "$rootok" = "1" ]; then
+ generator_wait_for_dev "${root#block:}" "$RDRETRY"
+ generator_fsck_after_pre_mount "${root#block:}"
+ strstr "$(cat /proc/cmdline)" 'root=' || generator_mount_rootfs "${root#block:}" "$(getarg rootfstype=)" "$(getarg rootflags=)"
+fi
exit 0