[PATCH 01/23] add grub feature
Alexey Shabalin
shaba at altlinux.org
Wed Oct 30 20:36:22 MSK 2019
---
features.in/grub/cfg.in/00defaults.cfg | 17 +++
features.in/grub/cfg.in/20install2.cfg | 6 ++
.../grub/cfg.in/25install-vnc-connect.cfg | 5 +
.../grub/cfg.in/25install-vnc-listen.cfg | 6 ++
features.in/grub/cfg.in/30live.cfg | 6 ++
features.in/grub/cfg.in/32live_rw.cfg | 4 +
features.in/grub/cfg.in/80rescue.cfg | 4 +
features.in/grub/cfg.in/82rescue_rw.cfg | 4 +
features.in/grub/cfg.in/83rescue_fm.cfg | 4 +
features.in/grub/cfg.in/85mediacheck.cfg | 4 +
features.in/grub/cfg.in/90memtest.cfg | 3 +
features.in/grub/cfg.in/95fwsetup.cfg | 3 +
features.in/grub/config.mk | 39 +++++++
features.in/grub/generate.mk | 100 ++++++++++++++++++
.../grub/scripts.d/20-propagator-ramdisk | 20 ++++
.../grub/scripts.d/20-propagator-rescue-hash | 14 +++
features.in/grub/stage1/scripts.d/01-grub | 41 +++++++
17 files changed, 280 insertions(+)
create mode 100644 features.in/grub/cfg.in/00defaults.cfg
create mode 100644 features.in/grub/cfg.in/20install2.cfg
create mode 100644 features.in/grub/cfg.in/25install-vnc-connect.cfg
create mode 100644 features.in/grub/cfg.in/25install-vnc-listen.cfg
create mode 100644 features.in/grub/cfg.in/30live.cfg
create mode 100644 features.in/grub/cfg.in/32live_rw.cfg
create mode 100644 features.in/grub/cfg.in/80rescue.cfg
create mode 100644 features.in/grub/cfg.in/82rescue_rw.cfg
create mode 100644 features.in/grub/cfg.in/83rescue_fm.cfg
create mode 100644 features.in/grub/cfg.in/85mediacheck.cfg
create mode 100644 features.in/grub/cfg.in/90memtest.cfg
create mode 100644 features.in/grub/cfg.in/95fwsetup.cfg
create mode 100644 features.in/grub/config.mk
create mode 100644 features.in/grub/generate.mk
create mode 100755 features.in/grub/scripts.d/20-propagator-ramdisk
create mode 100755 features.in/grub/scripts.d/20-propagator-rescue-hash
create mode 100755 features.in/grub/stage1/scripts.d/01-grub
diff --git a/features.in/grub/cfg.in/00defaults.cfg b/features.in/grub/cfg.in/00defaults.cfg
new file mode 100644
index 0000000000..4d469d4817
--- /dev/null
+++ b/features.in/grub/cfg.in/00defaults.cfg
@@ -0,0 +1,17 @@
+insmod echo
+insmod gzio
+insmod minicmd
+insmod normal
+insmod test
+set timeout=@timeout@
+
+if [ $grub_cpu = x86_64 -o $grub_cpu = i386 ]; then
+ if [ $grub_platform = efi ]; then
+ linux_suffix=efi
+ elif [ $grub_platform = pc ]; then
+ linux_suffix=16
+ else
+ linux_suffix=
+else
+ linux_suffix=
+fi
diff --git a/features.in/grub/cfg.in/20install2.cfg b/features.in/grub/cfg.in/20install2.cfg
new file mode 100644
index 0000000000..1da6304eb5
--- /dev/null
+++ b/features.in/grub/cfg.in/20install2.cfg
@@ -0,0 +1,6 @@
+
+default='linux'
+menuentry 'Install ALT @relname@' --hotkey 'i' --id 'linux' {
+ linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot automatic=method:cdrom ramdisk_size=@altinst_size@ vga=@bootvga@ @bootargs@
+ initrd$linux_suffix /EFI/BOOT/full.cz
+}
diff --git a/features.in/grub/cfg.in/25install-vnc-connect.cfg b/features.in/grub/cfg.in/25install-vnc-connect.cfg
new file mode 100644
index 0000000000..178e8fccd5
--- /dev/null
+++ b/features.in/grub/cfg.in/25install-vnc-connect.cfg
@@ -0,0 +1,5 @@
+
+menuentry 'Install ALT @relname@ (headless with DHCP+VNC client) (edit to set server IP address)' --id 'vncconnect' {
+ linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot automatic=method:cdrom ramdisk_size=@altinst_size@ showopts @bootargs@ headless no_alt_virt_keyboard vncconnect=IP
+ initrd$linux_suffix /EFI/BOOT/full.cz
+}
diff --git a/features.in/grub/cfg.in/25install-vnc-listen.cfg b/features.in/grub/cfg.in/25install-vnc-listen.cfg
new file mode 100644
index 0000000000..53b2b5119b
--- /dev/null
+++ b/features.in/grub/cfg.in/25install-vnc-listen.cfg
@@ -0,0 +1,6 @@
+
+menuentry 'Install ALT @relname@ (headless with DHCP+VNC) (password VNCPWD)' --id 'vncpasswd' {
+ linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot automatic=method:cdrom ramdisk_size=@altinst_size@ showopts @bootargs@ headless no_alt_virt_keyboard vncpassword=VNCPWD
+ initrd$linux_suffix /EFI/BOOT/full.cz
+}
+
diff --git a/features.in/grub/cfg.in/30live.cfg b/features.in/grub/cfg.in/30live.cfg
new file mode 100644
index 0000000000..d53a1e506a
--- /dev/null
+++ b/features.in/grub/cfg.in/30live.cfg
@@ -0,0 +1,6 @@
+menuentry 'LiveCD (no hard disk needed)' --id 'live' {
+ linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot live automatic=method:cdrom ramdisk_size=@live_size@ stagename=live showopts lowmem vga=@bootvga@ @bootargs@
+ initrd$linux_suffix /EFI/BOOT/full.cz
+}
+
+
diff --git a/features.in/grub/cfg.in/32live_rw.cfg b/features.in/grub/cfg.in/32live_rw.cfg
new file mode 100644
index 0000000000..55c4b977fe
--- /dev/null
+++ b/features.in/grub/cfg.in/32live_rw.cfg
@@ -0,0 +1,4 @@
+menuentry 'LiveCD with sessions support' --id 'session' {
+ linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot live automatic=method:cdrom ramdisk_size=@live_size@ stagename=live showopts live_rw vga=@bootvga@ @bootargs@
+ initrd$linux_suffix /EFI/BOOT/full.cz
+}
diff --git a/features.in/grub/cfg.in/80rescue.cfg b/features.in/grub/cfg.in/80rescue.cfg
new file mode 100644
index 0000000000..c6c0ae53c9
--- /dev/null
+++ b/features.in/grub/cfg.in/80rescue.cfg
@@ -0,0 +1,4 @@
+menuentry 'Rescue LiveCD' --id 'rescue' {
+ linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot live automatic=method:cdrom ramdisk_size=@rescue_size@ stagename=rescue splash=0 showopts @rescue_bootargs@
+ initrd$linux_suffix /EFI/BOOT/full.cz
+}
diff --git a/features.in/grub/cfg.in/82rescue_rw.cfg b/features.in/grub/cfg.in/82rescue_rw.cfg
new file mode 100644
index 0000000000..ec18be28bb
--- /dev/null
+++ b/features.in/grub/cfg.in/82rescue_rw.cfg
@@ -0,0 +1,4 @@
+menuentry 'Rescue with sessions support' --id 'rescue_session' {
+ linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot live automatic=method:cdrom,label:ALT* ramdisk_size=@rescue_size@ stagename=rescue splash=0 showopts @rescue_bootargs@ live_rw
+ initrd$linux_suffix /EFI/BOOT/full.cz
+}
diff --git a/features.in/grub/cfg.in/83rescue_fm.cfg b/features.in/grub/cfg.in/83rescue_fm.cfg
new file mode 100644
index 0000000000..71bf21d3b7
--- /dev/null
+++ b/features.in/grub/cfg.in/83rescue_fm.cfg
@@ -0,0 +1,4 @@
+menuentry 'Forensic mode (leave disks alone)' --id 'rescue_forensic' {
+ linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot live automatic=method:cdrom ramdisk_size=@rescue_size@ splash=0 showopts stagename=rescue @rescue_bootargs@ max_loop=16 forensic hash=@rescue_hash@
+ initrd$linux_suffix /EFI/BOOT/full.cz
+}
diff --git a/features.in/grub/cfg.in/85mediacheck.cfg b/features.in/grub/cfg.in/85mediacheck.cfg
new file mode 100644
index 0000000000..6779dd00d3
--- /dev/null
+++ b/features.in/grub/cfg.in/85mediacheck.cfg
@@ -0,0 +1,4 @@
+menuentry 'Check this media for defects' --id 'mediachk' {
+ linux$linux_suffix /EFI/BOOT/vmlinuz changedisk live quiet lowmem automatic=method:cdrom mediacheck=1 stagename=mediacheck showopts @bootargs@
+ initrd$linux_suffix /EFI/BOOT/full.cz
+}
diff --git a/features.in/grub/cfg.in/90memtest.cfg b/features.in/grub/cfg.in/90memtest.cfg
new file mode 100644
index 0000000000..f4c2121687
--- /dev/null
+++ b/features.in/grub/cfg.in/90memtest.cfg
@@ -0,0 +1,3 @@
+menuentry 'Memory Test' --id 'memtest' {
+ linux$linux_suffix /EFI/BOOT/memtest86.efi
+}
diff --git a/features.in/grub/cfg.in/95fwsetup.cfg b/features.in/grub/cfg.in/95fwsetup.cfg
new file mode 100644
index 0000000000..52404efd28
--- /dev/null
+++ b/features.in/grub/cfg.in/95fwsetup.cfg
@@ -0,0 +1,3 @@
+menuentry 'System setup' --id 'uefi-firmware' {
+ fwsetup
+}
diff --git a/features.in/grub/config.mk b/features.in/grub/config.mk
new file mode 100644
index 0000000000..9f80822fa4
--- /dev/null
+++ b/features.in/grub/config.mk
@@ -0,0 +1,39 @@
+# default is plain text prompt
+# NB: might be usbflash-ready hybrid iso
+
+# on ppc64le syslinux feature is used only to generate config
+#ifeq (,$(filter-out i586 x86_64 ppc64le aarch64,$(ARCH)))
+ifeq (,$(filter-out i586 x86_64,$(ARCH)))
+
+use/grub: sub/stage1 $(ISOHYBRID:%=use/isohybrid)
+ @$(call add_feature)
+ifeq (,$(filter-out i586 x86_64,$(ARCH)))
+ @$(call add,STAGE1_PACKAGES,grub-efi shim-signed)
+ @$(call try,BOOTVGA,normal)
+endif
+ @$(call set,RELNAME,ALT ($(IMAGE_NAME)))
+ @$(call set,IMAGE_PACKTYPE,boot)
+else
+
+use/grub: ; @:
+
+endif
+
+ifeq (,$(filter-out i586 x86_64,$(ARCH)))
+# UI is overwritten
+use/grub/ui/%: use/grub
+ @$(call set,GRUB_UI,$*)
+ @if [ "$*" == gfxboot ]; then \
+ $(call add,STAGE1_PACKAGES,gfxboot); \
+ $(call add,STAGE1_BRANDING,bootloader); \
+ fi
+else
+use/grub/ui/%: use/grub; @:
+endif
+
+use/grub/%.cfg: use/grub
+ @$(call add,GRUB_CFG,$*)
+
+
+use/grub/timeout/%: use/grub
+ @$(call set,GRUB_TIMEOUT,$*)
diff --git a/features.in/grub/generate.mk b/features.in/grub/generate.mk
new file mode 100644
index 0000000000..a0b59221a2
--- /dev/null
+++ b/features.in/grub/generate.mk
@@ -0,0 +1,100 @@
+ifdef BUILDDIR
+
+# in deciseconds
+DEFAULT_TIMEOUT = 90
+
+# prepare data for grub installation;
+# see also stage1/scripts.d/01-grub
+
+include $(BUILDDIR)/distcfg.mk
+
+ifndef BOOTLOADER
+$(error grub feature enabled but BOOTLOADER undefined)
+endif
+
+ifndef GRUB_DIRECT
+# SUBPROFILES are considered GRUB_CFG too
+# (note these can appear like stage2 ÎÁ live);
+# 01defaults.cfg is included indefinitely
+GRUB_CFG := $(GRUB_CFG) $(SUBPROFILE_DIRS) defaults
+endif
+
+DSTDIR := $(BUILDDIR)/stage1/files/EFI/BOOT/.in
+DSTCFGS := $(DSTDIR)/*.cfg
+
+# we can do GRUB_{CFG,MODULES,FILES}
+# CFG have only cfg snippet
+cfg = $(wildcard cfg.in/??$(1).cfg)
+
+# NB: list position determined by file numbering (*.cfg sorting)
+#
+# config snippets are copied into generated profile where they can
+# be also tested against grub modules (some can be unavailable);
+# we can't do tests right now since that implies host grub being
+# identical to build system one which might be not the case...
+#
+# have to piggyback parameters as we're running in host system yet,
+# and files involved will appear inside instrumental chroot
+#
+# arguments get evaluated before recipe body execution thus prep
+
+all: debug timeout
+ @### proper text branding should be implemented
+ @echo $(GRUB_FILES) > $(DSTDIR)/grub.list
+ @sed -i \
+ -e 's, ÎÁ mkimage-profiles@,$(IMAGE_NAME),' \
+ -e 's, ÎÁ relname@,$(RELNAME),' \
+ $(DSTCFGS)
+
+# integerity check
+timeout: distro
+ @if [ "$(GRUB_TIMEOUT)" -ge 0 ] 2>/dev/null; then \
+ TIMEOUT="$(GRUB_TIMEOUT)"; \
+ else \
+ TIMEOUT="$(DEFAULT_TIMEOUT)"; \
+ fi; \
+ sed -i "s, ÎÁ timeout@,$$TIMEOUT," $(DSTCFGS)
+
+distro: bootargs
+ @if [ -n "$(META_VOL_SET)" ]; then \
+ DISTRO="$(META_VOL_SET)"; \
+ else \
+ DISTRO="ALT"; \
+ fi; \
+ sed -i "s, ÎÁ distro@,$$DISTRO," $(DSTCFGS)
+
+# pass over additional parameters, if any
+bootargs: clean
+ @if [ -n "$(STAGE2_BOOTARGS)" ]; then \
+ sed -i "s, ÎÁ bootargs@,$(STAGE2_BOOTARGS)," $(DSTCFGS); \
+ fi; \
+ sed -i "s, ÎÁ bootargs@,," $(DSTCFGS)
+ @if [ -n "$(RESCUE_BOOTARGS)" ]; then \
+ sed -i "s, ÎÁ rescue_bootargs@,$(RESCUE_BOOTARGS)," $(DSTCFGS); \
+ fi; \
+ sed -i "s, ÎÁ rescue_bootargs@,," $(DSTCFGS)
+ @if [ -n "$(BOOTVGA)" ]; then \
+ sed -i "s, ÎÁ bootvga@,$(BOOTVGA)," $(DSTCFGS); \
+ fi; \
+ sed -i "s, ÎÁ bootvga@,,;s,vga= ,," $(DSTCFGS)
+
+clean: copy
+ @if [ "$(GRUB_UI)" = gfxboot ]; then \
+ sed -i "s/\^//;/menu label /d" $(DSTCFGS); \
+ fi
+
+copy: prep
+ @cp -pLt $(DSTDIR) -- $(sort \
+ $(foreach C,$(GRUB_CFG),$(call cfg,$(C))))
+
+prep:
+ @mkdir -p $(DSTDIR)
+
+debug:
+ @if [ -n "$(DEBUG)" ]; then \
+ echo "** BOOTLOADER: $(BOOTLOADER)"; \
+ echo "** GRUB_CFG: $(GRUB_CFG)"; \
+ echo "** GRUB_FILES: $(GRUB_FILES)"; \
+ fi
+
+endif
diff --git a/features.in/grub/scripts.d/20-propagator-ramdisk b/features.in/grub/scripts.d/20-propagator-ramdisk
new file mode 100755
index 0000000000..c47302a769
--- /dev/null
+++ b/features.in/grub/scripts.d/20-propagator-ramdisk
@@ -0,0 +1,20 @@
+#!/bin/sh
+# postprocess isolinux configuration
+# when the image sizes are finally known
+# NB: install2_size, live_size, rescue_size get defined here
+
+cd "$WORKDIR"
+
+cfgs="$(find EFI/BOOT -name '*.cfg')"
+[ -n "$cfgs" ] || {
+ echo "${0##*/}: did not find any config under EFI/BOOT " >&2
+ exit 1
+}
+
+# apply size census while looking for potential squashfs images
+find -maxdepth 1 -type f -size +1M \
+| sed 's,^\./,,' \
+| while read image; do
+ size="$[ $(stat -c%s "$image") / 1024 + 1 ]"
+ sed -i "s,@${image}_size@,$size," $cfgs
+done
diff --git a/features.in/grub/scripts.d/20-propagator-rescue-hash b/features.in/grub/scripts.d/20-propagator-rescue-hash
new file mode 100755
index 0000000000..fff0be0ce9
--- /dev/null
+++ b/features.in/grub/scripts.d/20-propagator-rescue-hash
@@ -0,0 +1,14 @@
+#!/bin/sh
+# postprocess isolinux configuration
+# to add rescue image hash, if any
+# (for propagator in forensic mode)
+
+cd "$WORKDIR"
+
+grep -qs "@rescue_hash@" EFI/BOOT/*.cfg || exit 0
+
+find -maxdepth 1 -type f -name rescue \
+| while read image; do
+ rescue_hash="$(sha256sum -b "$image" | cut -f1 -d' ')"
+ sed -i "s, ÎÁ rescue_hash@,$rescue_hash," EFI/BOOT/*.cfg
+done
diff --git a/features.in/grub/stage1/scripts.d/01-grub b/features.in/grub/stage1/scripts.d/01-grub
new file mode 100755
index 0000000000..620b8dac4b
--- /dev/null
+++ b/features.in/grub/stage1/scripts.d/01-grub
@@ -0,0 +1,41 @@
+#!/bin/sh
+# gather syslinux configuration from snippets;
+# copy modules; see also this feature's generate.mk
+
+CFG="grub.cfg"
+
+mkdir -p "$WORKDIR/EFI/BOOT"
+cd "$WORKDIR/EFI/BOOT"
+
+# validate just in case (see also stage1 Makefile)
+case "$GLOBAL_BOOTLOADER" in
+ isolinux|syslinux|ieee1275boot|grubaa64boot|grubx86boot) ;;
+ *) echo "error: weird GLOBAL_BOOTLOADER: \`$GLOBAL_BOOTLOADER'" >&2;
+ exit 1;;
+esac
+
+# copy extra files, if any
+GRUB_FILES="$(cat .in/grub.list)"
+if [ -n "${GRUB_FILES% }" ]; then
+ cp -a $GRUB_FILES .
+fi
+
+# number ordering sponsored by shell's pathname expansion
+grep -hv '^#' .in/[0-9][0-9]*.cfg > "$CFG"
+
+# there should be DEFAULT directive there (at least for alterator-netinst)
+if ! grep -i '^default' "$CFG"; then
+ DEFAULT="$(grep -i '^label ' "$CFG" | head -1 | cut -f2 -d' ')"
+ if [ -n "$DEFAULT" ]; then
+ echo "default $DEFAULT" >> "$CFG"
+ else
+ echo "error: no DEFAULT or UI directive and cannot guess" >&2
+ exit 1
+ fi
+fi
+
+# snippets are not going into the actual image
+if [ "$DEBUG" != 2 ]; then rm -r .in/; fi
+
+# NB: there will be final macro expansion based on actual image sizes
+# done by features.in/syslinux/scripts.d/20-propagator-ramdisk
--
2.24.1
--------------E54E3444F4BC138E1CEC79A9
Content-Type: text/x-patch;
name="0001-grub-fix-typo.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="0001-grub-fix-typo.patch"
More information about the devel-distro
mailing list