[make-initrd] [PATCH v1 03/41] fork pipeline: 10 new files added
Leonid Krivoshein
klark.devel at gmail.com
Fri Sep 24 18:55:00 MSK 2021
---
make-initrd/features/bootchain-core/config.mk | 5 +
.../bootchain-core/data/bin/machine-info | 123 ++++++++++++++++++
.../bootchain-core/data/lib/bootchain/debug | 84 ++++++++++++
.../data/lib/initrd/cmdline.d/bootchain | 6 +
.../bootchain-core/data/sbin/bootchain-logvt | 36 +++++
make-initrd/features/bootchain-core/rules.mk | 3 +
.../features/bootchain-getimage/README.md | 20 +++
.../features/bootchain-getimage/config.mk | 5 +
.../features/bootchain-getimage/rules.mk | 2 +
.../features/bootchain-waitdev/README.md | 21 +++
10 files changed, 305 insertions(+)
create mode 100644 make-initrd/features/bootchain-core/config.mk
create mode 100755
make-initrd/features/bootchain-core/data/bin/machine-info
create mode 100755
make-initrd/features/bootchain-core/data/lib/bootchain/debug
create mode 100755
make-initrd/features/bootchain-core/data/lib/initrd/cmdline.d/bootchain
create mode 100755
make-initrd/features/bootchain-core/data/sbin/bootchain-logvt
create mode 100644 make-initrd/features/bootchain-core/rules.mk
create mode 100644 make-initrd/features/bootchain-getimage/README.md
create mode 100644 make-initrd/features/bootchain-getimage/config.mk
create mode 100644 make-initrd/features/bootchain-getimage/rules.mk
create mode 100644 make-initrd/features/bootchain-waitdev/README.md
diff --git a/make-initrd/features/bootchain-core/config.mk
b/make-initrd/features/bootchain-core/config.mk
new file mode 100644
index 0000000..c87bad2
--- /dev/null
+++ b/make-initrd/features/bootchain-core/config.mk
@@ -0,0 +1,5 @@
+$(call feature-requires,depmod-image)
+
+BOOTCHAIN_CORE_DATADIR = $(FEATURESDIR)/bootchain-core/data
+
+BOOTCHAIN_CORE_MODULES = isofs squashfs overlay
diff --git a/make-initrd/features/bootchain-core/data/bin/machine-info
b/make-initrd/features/bootchain-core/data/bin/machine-info
new file mode 100755
index 0000000..79c528e
--- /dev/null
+++ b/make-initrd/features/bootchain-core/data/bin/machine-info
@@ -0,0 +1,123 @@
+#!/bin/bash -efu
+
+# TODO: read additional machine data for non-x86 platforms
+
+show_help()
+{
+ cat <<-EOF
+ Usage: $0 [<options>]
+
+ Options:
+ -d, --drivers Show drivers set unique ID
+ -i, --instance Show hardware instance unique ID
+ -h, --help Show this help message
+ EOF
+ exit 0
+}
+
+# Use DMI fields only on hardware that supports it
+
+show_dmi_info()
+{
+ local objects="bios_vendor board_name board_vendor board_version"
+ objects="$objects chassis_type chassis_vendor chassis_version sys_vendor"
+ objects="$objects product_family product_name product_sku product_version"
+ local f d dmi=/sys/class/dmi/id
+
+ [ -d "$dmi" ] ||
+ dmi=/sys/devices/virtual/dmi/id
+ [ -d "$dmi" ] ||
+ return 0
+ [ -z "${1-}" ] ||
+ objects="$objects product_uuid bios_version board_serial chassis_serial"
+
+ for f in $objects; do
+ [ -r "$dmi/$f" ] ||
+ continue
+ read -r d <"$dmi/$f"
+ [ -n "${d//[[:space:]]*/}" ] ||
+ continue
+ printf '%s: %s\n' "$f" "$d"
+ done
+}
+
+# Accessing PCI device resources through sysfs, see:
+# https://www.kernel.org/doc/html/latest/PCI/sysfs-pci.html
+# We reading fields, such as class, device, etc... as PCI ID's
+# (bus codes) according to Conventional PCI 3.0 specification.
+
+scan_pci_bus()
+{
+ local sysfs d h="[0-9a-f]"
+ local glob="$h$h$h$h\:$h$h\:$h$h.$h"
+
+ handle_field()
+ {
+ [ -r "$sysfs/$1" ] && read -r d <"$sysfs/$1" || d="-"
+ printf " %s" "$d"
+ }
+
+ find /sys/devices -mindepth 2 -maxdepth 2 -type d -name "$glob" |
+ grep '/sys/devices/pci' |
+ sort |
+ while read -r sysfs; do
+ printf "%s" "${sysfs##*/}"
+ handle_field class
+ handle_field vendor
+ handle_field device
+ handle_field subsystem_vendor
+ handle_field subsystem_device
+ handle_field revision
+ printf '\n'
+ done
+}
+
+show_cpu_info()
+{
+ local regex="vendor_id|cpu family|model"
+ regex="$regex|siblings|stepping|microcode"
+ regex="$regex|cache size|cpu cores|clflush size"
+ regex="$regex|cache_alignment|address sizes"
+
+ if [ -r /proc/cpuinfo ]; then
+ grep -E "^($regex)" /proc/cpuinfo |
+ sort -u |
+ sed -e 's/[[:space:]]*:/:/g'
+ fi
+}
+
+show_hw_info()
+{
+ printf 'platform: '
+ uname -m
+ show_dmi_info
+ scan_pci_bus
+}
+
+show_instance_info()
+{
+ printf 'platform: '
+ uname -m
+ show_cpu_info
+ show_dmi_info instance
+ scan_pci_bus
+}
+
+
+# Entry point
+case "${1-}" in
+-d|--drivers)
+ show_hw_info |sha256sum |cut -f1 -d' '
+ ;;
+-i|--instance)
+ show_instance_info |sha256sum |cut -f1 -d' '
+ ;;
+-h|--help)
+ show_help
+ ;;
+*) printf 'Hardware info:\n'
+ show_hw_info
+ printf '\nInstance info:\n'
+ show_instance_info
+ ;;
+esac
diff --git
a/make-initrd/features/bootchain-core/data/lib/bootchain/debug
b/make-initrd/features/bootchain-core/data/lib/bootchain/debug
new file mode 100755
index 0000000..ed70536
--- /dev/null
+++ b/make-initrd/features/bootchain-core/data/lib/bootchain/debug
@@ -0,0 +1,84 @@
+#!/bin/bash -efu
+
+. bootchain-sh-functions
+
+
+listpvdir()
+{
+ # shellcheck disable=SC2012
+ if [ -z "${1-}" ]; then
+ ls -1F "$prevdir/" |sort |head -n20
+ else
+ ls -1F "$prevdir/" |sort |grep -svE "$1" |head -n20
+ fi
+}
+
+
+# Entry point
+message "$PROG for $name [$callnum] started"
+
+message "PREV DIR: $prevdir"
+message "Data DIR: $datadir"
+message "DEST DIR: $destdir"
+
+{ printf "##############################"
+
+ if [ -d "$prevdir" ]; then
+ printf "\nPrevious step results (%s):\n" "$prevdir"
+
+ if mountpoint -q -- "$prevdir"; then
+ listpvdir
+ elif [ ! -b "$prevdir/dev" ] &&
+ [ ! -c "$prevdir/dev" ] &&
+ [ ! -s "$prevdir/DEVNAME" ] &&
+ [ ! -s "$prevdir/FILESIZE" ]
+ then
+ listpvdir
+ else
+ if [ -b "$prevdir/dev" ] || [ -c "$prevdir/dev" ]; then
+ devno="$(mountpoint -x -- "$prevdir/dev")"
+ [ -b "$prevdir/dev" ] &&
+ devname=/sys/dev/block ||
+ devname=/sys/dev/char
+ devname="$(grep -sE ^DEVNAME= "$devname/$devno/uevent" |cut -f2- -d=)"
+ printf 'dev (%s -> %s)\n' "$devno" "/dev/$devname"
+ fi
+
+ if [ -s "$prevdir/DEVNAME" ]; then
+ read -r devname <"$prevdir/DEVNAME" ||
+ devname=
+ if [ -z "$devname" ]; then
+ printf 'DEVNAME\n'
+ else
+ devno="$(mountpoint -x -- "$devname")" ||
+ devno="ABSENT"
+ printf 'DEVNAME (%s -> %s)\n' "$devno" "$devname"
+ fi
+ fi
+
+ if [ -s "$prevdir/FILESIZE" ]; then
+ read -r fsize <"$prevdir/FILESIZE" ||
+ fsize="NOT READABLE"
+ printf 'FILESIZE (%s)\n' "$fsize"
+ fi
+
+ listpvdir "^(dev|DEVNAME|FILESIZE)$"
+ fi
+ fi
+
+ # FIXME: make this better to specify interested mount points only
+ [ -z "${OEM_CDROOT-}" ] && regex="$rootmnt" ||
+ regex="$rootmnt $OEM_CDROOT"
+ regex="$regex $mntdir"
+ regex="${regex//\//\\/}"
+ regex=" (${regex// /\|})\/"
+
+ if mount |grep -qsE "$regex"; then
+ printf "\nMount points and devices:\n"
+ mount |grep -sE "$regex"
+ fi
+
+ printf "##############################\n"
+} 1>&2
+
+message "$PROG for $name [$callnum] finished"
diff --git
a/make-initrd/features/bootchain-core/data/lib/initrd/cmdline.d/bootchain
b/make-initrd/features/bootchain-core/data/lib/initrd/cmdline.d/bootchain
new file mode 100755
index 0000000..b692f6d
--- /dev/null
+++
b/make-initrd/features/bootchain-core/data/lib/initrd/cmdline.d/bootchain
@@ -0,0 +1,6 @@
+#!/bin/bash -efu
+
+. /.initrd/initenv
+
+[ "${ROOT-}" != bootchain ] ||
+ echo bootchain > /etc/initrd/method
diff --git
a/make-initrd/features/bootchain-core/data/sbin/bootchain-logvt
b/make-initrd/features/bootchain-core/data/sbin/bootchain-logvt
new file mode 100755
index 0000000..037505a
--- /dev/null
+++ b/make-initrd/features/bootchain-core/data/sbin/bootchain-logvt
@@ -0,0 +1,36 @@
+#!/bin/bash -efu
+
+. bootchain-sh-functions
+
+pid=
+pidfile=/var/run/bootchained.pid
+
+
+exit_handler()
+{
+ local rc=$?
+
+ trap - EXIT
+
+ if [ -n "$pid" ]; then
+ kill -TERM "$pid" ||
+ kill -KILL "$pid" ||:
+ wait "$pid" ||:
+ fi >/dev/null 2>&1
+
+ clear
+ exit $rc
+}
+
+
+# Entry point
+[ -z "${NOTTYS-}" ] && [ -n "$BC_LOG_VT" ] ||
+ exit 1
+set_cleanup_handler exit_handler
+exec </dev/null >"/dev/tty$BC_LOG_VT" 2>&1
+printf "bootchain logger started on tty%s\n\n" "$BC_LOG_VT"
+tail -f -- "$BC_LOGFILE" & pid="$!"
+
+while [ -f "$pidfile" ]; do
+ sleep 1
+done
diff --git a/make-initrd/features/bootchain-core/rules.mk
b/make-initrd/features/bootchain-core/rules.mk
new file mode 100644
index 0000000..aeddf91
--- /dev/null
+++ b/make-initrd/features/bootchain-core/rules.mk
@@ -0,0 +1,3 @@
+MODULES_TRY_ADD += $(BOOTCHAIN_CORE_MODULES)
+
+PUT_FEATURE_DIRS += $(BOOTCHAIN_CORE_DATADIR)
diff --git a/make-initrd/features/bootchain-getimage/README.md
b/make-initrd/features/bootchain-getimage/README.md
new file mode 100644
index 0000000..349de6e
--- /dev/null
+++ b/make-initrd/features/bootchain-getimage/README.md
@@ -0,0 +1,20 @@
+# Bootchain sub-module: getimage
+
+## Chain elements
+
+- `getimage` receives and mounts the remote image.
+
+## Boot parameters
+
+- `getimage` specifies an URL to fetch and mount.
+
+This parameter can be specified more than once depending on how many times
+a corresponding element is mentioned in the `bootchain`.
+
+## Example
+
+Cmdline: root=bootchain bootchain=getimage,mountfs,overlayfs,rootfs
getimage=http://ftp.altlinux.org/pub/people/mike/iso/misc/vi-20140918-i586.iso
mountfs=rescue
+
+Following these parameters, the bootchain downloads the
vi-20140918-i586.iso
+image, mount it as a loop, make it writable using overlayfs and will try to
+boot from it.
diff --git a/make-initrd/features/bootchain-getimage/config.mk
b/make-initrd/features/bootchain-getimage/config.mk
new file mode 100644
index 0000000..498196e
--- /dev/null
+++ b/make-initrd/features/bootchain-getimage/config.mk
@@ -0,0 +1,5 @@
+$(call feature-requires,bootchain-core)
+
+BOOTCHAIN_GETIMAGE_DATADIR = $(FEATURESDIR)/bootchain-getimage/data
+
+BOOTCHAIN_GETIMAGE_PROGS = wget
diff --git a/make-initrd/features/bootchain-getimage/rules.mk
b/make-initrd/features/bootchain-getimage/rules.mk
new file mode 100644
index 0000000..af50f8e
--- /dev/null
+++ b/make-initrd/features/bootchain-getimage/rules.mk
@@ -0,0 +1,2 @@
+PUT_FEATURE_DIRS += $(BOOTCHAIN_GETIMAGE_DATADIR)
+PUT_FEATURE_PROGS += $(BOOTCHAIN_GETIMAGE_PROGS)
diff --git a/make-initrd/features/bootchain-waitdev/README.md
b/make-initrd/features/bootchain-waitdev/README.md
new file mode 100644
index 0000000..f8c07a6
--- /dev/null
+++ b/make-initrd/features/bootchain-waitdev/README.md
@@ -0,0 +1,21 @@
+# Bootchain sub-module: waitdev
+
+## Chain elements
+
+- `waitdev` waits for the local device to appear.
+
+## Boot parameters
+
+- `waitdev` describes the local device to wait. The format of this
parameter is
+ the same as `root=`, but with optional `CDROM:` prefix.
+
+This parameter can be specified more than once depending on how many times
+a corresponding element is mentioned in the `bootchain`.
+
+## Example
+
+Cmdline: root=bootchain
bootchain=waitdev,mountfs,mountfs,overlayfs,rootfs
waitdev=CDROM:LABEL=ALT_regular-rescue/x86_64 mountfs=dev mountfs=rescue
+
+Following these parameters, the bootchain wait local CDROM drive labeled as
+`ALT_regular-rescue/x86_64`, mount it, mount squash file `rescue` as a loop
+from it, make final rootfs writable using overlayfs and will try to
boot from it.
--
2.21.0
More information about the Make-initrd
mailing list