Make-initrd development discussion
 help / color / mirror / Atom feed
From: Alexey Gladkov <gladkov.alexey@gmail.com>
To: make-initrd@lists.altlinux.org
Subject: Re: [make-initrd] [PATCH v1 03/41] fork pipeline: 10 new files added
Date: Fri, 24 Sep 2021 20:31:46 +0200
Message-ID: <20210924183146.ctscatzo5dosddrd@example.org> (raw)
In-Reply-To: <85596fef-b8b4-79ac-3714-8c7b0ca5b3a7@gmail.com>

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>]
> +
> +	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/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="$!"

Откуда берутся 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



  reply	other threads:[~2021-09-24 18:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-24 15:55 Leonid Krivoshein
2021-09-24 18:31 ` Alexey Gladkov [this message]
2021-09-26 18:41   ` Leonid Krivoshein
2021-09-27  8:45     ` Alexey Gladkov
2021-09-27 13:03       ` Leonid Krivoshein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210924183146.ctscatzo5dosddrd@example.org \
    --to=gladkov.alexey@gmail.com \
    --cc=make-initrd@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Make-initrd development discussion

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/make-initrd/0 make-initrd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 make-initrd make-initrd/ http://lore.altlinux.org/make-initrd \
		make-initrd@lists.altlinux.org make-initrd@lists.altlinux.ru make-initrd@lists.altlinux.com
	public-inbox-index make-initrd

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.make-initrd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git