From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Fri, 24 Sep 2021 20:31:46 +0200 From: Alexey Gladkov To: make-initrd@lists.altlinux.org Message-ID: <20210924183146.ctscatzo5dosddrd@example.org> References: <85596fef-b8b4-79ac-3714-8c7b0ca5b3a7@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <85596fef-b8b4-79ac-3714-8c7b0ca5b3a7@gmail.com> Subject: Re: [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 18:31:48 -0000 Archived-At: List-Archive: On Fri, Sep 24, 2021 at 06:55:00PM +0300, Leonid Krivoshein wrote: > --- > 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(+) Леонид, ты мастер commit message! С твоими описаниями не поспоришь. Действительно, 10. Но важнее, что это за файлы. Кстати, я хочу обратить внимание: https://github.com/osboot/make-initrd/blob/master/Documentation/Contributing.md Для меня это важно. Ты добавляешь фичи, но ни слова не пишешь о том, что это. Это же относится и к README.md. Там ни слова про то что это. Только название и параметры. > 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' | find /sys/devices -mindepth 2 -maxdepth 2 -type d -path "/sys/devices/pci*/$glob" > + 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 Мне кажется в handle_field() не имеет смысла проверять на существование эти файлы. Это всё компоненты MODALIAS. Зачем это печатать отдельно, если это ровно modalias ? По сути всё тело функции можно заменить: find /sys/devices -mindepth 2 -maxdepth 3 -type f -path "/sys/devices/pci*/$glob/modalias" | sort | while read -r path; do read -r modalias < "$path" path="${path%/modalias}" printf '%s %s\n' "${path##*/}" "$modalias" done > + 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="$!" Откуда берутся BC_LOG_VT и BC_LOGFILE ? > + > +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 > > > _______________________________________________ > Make-initrd mailing list > Make-initrd@lists.altlinux.org > https://lists.altlinux.org/mailman/listinfo/make-initrd > -- Rgrds, legion