From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:subject:to:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=+W6zGuKcik/TOgkcZXNGD2Nhy89CrGCLPvNN0nT1m1w=; b=QlN2QUd0RI1BJHUQyR5RoYAFrCTdCoigT7sB0cQpovvAqXs8KQKdnyLjxOgddtlDhO fk+aiatklOjG9msXouJZLmSTXEq97Z06IqLVne1vU1GTQyjxYFCNK3z/MXfXgWugkM4R d0Y1T54SHYv4gBf/WZhq3K54pAvDWC0YQLqiypkqxtYwpdhbDCMeDMkZWsDgpzCoZAFh 6FzR+WOfGiJviDIFjto0J4spGYGPmGiAK22EiDi0nGqfJvqOgNhT6s2+k4rHnewizBlu rGUDebcW1sYzVU1H6+Le2XNFgn4mzJaU+E6e1WvTGGmQ3gwheS1QCZsEWwmvP/5oi7cg ux1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=+W6zGuKcik/TOgkcZXNGD2Nhy89CrGCLPvNN0nT1m1w=; b=6Jt1OUsVCxyV4umNfEMZsigRUAjpdVbDq9YqGnlAK8kZRr/KUzzZWQ0l2c6w9XuBek +4LPWPQ5Tc2eq+a6Y8/nndgu5dd6fZSv98yL9QmcFPbPqaxX54S5fpzKBxooIddpEIlY 6rJ3rgRbLkoBDRncblmL7FPwaTtwe5hbpEykEDPkL6+DABYxGO59D46E9ZUbBfbE5zF4 5j3uvZX/xwqKHrbmRHMpcrIwbLOGsKJNXeSQvSgZ/l+fGHwR2d0emDJq9z98zYrZ1hIm 8uLOen5/y5YkG08w3sW2LPI+G4XMa+lCRIQvUl6IkLcs8cYfcr3rpi4CSYJh+pYQQGZ0 FFaA== X-Gm-Message-State: AOAM531x6Hr1SDUB+JgcpzU11rtLNHOB+DQtGj9ElNuEwiyYzZeZeCq0 5Ee/yRnyHiKCo187/r1M9xM/BFy47gk= X-Google-Smtp-Source: ABdhPJzxTEECvmdXVN0ezT79Ena7Z4qjo232L0e9gk+VA6u/tt/2rw9i0invBTrXwf09eTwt5xXd6Q== X-Received: by 2002:a05:651c:1689:: with SMTP id bd9mr11522893ljb.22.1632498901688; Fri, 24 Sep 2021 08:55:01 -0700 (PDT) From: Leonid Krivoshein To: make-initrd@lists.altlinux.org Message-ID: <85596fef-b8b4-79ac-3714-8c7b0ca5b3a7@gmail.com> Date: Fri, 24 Sep 2021 18:55:00 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1251; format=flowed Content-Language: ru Content-Transfer-Encoding: 7bit Subject: [make-initrd] [PATCH v1 03/41] fork pipeline: 10 new files added X-BeenThere: make-initrd@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: make-initrd@lists.altlinux.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Sep 2021 15:55:06 -0000 Archived-At: List-Archive: --- 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: + -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/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