[make-initrd] [PATCH v6 14/22] bootchain-core: extends bootchain-sh-functions API
Leonid Krivoshein
klark.devel at gmail.com
Sun Oct 24 20:22:09 MSK 2021
Signed-off-by: Leonid Krivoshein <klark.devel at gmail.com>
---
features/bootchain-core/README.md | 19 ++++++
.../data/bin/bootchain-sh-functions | 61 +++++++++++++++++++
features/bootchain-core/data/sbin/chaind | 2 +-
3 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/features/bootchain-core/README.md b/features/bootchain-core/README.md
index 14db55f..ffed599 100644
--- a/features/bootchain-core/README.md
+++ b/features/bootchain-core/README.md
@@ -59,6 +59,10 @@ us to optimize fill in `initramfs` only which we are need.
relative addressing it is safe in any case and can often be more convenient.
- Allows you to work with shorter and more familiar paths to special files
devices thanks to the use of `DEVNAME` along with `dev`.
+- Provides the ability to associate the <IN> of a step with the <OUT>
+ of the previous step through symbolic links to mount points inside initramfs,
+ outside the tree the results of the steps, which provides, if necessary, the
+ overlap mounting mechanism inherent in the program `propagator`.
- The daemon can be configured when building initramfs via the included file
configurations of `/etc/sysconfig/bootchain`, and not only through boot
parameters, see the details in the corresponding section.
@@ -134,6 +138,21 @@ own needs.
debugging.
- assign() - assignment of the specified value to a variable that gets into
the log with advanced debugging. The left-hand expression is also computable.
+- next_bootchain() - command to the daemon to change the sequence of the
+ following steps.
+- is_step_passed() - returns 0 if the current step has been passed at
+ least once.
+- launch_step_once() - if the current step has already been completed,
+ it completes the work through the fatal() call.
+- break_bc_loop() - informs the daemon that the current step is the last and
+ after after its successful completion, you can switch to stage2. The script
+ of this step, however, must work to the end and end with a zero status code
+ in order for the daemon to process the received signal.
+- bc_reboot() - performs a logged restart of the computer.
+- bypass_results() - asks the daemon to associate the <OUT> of the previous
+ step with the <IN> the next step. It is also used to inform the daemon about
+ the result (mounted directory) inside the current initramfs root, outside the
+ $mntdir tree.
- initrd_version() - output of the current version of make-initrd. It is proposed
to move to make-initrd/data/bin/initrd-sh-functions after has_module().
diff --git a/features/bootchain-core/data/bin/bootchain-sh-functions b/features/bootchain-core/data/bin/bootchain-sh-functions
index dcc1ab2..d1d0cef 100644
--- a/features/bootchain-core/data/bin/bootchain-sh-functions
+++ b/features/bootchain-core/data/bin/bootchain-sh-functions
@@ -22,6 +22,8 @@ else
mntdir="${mntdir:-/dev/bootchain}"
fi
+BC_NEXTCHAIN=/.initrd/bootchain/bootchain.next
+BC_PASSED=/.initrd/bootchain/passed
handlerdir=/lib/bootchain
@@ -153,6 +155,65 @@ assign()
debug "LET: ${_k}=\"${_v}\""
}
+next_bootchain()
+{
+ local _v="${1-}"
+
+ printf 'chainsteps="%s"\n' "${_v}" >>"$BC_NEXTCHAIN"
+ debug "BOOTCHAIN REPLACED: '${_v}'"
+}
+
+is_step_passed()
+{
+ [ -f "$BC_PASSED/$PROG" ] ||
+ return 1
+}
+
+launch_step_once()
+{
+ [ ! -f "$BC_PASSED/$PROG" ] ||
+ fatal "this step has been already passed"
+}
+
+break_bc_loop()
+{
+ enter "break_bc_loop"
+
+ :> "$BC_PASSED/chaind"
+
+ leave "break_bc_loop"
+}
+
+bc_reboot()
+{
+ run reboot -f -d
+}
+
+bypass_results()
+{
+ enter "bypass_results"
+
+ local realdir="${1-}"
+ local srcdir="${realdir:-$prevdir}"
+
+ if [ -n "$srcdir" ] && [ "$srcdir" != "$destdir" ]; then
+ if [ -d "$realdir" ] || [ -L "$prevdir" ] ||
+ [ "$srcdir" = "${srcdir#$mntdir/}" ]
+ then
+ run rmdir -- "$destdir" ||:
+ run ln -snf -- "$(readlink-e "$srcdir")" "$destdir"
+ elif mountpoint -q -- "$prevdir"; then
+ run mkdir -p -- "$destdir"
+ run mount --move -- "$prevdir" "$destdir"
+ else
+ run rmdir -- "$destdir" ||:
+ run mv -f -- "$prevdir" "$destdir"
+ fi
+ fi
+
+ leave "bypass_results"
+}
+
initrd_version()
{
[ ! -s /etc/initrd-release ] ||
diff --git a/features/bootchain-core/data/sbin/chaind b/features/bootchain-core/data/sbin/chaind
index c1b2451..9224c40 100755
--- a/features/bootchain-core/data/sbin/chaind
+++ b/features/bootchain-core/data/sbin/chaind
@@ -34,7 +34,7 @@ message "Starting server [$(initrd_version)]..."
debug "Booting with /proc/cmdline:"
fdump /proc/cmdline
-run mkdir -p -- "$mntdir"
+run mkdir -p -- "$mntdir" "$BC_PASSED"
mountpoint -q -- "$mntdir" ||
run mount -t tmpfs tmpfs "$mntdir" ||:
--
2.24.1
More information about the Make-initrd
mailing list