public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH] kernel-build.eclass: identify dist-kernels, and warn users
@ 2024-06-26 19:09 Andrew Nowa Ammerlaan
  2024-06-26 20:06 ` [gentoo-dev] [PATCH 0/5] mount-boot.eclass: revises /boot checking for dist-kernels, add checks for ESP Andrew Nowa Ammerlaan
  0 siblings, 1 reply; 13+ messages in thread
From: Andrew Nowa Ammerlaan @ 2024-06-26 19:09 UTC (permalink / raw
  To: gentoo-dev

Part of https://github.com/gentoo/gentoo/pull/37281

 From c88eee66089333fbcee6377b5f580e70a4ec2a8c Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
Date: Mon, 24 Jun 2024 22:18:46 +0200
Subject: [PATCH] kernel-build.eclass: identify dist-kernels, and warn users

Many, many, new users at some point make the mistake of running "make ...."
in the source directory of a distribution kernel.

This returns a vague error due to the absence of the kernel source files:

make[2]: *** No rule to make target 
'arch/x86/entry/syscalls/syscall_32.tbl', needed by 
'arch/x86/include/generated/uapi/asm/unistd_32.h'.  Stop.
make[1]: *** [arch/x86/Makefile:248: archheaders] Error 2
make: *** [Makefile:234: __sub-make] Error 2

Here we append to the kernel Makefile a warning that should make it more 
clear
what is going wrong. "$(shell [ -t 0 ] && echo 1)" is a trick to show this
warning when an user is executing "make" from their shell, but not when 
they are
compiling out-of-tree kernel modules (which is the reason we need to install
these makefiles to begin with).

We also add a "dist-kernel" file containing the package atom of the 
ebuild that
installed this kernel. This makes it possible for ebuilds/eclasses or 
whatever
other tools to check if a kernel is a Gentoo distribution kernel. This
identifier will be overwritten in gentoo-kernel-bin.ebuild.

Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
---
  eclass/kernel-build.eclass | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)

diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index 7922638be6e1c..86c7cd4a172d5 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -382,6 +382,22 @@ kernel-build_src_install() {
  	local module_ver
  	module_ver=$(<"${relfile}") || die

+	# warn when trying to "make" a dist-kernel
+	cat <<-EOF >> "${ED}${kernel_dir}/Makefile" || die
+
+		_GENTOO_IS_USER_SHELL:=\$(shell [ -t 0 ] && echo 1)
+		ifdef _GENTOO_IS_USER_SHELL
+		\$(warning !!!! WARNING !!!!)
+		\$(warning This kernel was configured and installed by the package 
manager.)
+		\$(warning "make" should not be run manually here.)
+		\$(warning See also: 
https://wiki.gentoo.org/wiki/Project:Distribution_Kernel)
+		\$(warning See also: https://wiki.gentoo.org/wiki/Kernel/Configuration)
+		\$(warning !!!! WARNING !!!!)
+		endif
+	EOF
+	# add a dist-kernel identifier file
+	echo "${CATEGORY}/${PF}:${SLOT}" > "${ED}${kernel_dir}/dist-kernel" || die
+
  	# fix source tree and build dir symlinks
  	dosym "../../../${kernel_dir}" "/lib/modules/${module_ver}/build"
  	dosym "../../../${kernel_dir}" "/lib/modules/${module_ver}/source"



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-dev] [PATCH 0/5] mount-boot.eclass: revises /boot checking for dist-kernels, add checks for ESP
  2024-06-26 19:09 [gentoo-dev] [PATCH] kernel-build.eclass: identify dist-kernels, and warn users Andrew Nowa Ammerlaan
@ 2024-06-26 20:06 ` Andrew Nowa Ammerlaan
  2024-06-26 20:06   ` [gentoo-dev] [PATCH 1/5] mount-boot.eclass: check for ESP as well as /boot, split, eclass Andrew Nowa Ammerlaan
  0 siblings, 1 reply; 13+ messages in thread
From: Andrew Nowa Ammerlaan @ 2024-06-26 20:06 UTC (permalink / raw
  To: gentoo-dev

Part of: https://github.com/gentoo/gentoo/pull/37292

This series builds on the previous patch: "kernel-build.eclass: identify 
dist-kernels, and warn users"

Effectively, the change amounts to harmonizing the way ebuilds/eclasses 
using "dist-kernel_reinstall_initramfs" re-install the dist-kernel with 
how kernel-install.eclass installs the dist-kernel. Specifically in the 
area's of a) checking mounting status of /boot and b) handeling failure 
in /sbin/installkernel.

This addresses an annoying issue new users run into where linux-firmware 
  and intel-microcode packages are too strict in enforcing mounted /boot.

To achieve this:
- Error handling and mount-boot checking is moved from 
kernel-install.eclass to dist-kerel-utils.eclass
- In the above we run into the problem that mount-boot.eclass exports 
pkg_pretend and pkg_{pre,post}{inst,rm}. Whereas dist-kernel-utils 
exports nothing. To resolved the problem the bulk of mount-boot.eclass 
is moved into a new "inherit-safe" mount-boot-utils.eclass, which in 
turn is inherited by mount-boot.eclass for backwards compatibility.
- The new mount-boot-utils.eclass is adjusted to check not only for 
mounted /boot, but also for a mounted EFI System Partition on UEFI systems.
- linux-mod-r1.eclass is adjusted to perform the mount-boot check early 
for packages that install modules into the initramfs (currently only 
zfs-kmod). We use pkg_setup instead of the usual pkg_pretend to avoid 
exporting a new phase. The check is nonfatal, i.e. only informative, the 
same way it is when installing the kernel (via kernel-install.eclass)
- linux-firmware and intel-microcode ebuilds are adjusted to be less 
strict about mounted /boot in the USE=dist-kernel case. This mirrors how 
kernel (re-)installation works in 
kernel-install.eclass/linux-mod-r1.eclass, i.e. nonfatal informative 
warning early, and only hard fail in pkg_postinst with informative 
message on how users can trigger kernel re-installation manually.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [gentoo-dev] [PATCH 1/5] mount-boot.eclass: check for ESP as well as /boot, split, eclass
  2024-06-26 20:06 ` [gentoo-dev] [PATCH 0/5] mount-boot.eclass: revises /boot checking for dist-kernels, add checks for ESP Andrew Nowa Ammerlaan
@ 2024-06-26 20:06   ` Andrew Nowa Ammerlaan
  2024-06-26 20:07     ` [gentoo-dev] [PATCH 2/5] kernel-install.eclass: move mount-boot check to, dist-kernel-utils.eclass Andrew Nowa Ammerlaan
  2024-06-27  4:00     ` [gentoo-dev] [PATCH 1/5] mount-boot.eclass: check for ESP as well as /boot, split, eclass Ulrich Mueller
  0 siblings, 2 replies; 13+ messages in thread
From: Andrew Nowa Ammerlaan @ 2024-06-26 20:06 UTC (permalink / raw
  To: gentoo-dev

 From 53f844361df57d480480b5e0ab0f35d2788ebf6a Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
Date: Tue, 25 Jun 2024 15:08:49 +0200
Subject: [PATCH] mount-boot.eclass: check for ESP as well as /boot, split
  eclass

This eclass is used by when the dist-kernel has to re-installed.

Depending on the configuration of sys-kernel/installkernel, the files may be
installed to /boot or to the EFI System partition. Therefore, extend 
this eclass
to check if the ESP is mounted read-write as well on UEFI platforms.

Split off the main functions into a separate "inherit-safe" eclass so we can
safely use it in dist-kernel-utils.eclass and linux-mod-r1.eclass.

Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
---
  eclass/mount-boot-utils.eclass | 109 +++++++++++++++++++++++++++++++++
  eclass/mount-boot.eclass       |  81 +++---------------------
  2 files changed, 118 insertions(+), 72 deletions(-)
  create mode 100644 eclass/mount-boot-utils.eclass

diff --git a/eclass/mount-boot-utils.eclass b/eclass/mount-boot-utils.eclass
new file mode 100644
index 0000000000000..06ea2254b0013
--- /dev/null
+++ b/eclass/mount-boot-utils.eclass
@@ -0,0 +1,109 @@
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: mount-boot-utils.eclass
+# @MAINTAINER:
+# base-system@gentoo.org
+# @SUPPORTED_EAPIS: 6 7 8
+# @BLURB: functions for packages that install files into /boot
+# @DESCRIPTION:
+# This eclass is really only useful for bootloaders and kernel 
installation.
+#
+# If the live system has a separate /boot partition or ESP configured, 
then this
+# function tries to ensure that it's mounted in rw mode, exiting with 
an error
+# if it can't.  It does nothing if /boot and ESP isn't a separate 
partition.
+#
+# This eclass provides the functions used by mount-boot.eclass in an 
"inherit-
+# safe" way. This allows these functions to be used in other eclasses 
cleanly.
+
+case ${EAPI} in
+	6|7|8) ;;
+	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+# @FUNCTION: mount-boot_is_disabled
+# @INTERNAL
+# @DESCRIPTION:
+# Detect whether the current environment/build settings are such that 
we do not
+# want to mess with any mounts.
+mount-boot_is_disabled() {
+	# Since this eclass only deals with /boot, skip things when EROOT is 
active.
+	if [[ ${EROOT:-/} != / ]] ; then
+		return 0
+	fi
+
+	# If we're only building a package, then there's no need to check things.
+	if [[ ${MERGE_TYPE} == buildonly ]] ; then
+		return 0
+	fi
+
+	# The user wants us to leave things be.
+	if [[ -n ${DONT_MOUNT_BOOT} ]] ; then
+		return 0
+	fi
+
+	# OK, we want to handle things ourselves.
+	return 1
+}
+
+# @FUNCTION: mount-boot_check_status
+# @INTERNAL
+# @DESCRIPTION:
+# Check if /boot and ESP is sane, i.e., mounted as read-write if on a 
separate
+# partition.  Die if conditions are not fulfilled.  If nonfatal is used,
+# the function will return a non-zero status instead.
+mount-boot_check_status() {
+	# Get out fast if possible.
+	mount-boot_is_disabled && return 0
+
+	local partition=
+	local part_is_not_mounted=
+	local part_is_read_only=
+	local candidates=( /boot )
+
+	# If system is booted with UEFI, check for ESP as well
+	if [[ -d /sys/firmware/efi ]]; then
+		# Use same candidates for ESP as installkernel and eclean-kernel
+		candidates+=( /efi /boot/efi /boot/EFI )
+	fi
+
+	for partition in ${candidates[@]}; do
+		# note that /dev/BOOT is in the Gentoo default /etc/fstab file
+		local fstabstate=$(awk "!/^[[:blank:]]*#|^\/dev\/BOOT/ && \$2 == 
\"${partition}\" \
+			{ print 1; exit }" /etc/fstab || die "awk failed")
+
+		if [[ -z ${fstabstate} ]] ; then
+			einfo "Assuming you do not have a separate ${partition} partition."
+		else
+			local procstate=$(awk "\$2 == \"${partition}\" { split(\$4, a, \",\"); \
+				for (i in a) if (a[i] ~ /^r[ow]\$/) { print a[i]; break }; exit }" \
+				/proc/mounts || die "awk failed")
+
+			if [[ -z ${procstate} ]] ; then
+				eerror "Your ${partition} partition is not mounted"
+				eerror "Please mount it and retry."
+				die -n "${partition} not mounted"
+				part_is_not_mounted=1
+			else
+				if [[ ${procstate} == ro ]] ; then
+					eerror "Your ${partition} partition, was detected as being mounted," \
+						"but is mounted read-only."
+					eerror "Please remount it as read-write and retry."
+					die -n "${partition} mounted read-only"
+					part_is_read_only=1
+				else
+					einfo "Your ${partition} partition was detected as being mounted."
+					einfo "Files will be installed there for ${PN} to function correctly."
+				fi
+			fi
+		fi
+	done
+
+	if [[ -n ${part_is_not_mounted} ]]; then
+		return 1
+	elif [[ -n ${part_is_read_only} ]]; then
+		return 2
+	else
+		return 0
+	fi
+}
diff --git a/eclass/mount-boot.eclass b/eclass/mount-boot.eclass
index 73beb9adea670..f4626ccb97a9c 100644
--- a/eclass/mount-boot.eclass
+++ b/eclass/mount-boot.eclass
@@ -1,4 +1,4 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
  # Distributed under the terms of the GNU General Public License v2

  # @ECLASS: mount-boot.eclass
@@ -7,84 +7,21 @@
  # @SUPPORTED_EAPIS: 6 7 8
  # @BLURB: functions for packages that install files into /boot
  # @DESCRIPTION:
-# This eclass is really only useful for bootloaders.
+# This eclass is really only useful for bootloaders and kernel 
installation.
  #
-# If the live system has a separate /boot partition configured, then this
-# function tries to ensure that it's mounted in rw mode, exiting with an
-# error if it can't.  It does nothing if /boot isn't a separate partition.
+# If the live system has a separate /boot partition or ESP configured, 
then this
+# function tries to ensure that it's mounted in rw mode, exiting with 
an error
+# if it can't.  It does nothing if /boot and ESP isn't a separate 
partition.
+#
+# This eclass exports the functions provided by mount-boot-utils.eclass to
+# the pkg_pretend and pkg_{pre,post}{inst,rm} phases.

  case ${EAPI} in
  	6|7|8) ;;
  	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
  esac

-# @FUNCTION: mount-boot_is_disabled
-# @INTERNAL
-# @DESCRIPTION:
-# Detect whether the current environment/build settings are such that 
we do not
-# want to mess with any mounts.
-mount-boot_is_disabled() {
-	# Since this eclass only deals with /boot, skip things when EROOT is 
active.
-	if [[ ${EROOT:-/} != / ]] ; then
-		return 0
-	fi
-
-	# If we're only building a package, then there's no need to check things.
-	if [[ ${MERGE_TYPE} == buildonly ]] ; then
-		return 0
-	fi
-
-	# The user wants us to leave things be.
-	if [[ -n ${DONT_MOUNT_BOOT} ]] ; then
-		return 0
-	fi
-
-	# OK, we want to handle things ourselves.
-	return 1
-}
-
-# @FUNCTION: mount-boot_check_status
-# @INTERNAL
-# @DESCRIPTION:
-# Check if /boot is sane, i.e., mounted as read-write if on a separate
-# partition.  Die if conditions are not fulfilled.  If nonfatal is used,
-# the function will return a non-zero status instead.
-mount-boot_check_status() {
-	# Get out fast if possible.
-	mount-boot_is_disabled && return 0
-
-	# note that /dev/BOOT is in the Gentoo default /etc/fstab file
-	local fstabstate=$(awk '!/^[[:blank:]]*#|^\/dev\/BOOT/ && $2 == "/boot" \
-		{ print 1; exit }' /etc/fstab || die "awk failed")
-
-	if [[ -z ${fstabstate} ]] ; then
-		einfo "Assuming you do not have a separate /boot partition."
-		return 0
-	fi
-
-	local procstate=$(awk '$2 == "/boot" { split($4, a, ","); \
-		for (i in a) if (a[i] ~ /^r[ow]$/) { print a[i]; break }; exit }' \
-		/proc/mounts || die "awk failed")
-
-	if [[ -z ${procstate} ]] ; then
-		eerror "Your boot partition is not mounted at /boot."
-		eerror "Please mount it and retry."
-		die -n "/boot not mounted"
-		return 1
-	fi
-
-	if [[ ${procstate} == ro ]] ; then
-		eerror "Your boot partition, detected as being mounted at /boot," \
-			"is read-only."
-		eerror "Please remount it as read-write and retry."
-		die -n "/boot mounted read-only"
-		return 2
-	fi
-
-	einfo "Your boot partition was detected as being mounted at /boot."
-	einfo "Files will be installed there for ${PN} to function correctly."
-	return 0
-}
+inherit mount-boot-utils

  mount-boot_pkg_pretend() {
  	mount-boot_check_status


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [gentoo-dev] [PATCH 2/5] kernel-install.eclass: move mount-boot check to, dist-kernel-utils.eclass
  2024-06-26 20:06   ` [gentoo-dev] [PATCH 1/5] mount-boot.eclass: check for ESP as well as /boot, split, eclass Andrew Nowa Ammerlaan
@ 2024-06-26 20:07     ` Andrew Nowa Ammerlaan
  2024-06-26 20:08       ` [gentoo-dev] [PATCH 3/5] linux-mod-r1.eclass: check /boot if we are re-installing, dist-kernel Andrew Nowa Ammerlaan
  2024-06-27  4:07       ` [gentoo-dev] [PATCH 2/5] kernel-install.eclass: move mount-boot check to, dist-kernel-utils.eclass Ulrich Mueller
  2024-06-27  4:00     ` [gentoo-dev] [PATCH 1/5] mount-boot.eclass: check for ESP as well as /boot, split, eclass Ulrich Mueller
  1 sibling, 2 replies; 13+ messages in thread
From: Andrew Nowa Ammerlaan @ 2024-06-26 20:07 UTC (permalink / raw
  To: gentoo-dev

 From c4c5ef732670f8b23f20b1215af49cdceacd28a3 Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
Date: Tue, 25 Jun 2024 16:12:39 +0200
Subject: [PATCH] kernel-install.eclass: move mount-boot check to
  dist-kernel-utils.eclass

ebuilds and eclasses using dist-kernel_reinstall_initramfs should also
have the check for mounted /boot and ESP. We can do this safely via
mount-boot-utils.eclass which does not export any phases.

Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
---
  eclass/dist-kernel-utils.eclass | 41 +++++++++++++++++++++++++++-----
  eclass/kernel-install.eclass    | 42 +++++++--------------------------
  2 files changed, 43 insertions(+), 40 deletions(-)

diff --git a/eclass/dist-kernel-utils.eclass 
b/eclass/dist-kernel-utils.eclass
index 13137f8c863c8..b357cfe6d228c 100644
--- a/eclass/dist-kernel-utils.eclass
+++ b/eclass/dist-kernel-utils.eclass
@@ -26,7 +26,7 @@ case ${EAPI} in
  	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
  esac

-inherit toolchain-funcs
+inherit mount-boot-utils toolchain-funcs

  # @FUNCTION: dist-kernel_get_image_path
  # @DESCRIPTION:
@@ -79,11 +79,40 @@ dist-kernel_install_kernel() {
  	local image=${2}
  	local map=${3}

-	ebegin "Installing the kernel via installkernel"
-	# note: .config is taken relatively to System.map;
-	# initrd relatively to bzImage
-	ARCH=$(tc-arch-kernel) installkernel "${version}" "${image}" "${map}"
-	eend ${?} || die -n "Installing the kernel failed"
+	local success=
+	# not an actual loop but allows error handling with 'break'
+	while :; do
+		nonfatal mount-boot_check_status || break
+
+		ebegin "Installing the kernel via installkernel"
+		# note: .config is taken relatively to System.map;
+		# initrd relatively to bzImage
+		ARCH=$(tc-arch-kernel) installkernel "${version}" "${image}" "${map}" 
|| break
+		eend ${?} || die -n "Installing the kernel failed"
+
+		success=1
+		break
+	done
+
+	if [[ ! ${success} ]]; then
+		# Try to read dist-kernel identifier to more accurately instruct users
+		local kernel
+		local k_id_file=${image%$(dist-kernel_get_image_path)}/dist-kernel
+		if [[ -f ${k_id_file} ]]; then
+			kernel=\'\=$(<${k_id_file})\'
+		else
+			# Fallback string if identifier is not found
+			kernel="<name of your kernel pakcage>:<kernel version>"
+		fi
+
+		eerror
+		eerror "The kernel was not deployed successfully. Inspect the failure"
+		eerror "in the logs above and once you resolve the problems please"
+		eerror "run the equivalent of the following command to try again:"
+		eerror
+		eerror "    emerge --config ${kernel}"
+		die "Kernel install failed, please fix the problems and run emerge 
--config"
+	fi
  }

  # @FUNCTION: dist-kernel_reinstall_initramfs
diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass
index f512d815fe098..a572597bc6fa3 100644
--- a/eclass/kernel-install.eclass
+++ b/eclass/kernel-install.eclass
@@ -18,8 +18,6 @@
  # location and System.map.
  #
  # The eclass exports src_test, pkg_postinst and pkg_postrm.
-# Additionally, the inherited mount-boot eclass exports pkg_pretend.
-# It also stubs out pkg_preinst and pkg_prerm defined by mount-boot.

  # @ECLASS_VARIABLE: KERNEL_IUSE_GENERIC_UKI
  # @PRE_INHERIT
@@ -50,7 +48,7 @@ case ${EAPI} in
  	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
  esac

-inherit dist-kernel-utils mount-boot multiprocessing toolchain-funcs
+inherit dist-kernel-utils mount-boot-utils multiprocessing toolchain-funcs

  SLOT="${PV}"
  IUSE="+initramfs test"
@@ -526,6 +524,10 @@ kernel-install_test() {
  kernel-install_pkg_pretend() {
  	debug-print-function ${FUNCNAME} "${@}"

+	# Check, but don't die because we can fix the problem and then
+	# emerge --config ... to re-run installation.
+	nonfatal mount-boot_check_status
+
  	if ! has_version -d sys-kernel/linux-firmware; then
  		ewarn "sys-kernel/linux-firmware not found installed on your system."
  		ewarn "This package provides various firmware files that may be needed"
@@ -665,27 +667,8 @@ kernel-install_install_all() {
  		fi
  	fi

-	local success=
-	# not an actual loop but allows error handling with 'break'
-	while :; do
-		nonfatal mount-boot_check_status || break
-
-		nonfatal dist-kernel_install_kernel "${module_ver}" \
-			"${kernel_dir}/${image_path}" "${kernel_dir}/System.map" || break
-
-		success=1
-		break
-	done
-
-	if [[ ! ${success} ]]; then
-		eerror
-		eerror "The kernel files were copied to disk successfully but the kernel"
-		eerror "was not deployed successfully.  Once you resolve the problems,"
-		eerror "please run the equivalent of the following command to try again:"
-		eerror
-		eerror "    emerge --config ${CATEGORY}/${PN}:${SLOT}"
-		die "Kernel install failed, please fix the problems and run emerge 
--config ${CATEGORY}/${PN}:${SLOT}"
-	fi
+	dist-kernel_install_kernel "${module_ver}" "${kernel_dir}/${image_path}" \
+		"${kernel_dir}/System.map"
  }

  # @FUNCTION: kernel-install_pkg_postinst
@@ -718,15 +701,6 @@ kernel-install_pkg_postinst() {
  	fi
  }

-# @FUNCTION: kernel-install_pkg_prerm
-# @DESCRIPTION:
-# Stub out mount-boot.eclass.
-kernel-install_pkg_prerm() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	# (no-op)
-}
-
  # @FUNCTION: kernel-install_pkg_postrm
  # @DESCRIPTION:
  # Clean up the generated initramfs from the removed kernel directory.
@@ -774,5 +748,5 @@ kernel-install_compress_modules() {

  fi

-EXPORT_FUNCTIONS src_test pkg_preinst pkg_postinst pkg_prerm pkg_postrm
+EXPORT_FUNCTIONS src_test pkg_preinst pkg_postinst pkg_postrm
  EXPORT_FUNCTIONS pkg_config pkg_pretend


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-dev] [PATCH 3/5] linux-mod-r1.eclass: check /boot if we are re-installing, dist-kernel
  2024-06-26 20:07     ` [gentoo-dev] [PATCH 2/5] kernel-install.eclass: move mount-boot check to, dist-kernel-utils.eclass Andrew Nowa Ammerlaan
@ 2024-06-26 20:08       ` Andrew Nowa Ammerlaan
  2024-06-26 20:08         ` [gentoo-dev] [PATCH 4/5] sys-kernel/linux-firmware: complain less when /boot is not, mounted Andrew Nowa Ammerlaan
  2024-06-27  4:07       ` [gentoo-dev] [PATCH 2/5] kernel-install.eclass: move mount-boot check to, dist-kernel-utils.eclass Ulrich Mueller
  1 sibling, 1 reply; 13+ messages in thread
From: Andrew Nowa Ammerlaan @ 2024-06-26 20:08 UTC (permalink / raw
  To: gentoo-dev

 From 3c5267472fb72223336063007173157a5de3f0cc Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
Date: Tue, 25 Jun 2024 16:15:05 +0200
Subject: [PATCH] linux-mod-r1.eclass: check /boot if we are re-installing
  dist-kernel

Previous commit already adds the check when we call
dist-kernel_reinstall_initramfs, but lets do it a bit earlier as well.

As in dist-kernel-utils.eclass, make the check nonfatal because when users
notice the problem they can correct it and manually re-install the 
kernel via
emerge --config ...

We don't have a pkg_pretend phase in this eclass, so we use the pkg_setup
phase instead to avoid introducing a new phase here.

Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
---
  eclass/linux-mod-r1.eclass | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/eclass/linux-mod-r1.eclass b/eclass/linux-mod-r1.eclass
index 43c5a7d7b140b..9911a6ddee123 100644
--- a/eclass/linux-mod-r1.eclass
+++ b/eclass/linux-mod-r1.eclass
@@ -132,6 +132,7 @@ IDEPEND="
  "

  if [[ ${MODULES_INITRAMFS_IUSE} ]]; then
+	inherit mount-boot-utils
  	IUSE+=" ${MODULES_INITRAMFS_IUSE}"
  	IDEPEND+="
  		${MODULES_INITRAMFS_IUSE#+}? (
@@ -328,9 +329,19 @@ fi
  #  3. perform various sanity checks to fail early on issues
  linux-mod-r1_pkg_setup() {
  	debug-print-function ${FUNCNAME[0]} "${@}"
-	[[ ${MERGE_TYPE} != binary ]] || return 0
  	_MODULES_GLOBAL[ran:pkg_setup]=1
  	_modules_check_function ${#} 0 0 || return 0
+
+	if [[ -z ${ROOT} && ${MODULES_INITRAMFS_IUSE} ]] &&
+		use dist-kernel && use ${MODULES_INITRAMFS_IUSE#+}
+	then
+		# Check, but don't die because we can fix the problem and then
+		# emerge --config ... to re-run installation.
+		nonfatal mount-boot_check_status
+	fi
+
+	[[ ${MERGE_TYPE} != binary ]] || return 0
+
  	_modules_check_migration

  	_modules_prepare_kernel



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-dev] [PATCH 4/5] sys-kernel/linux-firmware: complain less when /boot is not, mounted
  2024-06-26 20:08       ` [gentoo-dev] [PATCH 3/5] linux-mod-r1.eclass: check /boot if we are re-installing, dist-kernel Andrew Nowa Ammerlaan
@ 2024-06-26 20:08         ` Andrew Nowa Ammerlaan
  2024-06-26 20:09           ` [gentoo-dev] [PATCH 5/5] sys-firmware/intel-microcode: " Andrew Nowa Ammerlaan
  0 siblings, 1 reply; 13+ messages in thread
From: Andrew Nowa Ammerlaan @ 2024-06-26 20:08 UTC (permalink / raw
  To: gentoo-dev

 From 45a34aecafa64a666976e3d3d7944f8c8ff1e058 Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
Date: Tue, 25 Jun 2024 16:32:42 +0200
Subject: [PATCH] sys-kernel/linux-firmware: complain less when /boot is not
  mounted

when using dist-kernel we can correct the problem and then
emerge --config ...

Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
---
  .../linux-firmware-20240410.ebuild            | 21 +++++++++++++------
  .../linux-firmware-20240513.ebuild            | 21 +++++++++++++------
  .../linux-firmware-20240610.ebuild            | 21 +++++++++++++------
  .../linux-firmware-99999999.ebuild            | 21 +++++++++++++------
  4 files changed, 60 insertions(+), 24 deletions(-)

diff --git a/sys-kernel/linux-firmware/linux-firmware-20240410.ebuild 
b/sys-kernel/linux-firmware/linux-firmware-20240410.ebuild
index 1bb6954d00c88..b8bbed17f1a6d 100644
--- a/sys-kernel/linux-firmware/linux-firmware-20240410.ebuild
+++ b/sys-kernel/linux-firmware/linux-firmware-20240410.ebuild
@@ -69,7 +69,15 @@ QA_PREBUILT="*"
  PATCHES=( "${FILESDIR}"/${PN}-copy-firmware-r4.patch )

  pkg_pretend() {
-	use initramfs && mount-boot_pkg_pretend
+	if use initramfs; then
+		if [[ -z ${ROOT} ]] && use dist-kernel; then
+			# Check, but don't die because we can fix the problem and then
+			# emerge --config ... to re-run installation.
+			nonfatal mount-boot_check_status
+		else
+			mount-boot_pkg_pretend
+		fi
+	fi
  }

  pkg_setup() {
@@ -379,7 +387,7 @@ pkg_preinst() {
  	fi

  	# Make sure /boot is available if needed.
-	use initramfs && mount-boot_pkg_preinst
+	use initramfs && ! use dist-kernel && mount-boot_pkg_preinst
  }

  pkg_postinst() {
@@ -397,21 +405,22 @@ pkg_postinst() {
  		fi
  	done

-	# Don't forget to umount /boot if it was previously mounted by us.
  	if use initramfs; then
  		if [[ -z ${ROOT} ]] && use dist-kernel; then
  			dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+		else
+			# Don't forget to umount /boot if it was previously mounted by us.
+			mount-boot_pkg_postinst
  		fi
-		mount-boot_pkg_postinst
  	fi
  }

  pkg_prerm() {
  	# Make sure /boot is mounted so that we can remove /boot/amd-uc.img!
-	use initramfs && mount-boot_pkg_prerm
+	use initramfs && ! use dist-kernel && mount-boot_pkg_prerm
  }

  pkg_postrm() {
  	# Don't forget to umount /boot if it was previously mounted by us.
-	use initramfs && mount-boot_pkg_postrm
+	use initramfs && ! use dist-kernel && mount-boot_pkg_postrm
  }
diff --git a/sys-kernel/linux-firmware/linux-firmware-20240513.ebuild 
b/sys-kernel/linux-firmware/linux-firmware-20240513.ebuild
index 1bb6954d00c88..b8bbed17f1a6d 100644
--- a/sys-kernel/linux-firmware/linux-firmware-20240513.ebuild
+++ b/sys-kernel/linux-firmware/linux-firmware-20240513.ebuild
@@ -69,7 +69,15 @@ QA_PREBUILT="*"
  PATCHES=( "${FILESDIR}"/${PN}-copy-firmware-r4.patch )

  pkg_pretend() {
-	use initramfs && mount-boot_pkg_pretend
+	if use initramfs; then
+		if [[ -z ${ROOT} ]] && use dist-kernel; then
+			# Check, but don't die because we can fix the problem and then
+			# emerge --config ... to re-run installation.
+			nonfatal mount-boot_check_status
+		else
+			mount-boot_pkg_pretend
+		fi
+	fi
  }

  pkg_setup() {
@@ -379,7 +387,7 @@ pkg_preinst() {
  	fi

  	# Make sure /boot is available if needed.
-	use initramfs && mount-boot_pkg_preinst
+	use initramfs && ! use dist-kernel && mount-boot_pkg_preinst
  }

  pkg_postinst() {
@@ -397,21 +405,22 @@ pkg_postinst() {
  		fi
  	done

-	# Don't forget to umount /boot if it was previously mounted by us.
  	if use initramfs; then
  		if [[ -z ${ROOT} ]] && use dist-kernel; then
  			dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+		else
+			# Don't forget to umount /boot if it was previously mounted by us.
+			mount-boot_pkg_postinst
  		fi
-		mount-boot_pkg_postinst
  	fi
  }

  pkg_prerm() {
  	# Make sure /boot is mounted so that we can remove /boot/amd-uc.img!
-	use initramfs && mount-boot_pkg_prerm
+	use initramfs && ! use dist-kernel && mount-boot_pkg_prerm
  }

  pkg_postrm() {
  	# Don't forget to umount /boot if it was previously mounted by us.
-	use initramfs && mount-boot_pkg_postrm
+	use initramfs && ! use dist-kernel && mount-boot_pkg_postrm
  }
diff --git a/sys-kernel/linux-firmware/linux-firmware-20240610.ebuild 
b/sys-kernel/linux-firmware/linux-firmware-20240610.ebuild
index 1bb6954d00c88..b8bbed17f1a6d 100644
--- a/sys-kernel/linux-firmware/linux-firmware-20240610.ebuild
+++ b/sys-kernel/linux-firmware/linux-firmware-20240610.ebuild
@@ -69,7 +69,15 @@ QA_PREBUILT="*"
  PATCHES=( "${FILESDIR}"/${PN}-copy-firmware-r4.patch )

  pkg_pretend() {
-	use initramfs && mount-boot_pkg_pretend
+	if use initramfs; then
+		if [[ -z ${ROOT} ]] && use dist-kernel; then
+			# Check, but don't die because we can fix the problem and then
+			# emerge --config ... to re-run installation.
+			nonfatal mount-boot_check_status
+		else
+			mount-boot_pkg_pretend
+		fi
+	fi
  }

  pkg_setup() {
@@ -379,7 +387,7 @@ pkg_preinst() {
  	fi

  	# Make sure /boot is available if needed.
-	use initramfs && mount-boot_pkg_preinst
+	use initramfs && ! use dist-kernel && mount-boot_pkg_preinst
  }

  pkg_postinst() {
@@ -397,21 +405,22 @@ pkg_postinst() {
  		fi
  	done

-	# Don't forget to umount /boot if it was previously mounted by us.
  	if use initramfs; then
  		if [[ -z ${ROOT} ]] && use dist-kernel; then
  			dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+		else
+			# Don't forget to umount /boot if it was previously mounted by us.
+			mount-boot_pkg_postinst
  		fi
-		mount-boot_pkg_postinst
  	fi
  }

  pkg_prerm() {
  	# Make sure /boot is mounted so that we can remove /boot/amd-uc.img!
-	use initramfs && mount-boot_pkg_prerm
+	use initramfs && ! use dist-kernel && mount-boot_pkg_prerm
  }

  pkg_postrm() {
  	# Don't forget to umount /boot if it was previously mounted by us.
-	use initramfs && mount-boot_pkg_postrm
+	use initramfs && ! use dist-kernel && mount-boot_pkg_postrm
  }
diff --git a/sys-kernel/linux-firmware/linux-firmware-99999999.ebuild 
b/sys-kernel/linux-firmware/linux-firmware-99999999.ebuild
index dc02d051d7ea4..88c5398099a38 100644
--- a/sys-kernel/linux-firmware/linux-firmware-99999999.ebuild
+++ b/sys-kernel/linux-firmware/linux-firmware-99999999.ebuild
@@ -84,7 +84,15 @@ pkg_setup() {
  }

  pkg_pretend() {
-	use initramfs && mount-boot_pkg_pretend
+	if use initramfs; then
+		if [[ -z ${ROOT} ]] && use dist-kernel; then
+			# Check, but don't die because we can fix the problem and then
+			# emerge --config ... to re-run installation.
+			nonfatal mount-boot_check_status
+		else
+			mount-boot_pkg_pretend
+		fi
+	fi
  }

  src_unpack() {
@@ -379,7 +387,7 @@ pkg_preinst() {
  	fi

  	# Make sure /boot is available if needed.
-	use initramfs && mount-boot_pkg_preinst
+	use initramfs && ! use dist-kernel && mount-boot_pkg_preinst
  }

  pkg_postinst() {
@@ -397,21 +405,22 @@ pkg_postinst() {
  		fi
  	done

-	# Don't forget to umount /boot if it was previously mounted by us.
  	if use initramfs; then
  		if [[ -z ${ROOT} ]] && use dist-kernel; then
  			dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+		else
+			# Don't forget to umount /boot if it was previously mounted by us.
+			mount-boot_pkg_postinst
  		fi
-		mount-boot_pkg_postinst
  	fi
  }

  pkg_prerm() {
  	# Make sure /boot is mounted so that we can remove /boot/amd-uc.img!
-	use initramfs && mount-boot_pkg_prerm
+	use initramfs && ! use dist-kernel && mount-boot_pkg_prerm
  }

  pkg_postrm() {
  	# Don't forget to umount /boot if it was previously mounted by us.
-	use initramfs && mount-boot_pkg_postrm
+	use initramfs && ! use dist-kernel && mount-boot_pkg_postrm
  }



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-dev] [PATCH 5/5] sys-firmware/intel-microcode: complain less when /boot is not, mounted
  2024-06-26 20:08         ` [gentoo-dev] [PATCH 4/5] sys-kernel/linux-firmware: complain less when /boot is not, mounted Andrew Nowa Ammerlaan
@ 2024-06-26 20:09           ` Andrew Nowa Ammerlaan
  0 siblings, 0 replies; 13+ messages in thread
From: Andrew Nowa Ammerlaan @ 2024-06-26 20:09 UTC (permalink / raw
  To: gentoo-dev

 From c5cf62a41038e344312d8758a4ba232fcd726053 Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
Date: Tue, 25 Jun 2024 16:36:46 +0200
Subject: [PATCH] sys-firmware/intel-microcode: complain less when /boot 
is not
  mounted

When using dist-kernel users can correct the problem and then
emerge --config ...

Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
---
  .../intel-microcode-20240312_p20240312.ebuild | 21 +++++++++++++------
  .../intel-microcode-20240514_p20240514.ebuild | 21 +++++++++++++------
  .../intel-microcode-20240531_p20240526.ebuild | 21 +++++++++++++------
  3 files changed, 45 insertions(+), 18 deletions(-)

diff --git 
a/sys-firmware/intel-microcode/intel-microcode-20240312_p20240312.ebuild 
b/sys-firmware/intel-microcode/intel-microcode-20240312_p20240312.ebuild
index 957da662f92e3..5e2d305fc9ed6 100644
--- a/sys-firmware/intel-microcode/intel-microcode-20240312_p20240312.ebuild
+++ b/sys-firmware/intel-microcode/intel-microcode-20240312_p20240312.ebuild
@@ -83,7 +83,15 @@ MICROCODE_SIGNATURES_DEFAULT=""
  # exclude specific CPU: MICROCODE_SIGNATURES="-s !0x00000686"

  pkg_pretend() {
-	use initramfs && mount-boot_pkg_pretend
+	if use initramfs; then
+		if [[ -z ${ROOT} ]] && use dist-kernel; then
+			# Check, but don't die because we can fix the problem and then
+			# emerge --config ... to re-run installation.
+			nonfatal mount-boot_check_status
+		else
+			mount-boot_pkg_pretend
+		fi
+	fi
  }

  src_prepare() {
@@ -181,7 +189,7 @@ pkg_preinst() {
  	fi

  	# Make sure /boot is available if needed.
-	use initramfs && mount-boot_pkg_preinst
+	use initramfs && ! use dist-kernel && mount-boot_pkg_preinst

  	local _initramfs_file="${ED}/boot/intel-uc.img"

@@ -274,21 +282,22 @@ pkg_preinst() {

  pkg_prerm() {
  	# Make sure /boot is mounted so that we can remove /boot/intel-uc.img!
-	use initramfs && mount-boot_pkg_prerm
+	use initramfs && ! use dist-kernel && mount-boot_pkg_prerm
  }

  pkg_postrm() {
  	# Don't forget to umount /boot if it was previously mounted by us.
-	use initramfs && mount-boot_pkg_postrm
+	use initramfs && ! use dist-kernel && mount-boot_pkg_postrm
  }

  pkg_postinst() {
-	# Don't forget to umount /boot if it was previously mounted by us.
  	if use initramfs; then
  		if [[ -z ${ROOT} ]] && use dist-kernel; then
  			dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+		else
+			# Don't forget to umount /boot if it was previously mounted by us.
+			mount-boot_pkg_postinst
  		fi
-		mount-boot_pkg_postinst
  	fi

  	# We cannot give detailed information if user is affected or not:
diff --git 
a/sys-firmware/intel-microcode/intel-microcode-20240514_p20240514.ebuild 
b/sys-firmware/intel-microcode/intel-microcode-20240514_p20240514.ebuild
index c33321a94497a..656f5a519b913 100644
--- a/sys-firmware/intel-microcode/intel-microcode-20240514_p20240514.ebuild
+++ b/sys-firmware/intel-microcode/intel-microcode-20240514_p20240514.ebuild
@@ -83,7 +83,15 @@ MICROCODE_SIGNATURES_DEFAULT=""
  # exclude specific CPU: MICROCODE_SIGNATURES="-s !0x00000686"

  pkg_pretend() {
-	use initramfs && mount-boot_pkg_pretend
+	if use initramfs; then
+		if [[ -z ${ROOT} ]] && use dist-kernel; then
+			# Check, but don't die because we can fix the problem and then
+			# emerge --config ... to re-run installation.
+			nonfatal mount-boot_check_status
+		else
+			mount-boot_pkg_pretend
+		fi
+	fi
  }

  src_prepare() {
@@ -181,7 +189,7 @@ pkg_preinst() {
  	fi

  	# Make sure /boot is available if needed.
-	use initramfs && mount-boot_pkg_preinst
+	use initramfs && ! use dist-kernel && mount-boot_pkg_preinst

  	local _initramfs_file="${ED}/boot/intel-uc.img"

@@ -274,21 +282,22 @@ pkg_preinst() {

  pkg_prerm() {
  	# Make sure /boot is mounted so that we can remove /boot/intel-uc.img!
-	use initramfs && mount-boot_pkg_prerm
+	use initramfs && ! use dist-kernel && mount-boot_pkg_prerm
  }

  pkg_postrm() {
  	# Don't forget to umount /boot if it was previously mounted by us.
-	use initramfs && mount-boot_pkg_postrm
+	use initramfs && ! use dist-kernel && mount-boot_pkg_postrm
  }

  pkg_postinst() {
-	# Don't forget to umount /boot if it was previously mounted by us.
  	if use initramfs; then
  		if [[ -z ${ROOT} ]] && use dist-kernel; then
  			dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+		else
+			# Don't forget to umount /boot if it was previously mounted by us.
+			mount-boot_pkg_postinst
  		fi
-		mount-boot_pkg_postinst
  	fi

  	# We cannot give detailed information if user is affected or not:
diff --git 
a/sys-firmware/intel-microcode/intel-microcode-20240531_p20240526.ebuild 
b/sys-firmware/intel-microcode/intel-microcode-20240531_p20240526.ebuild
index c33321a94497a..656f5a519b913 100644
--- a/sys-firmware/intel-microcode/intel-microcode-20240531_p20240526.ebuild
+++ b/sys-firmware/intel-microcode/intel-microcode-20240531_p20240526.ebuild
@@ -83,7 +83,15 @@ MICROCODE_SIGNATURES_DEFAULT=""
  # exclude specific CPU: MICROCODE_SIGNATURES="-s !0x00000686"

  pkg_pretend() {
-	use initramfs && mount-boot_pkg_pretend
+	if use initramfs; then
+		if [[ -z ${ROOT} ]] && use dist-kernel; then
+			# Check, but don't die because we can fix the problem and then
+			# emerge --config ... to re-run installation.
+			nonfatal mount-boot_check_status
+		else
+			mount-boot_pkg_pretend
+		fi
+	fi
  }

  src_prepare() {
@@ -181,7 +189,7 @@ pkg_preinst() {
  	fi

  	# Make sure /boot is available if needed.
-	use initramfs && mount-boot_pkg_preinst
+	use initramfs && ! use dist-kernel && mount-boot_pkg_preinst

  	local _initramfs_file="${ED}/boot/intel-uc.img"

@@ -274,21 +282,22 @@ pkg_preinst() {

  pkg_prerm() {
  	# Make sure /boot is mounted so that we can remove /boot/intel-uc.img!
-	use initramfs && mount-boot_pkg_prerm
+	use initramfs && ! use dist-kernel && mount-boot_pkg_prerm
  }

  pkg_postrm() {
  	# Don't forget to umount /boot if it was previously mounted by us.
-	use initramfs && mount-boot_pkg_postrm
+	use initramfs && ! use dist-kernel && mount-boot_pkg_postrm
  }

  pkg_postinst() {
-	# Don't forget to umount /boot if it was previously mounted by us.
  	if use initramfs; then
  		if [[ -z ${ROOT} ]] && use dist-kernel; then
  			dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+		else
+			# Don't forget to umount /boot if it was previously mounted by us.
+			mount-boot_pkg_postinst
  		fi
-		mount-boot_pkg_postinst
  	fi

  	# We cannot give detailed information if user is affected or not:



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [gentoo-dev] [PATCH 1/5] mount-boot.eclass: check for ESP as well as /boot, split, eclass
  2024-06-26 20:06   ` [gentoo-dev] [PATCH 1/5] mount-boot.eclass: check for ESP as well as /boot, split, eclass Andrew Nowa Ammerlaan
  2024-06-26 20:07     ` [gentoo-dev] [PATCH 2/5] kernel-install.eclass: move mount-boot check to, dist-kernel-utils.eclass Andrew Nowa Ammerlaan
@ 2024-06-27  4:00     ` Ulrich Mueller
  2024-06-27 14:24       ` [gentoo-dev] [PATCH 1/5 v2] " Andrew Nowa Ammerlaan
  1 sibling, 1 reply; 13+ messages in thread
From: Ulrich Mueller @ 2024-06-27  4:00 UTC (permalink / raw
  To: Andrew Nowa Ammerlaan; +Cc: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 161 bytes --]

>>>>> On Wed, 26 Jun 2024, Andrew Nowa Ammerlaan wrote:

> +# @SUPPORTED_EAPIS: 6 7 8

AFAICS, no EAPI 6 ebuild inherits mount-boot, so EAPI 6 could be
dropped?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 507 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [gentoo-dev] [PATCH 2/5] kernel-install.eclass: move mount-boot check to, dist-kernel-utils.eclass
  2024-06-26 20:07     ` [gentoo-dev] [PATCH 2/5] kernel-install.eclass: move mount-boot check to, dist-kernel-utils.eclass Andrew Nowa Ammerlaan
  2024-06-26 20:08       ` [gentoo-dev] [PATCH 3/5] linux-mod-r1.eclass: check /boot if we are re-installing, dist-kernel Andrew Nowa Ammerlaan
@ 2024-06-27  4:07       ` Ulrich Mueller
  2024-06-27 14:26         ` [gentoo-dev] [PATCH 2/5 v2] " Andrew Nowa Ammerlaan
  1 sibling, 1 reply; 13+ messages in thread
From: Ulrich Mueller @ 2024-06-27  4:07 UTC (permalink / raw
  To: Andrew Nowa Ammerlaan; +Cc: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 5290 bytes --]

>>>>> On Wed, 26 Jun 2024, Andrew Nowa Ammerlaan wrote:

> --- a/eclass/dist-kernel-utils.eclass
> +++ b/eclass/dist-kernel-utils.eclass
> @@ -26,7 +26,7 @@ case ${EAPI} in
>  	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
>  esac
>  
> -inherit toolchain-funcs
> +inherit mount-boot-utils toolchain-funcs
>  
>  # @FUNCTION: dist-kernel_get_image_path
>  # @DESCRIPTION:
> @@ -79,11 +79,40 @@ dist-kernel_install_kernel() {
>  	local image=${2}
>  	local map=${3}
>  
> -	ebegin "Installing the kernel via installkernel"
> -	# note: .config is taken relatively to System.map;
> -	# initrd relatively to bzImage
> -	ARCH=$(tc-arch-kernel) installkernel "${version}" "${image}" "${map}"
> -	eend ${?} || die -n "Installing the kernel failed"
> +	local success=
> +	# not an actual loop but allows error handling with 'break'
> +	while :; do

IMHO "while true" would be better readable.

> +		nonfatal mount-boot_check_status || break
> +
> +		ebegin "Installing the kernel via installkernel"
> +		# note: .config is taken relatively to System.map;
> +		# initrd relatively to bzImage
> +		ARCH=$(tc-arch-kernel) installkernel "${version}"
> "${image}" "${map}" || break
> +		eend ${?} || die -n "Installing the kernel failed"
> +
> +		success=1
> +		break
> +	done
> +
> +	if [[ ! ${success} ]]; then
> +		# Try to read dist-kernel identifier to more accurately instruct users
> +		local kernel
> +		local k_id_file=${image%$(dist-kernel_get_image_path)}/dist-kernel
> +		if [[ -f ${k_id_file} ]]; then
> +			kernel=\'\=$(<${k_id_file})\'
> +		else
> +			# Fallback string if identifier is not found
> +			kernel="<name of your kernel pakcage>:<kernel version>"
> +		fi
> +
> +		eerror
> +		eerror "The kernel was not deployed successfully. Inspect the failure"
> +		eerror "in the logs above and once you resolve the problems please"
> +		eerror "run the equivalent of the following command to try again:"
> +		eerror
> +		eerror "    emerge --config ${kernel}"
> +		die "Kernel install failed, please fix the problems
> and run emerge --config"
> +	fi
>  }
>  
>  # @FUNCTION: dist-kernel_reinstall_initramfs
> diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass
> index f512d815fe098..a572597bc6fa3 100644
> --- a/eclass/kernel-install.eclass
> +++ b/eclass/kernel-install.eclass
> @@ -18,8 +18,6 @@
>  # location and System.map.
>  #
>  # The eclass exports src_test, pkg_postinst and pkg_postrm.
> -# Additionally, the inherited mount-boot eclass exports pkg_pretend.
> -# It also stubs out pkg_preinst and pkg_prerm defined by mount-boot.
>  
>  # @ECLASS_VARIABLE: KERNEL_IUSE_GENERIC_UKI
>  # @PRE_INHERIT
> @@ -50,7 +48,7 @@ case ${EAPI} in
>  	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
>  esac
>  
> -inherit dist-kernel-utils mount-boot multiprocessing toolchain-funcs
> +inherit dist-kernel-utils mount-boot-utils multiprocessing toolchain-funcs
>  
>  SLOT="${PV}"
>  IUSE="+initramfs test"
> @@ -526,6 +524,10 @@ kernel-install_test() {
>  kernel-install_pkg_pretend() {
>  	debug-print-function ${FUNCNAME} "${@}"
>  
> +	# Check, but don't die because we can fix the problem and then
> +	# emerge --config ... to re-run installation.
> +	nonfatal mount-boot_check_status
> +
>  	if ! has_version -d sys-kernel/linux-firmware; then
>  		ewarn "sys-kernel/linux-firmware not found installed on your system."
>  		ewarn "This package provides various firmware files that may be needed"
> @@ -665,27 +667,8 @@ kernel-install_install_all() {
>  		fi
>  	fi
>  
> -	local success=
> -	# not an actual loop but allows error handling with 'break'
> -	while :; do
> -		nonfatal mount-boot_check_status || break
> -
> -		nonfatal dist-kernel_install_kernel "${module_ver}" \
> -			"${kernel_dir}/${image_path}" "${kernel_dir}/System.map" || break
> -
> -		success=1
> -		break
> -	done
> -
> -	if [[ ! ${success} ]]; then
> -		eerror
> -		eerror "The kernel files were copied to disk successfully but the kernel"
> -		eerror "was not deployed successfully.  Once you resolve the problems,"
> -		eerror "please run the equivalent of the following command to try again:"
> -		eerror
> -		eerror "    emerge --config ${CATEGORY}/${PN}:${SLOT}"
> -		die "Kernel install failed, please fix the problems
>                  and run emerge --config ${CATEGORY}/${PN}:${SLOT}"
> -	fi
> +	dist-kernel_install_kernel "${module_ver}" "${kernel_dir}/${image_path}" \
> +		"${kernel_dir}/System.map"
>  }
>  
>  # @FUNCTION: kernel-install_pkg_postinst
> @@ -718,15 +701,6 @@ kernel-install_pkg_postinst() {
>  	fi
>  }
>  
> -# @FUNCTION: kernel-install_pkg_prerm
> -# @DESCRIPTION:
> -# Stub out mount-boot.eclass.
> -kernel-install_pkg_prerm() {
> -	debug-print-function ${FUNCNAME} "${@}"
> -
> -	# (no-op)
> -}
> -
>  # @FUNCTION: kernel-install_pkg_postrm
>  # @DESCRIPTION:
>  # Clean up the generated initramfs from the removed kernel directory.
> @@ -774,5 +748,5 @@ kernel-install_compress_modules() {
>  
>  fi
>  
> -EXPORT_FUNCTIONS src_test pkg_preinst pkg_postinst pkg_prerm pkg_postrm
> +EXPORT_FUNCTIONS src_test pkg_preinst pkg_postinst pkg_postrm
>  EXPORT_FUNCTIONS pkg_config pkg_pretend

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 507 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [gentoo-dev] [PATCH 1/5 v2] mount-boot.eclass: check for ESP as well as /boot, split, eclass
  2024-06-27  4:00     ` [gentoo-dev] [PATCH 1/5] mount-boot.eclass: check for ESP as well as /boot, split, eclass Ulrich Mueller
@ 2024-06-27 14:24       ` Andrew Nowa Ammerlaan
  2024-06-28  6:33         ` Ulrich Mueller
  0 siblings, 1 reply; 13+ messages in thread
From: Andrew Nowa Ammerlaan @ 2024-06-27 14:24 UTC (permalink / raw
  To: gentoo-dev

On 27/06/2024 06:00, Ulrich Mueller wrote:
> AFAICS, no EAPI 6 ebuild inherits mount-boot, so EAPI 6 could be
> dropped?

Yes, might as well drop that now. Here's v2:

 From 9f6e912237bf1f67b3bb5341e64449a6b02703bc Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
Date: Tue, 25 Jun 2024 15:08:49 +0200
Subject: [PATCH] mount-boot.eclass: check for ESP as well as /boot, split
  eclass

This eclass is used by when the dist-kernel has to re-installed.

Depending on the configuration of sys-kernel/installkernel, the files may be
installed to /boot or to the EFI System partition. Therefore, extend 
this eclass
to check if the ESP is mounted read-write as well on UEFI platforms.

Split off the main functions into a separate "inherit-safe" eclass so we can
safely use it in dist-kernel-utils.eclass and linux-mod-r1.eclass.

In the process we drop support for EAPI 6, since there are no EAPI 6 
consumers
left in ::gentoo.

Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
---
  eclass/mount-boot-utils.eclass | 109 +++++++++++++++++++++++++++++++++
  eclass/mount-boot.eclass       |  85 ++++---------------------
  2 files changed, 120 insertions(+), 74 deletions(-)
  create mode 100644 eclass/mount-boot-utils.eclass

diff --git a/eclass/mount-boot-utils.eclass b/eclass/mount-boot-utils.eclass
new file mode 100644
index 0000000000000..600b60a20d89d
--- /dev/null
+++ b/eclass/mount-boot-utils.eclass
@@ -0,0 +1,109 @@
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: mount-boot-utils.eclass
+# @MAINTAINER:
+# base-system@gentoo.org
+# @SUPPORTED_EAPIS: 6 7 8
+# @BLURB: functions for packages that install files into /boot or the ESP
+# @DESCRIPTION:
+# This eclass is really only useful for bootloaders and kernel 
installation.
+#
+# If the live system has a separate /boot partition or ESP configured, 
then this
+# function tries to ensure that it's mounted in rw mode, exiting with 
an error
+# if it can't.  It does nothing if /boot and ESP isn't a separate 
partition.
+#
+# This eclass provides the functions used by mount-boot.eclass in an 
"inherit-
+# safe" way. This allows these functions to be used in other eclasses 
cleanly.
+
+case ${EAPI} in
+	7|8) ;;
+	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+# @FUNCTION: mount-boot_is_disabled
+# @INTERNAL
+# @DESCRIPTION:
+# Detect whether the current environment/build settings are such that 
we do not
+# want to mess with any mounts.
+mount-boot_is_disabled() {
+	# Since this eclass only deals with /boot, skip things when EROOT is 
active.
+	if [[ ${EROOT:-/} != / ]] ; then
+		return 0
+	fi
+
+	# If we're only building a package, then there's no need to check things.
+	if [[ ${MERGE_TYPE} == buildonly ]] ; then
+		return 0
+	fi
+
+	# The user wants us to leave things be.
+	if [[ -n ${DONT_MOUNT_BOOT} ]] ; then
+		return 0
+	fi
+
+	# OK, we want to handle things ourselves.
+	return 1
+}
+
+# @FUNCTION: mount-boot_check_status
+# @INTERNAL
+# @DESCRIPTION:
+# Check if /boot and ESP is sane, i.e., mounted as read-write if on a 
separate
+# partition.  Die if conditions are not fulfilled.  If nonfatal is used,
+# the function will return a non-zero status instead.
+mount-boot_check_status() {
+	# Get out fast if possible.
+	mount-boot_is_disabled && return 0
+
+	local partition=
+	local part_is_not_mounted=
+	local part_is_read_only=
+	local candidates=( /boot )
+
+	# If system is booted with UEFI, check for ESP as well
+	if [[ -d /sys/firmware/efi ]]; then
+		# Use same candidates for ESP as installkernel and eclean-kernel
+		candidates+=( /efi /boot/efi /boot/EFI )
+	fi
+
+	for partition in ${candidates[@]}; do
+		# note that /dev/BOOT is in the Gentoo default /etc/fstab file
+		local fstabstate=$(awk "!/^[[:blank:]]*#|^\/dev\/BOOT/ && \$2 == 
\"${partition}\" \
+			{ print 1; exit }" /etc/fstab || die "awk failed")
+
+		if [[ -z ${fstabstate} ]] ; then
+			einfo "Assuming you do not have a separate ${partition} partition."
+		else
+			local procstate=$(awk "\$2 == \"${partition}\" { split(\$4, a, \",\"); \
+				for (i in a) if (a[i] ~ /^r[ow]\$/) { print a[i]; break }; exit }" \
+				/proc/mounts || die "awk failed")
+
+			if [[ -z ${procstate} ]] ; then
+				eerror "Your ${partition} partition is not mounted"
+				eerror "Please mount it and retry."
+				die -n "${partition} not mounted"
+				part_is_not_mounted=1
+			else
+				if [[ ${procstate} == ro ]] ; then
+					eerror "Your ${partition} partition, was detected as being mounted," \
+						"but is mounted read-only."
+					eerror "Please remount it as read-write and retry."
+					die -n "${partition} mounted read-only"
+					part_is_read_only=1
+				else
+					einfo "Your ${partition} partition was detected as being mounted."
+					einfo "Files will be installed there for ${PN} to function correctly."
+				fi
+			fi
+		fi
+	done
+
+	if [[ -n ${part_is_not_mounted} ]]; then
+		return 1
+	elif [[ -n ${part_is_read_only} ]]; then
+		return 2
+	else
+		return 0
+	fi
+}
diff --git a/eclass/mount-boot.eclass b/eclass/mount-boot.eclass
index 73beb9adea670..ab02b39d6141e 100644
--- a/eclass/mount-boot.eclass
+++ b/eclass/mount-boot.eclass
@@ -1,90 +1,27 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
  # Distributed under the terms of the GNU General Public License v2

  # @ECLASS: mount-boot.eclass
  # @MAINTAINER:
  # base-system@gentoo.org
  # @SUPPORTED_EAPIS: 6 7 8
-# @BLURB: functions for packages that install files into /boot
+# @BLURB: eclass for packages that install files into /boot or the ESP
  # @DESCRIPTION:
-# This eclass is really only useful for bootloaders.
+# This eclass is really only useful for bootloaders and kernel 
installation.
  #
-# If the live system has a separate /boot partition configured, then this
-# function tries to ensure that it's mounted in rw mode, exiting with an
-# error if it can't.  It does nothing if /boot isn't a separate partition.
+# If the live system has a separate /boot partition or ESP configured, 
then this
+# function tries to ensure that it's mounted in rw mode, exiting with 
an error
+# if it can't.  It does nothing if /boot and ESP isn't a separate 
partition.
+#
+# This eclass exports the functions provided by mount-boot-utils.eclass to
+# the pkg_pretend and pkg_{pre,post}{inst,rm} phases.

  case ${EAPI} in
-	6|7|8) ;;
+	7|8) ;;
  	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
  esac

-# @FUNCTION: mount-boot_is_disabled
-# @INTERNAL
-# @DESCRIPTION:
-# Detect whether the current environment/build settings are such that 
we do not
-# want to mess with any mounts.
-mount-boot_is_disabled() {
-	# Since this eclass only deals with /boot, skip things when EROOT is 
active.
-	if [[ ${EROOT:-/} != / ]] ; then
-		return 0
-	fi
-
-	# If we're only building a package, then there's no need to check things.
-	if [[ ${MERGE_TYPE} == buildonly ]] ; then
-		return 0
-	fi
-
-	# The user wants us to leave things be.
-	if [[ -n ${DONT_MOUNT_BOOT} ]] ; then
-		return 0
-	fi
-
-	# OK, we want to handle things ourselves.
-	return 1
-}
-
-# @FUNCTION: mount-boot_check_status
-# @INTERNAL
-# @DESCRIPTION:
-# Check if /boot is sane, i.e., mounted as read-write if on a separate
-# partition.  Die if conditions are not fulfilled.  If nonfatal is used,
-# the function will return a non-zero status instead.
-mount-boot_check_status() {
-	# Get out fast if possible.
-	mount-boot_is_disabled && return 0
-
-	# note that /dev/BOOT is in the Gentoo default /etc/fstab file
-	local fstabstate=$(awk '!/^[[:blank:]]*#|^\/dev\/BOOT/ && $2 == "/boot" \
-		{ print 1; exit }' /etc/fstab || die "awk failed")
-
-	if [[ -z ${fstabstate} ]] ; then
-		einfo "Assuming you do not have a separate /boot partition."
-		return 0
-	fi
-
-	local procstate=$(awk '$2 == "/boot" { split($4, a, ","); \
-		for (i in a) if (a[i] ~ /^r[ow]$/) { print a[i]; break }; exit }' \
-		/proc/mounts || die "awk failed")
-
-	if [[ -z ${procstate} ]] ; then
-		eerror "Your boot partition is not mounted at /boot."
-		eerror "Please mount it and retry."
-		die -n "/boot not mounted"
-		return 1
-	fi
-
-	if [[ ${procstate} == ro ]] ; then
-		eerror "Your boot partition, detected as being mounted at /boot," \
-			"is read-only."
-		eerror "Please remount it as read-write and retry."
-		die -n "/boot mounted read-only"
-		return 2
-	fi
-
-	einfo "Your boot partition was detected as being mounted at /boot."
-	einfo "Files will be installed there for ${PN} to function correctly."
-	return 0
-}
+inherit mount-boot-utils

  mount-boot_pkg_pretend() {
  	mount-boot_check_status



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [gentoo-dev] [PATCH 2/5 v2] kernel-install.eclass: move mount-boot check to, dist-kernel-utils.eclass
  2024-06-27  4:07       ` [gentoo-dev] [PATCH 2/5] kernel-install.eclass: move mount-boot check to, dist-kernel-utils.eclass Ulrich Mueller
@ 2024-06-27 14:26         ` Andrew Nowa Ammerlaan
  0 siblings, 0 replies; 13+ messages in thread
From: Andrew Nowa Ammerlaan @ 2024-06-27 14:26 UTC (permalink / raw
  To: Ulrich Mueller; +Cc: gentoo-dev

On 27/06/2024 06:07, Ulrich Mueller wrote:
> IMHO "while true" would be better readable.

Adjusted, here's v2:

 From 422fcc5fb53c3f2adf25256fb7d18a65e4036496 Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
Date: Tue, 25 Jun 2024 16:12:39 +0200
Subject: [PATCH] kernel-install.eclass: move mount-boot check to
  dist-kernel-utils.eclass

ebuilds and eclasses using dist-kernel_reinstall_initramfs should also
have the check for mounted /boot and ESP. We can do this safely via
mount-boot-utils.eclass which does not export any phases.

Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
---
  eclass/dist-kernel-utils.eclass | 39 ++++++++++++++++++++++++-----
  eclass/kernel-install.eclass    | 44 +++++++--------------------------
  2 files changed, 42 insertions(+), 41 deletions(-)

diff --git a/eclass/dist-kernel-utils.eclass 
b/eclass/dist-kernel-utils.eclass
index 13137f8c863c8..4bc3fab44aae9 100644
--- a/eclass/dist-kernel-utils.eclass
+++ b/eclass/dist-kernel-utils.eclass
@@ -26,7 +26,7 @@ case ${EAPI} in
  	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
  esac

-inherit toolchain-funcs
+inherit mount-boot-utils toolchain-funcs

  # @FUNCTION: dist-kernel_get_image_path
  # @DESCRIPTION:
@@ -79,11 +79,38 @@ dist-kernel_install_kernel() {
  	local image=${2}
  	local map=${3}

-	ebegin "Installing the kernel via installkernel"
-	# note: .config is taken relatively to System.map;
-	# initrd relatively to bzImage
-	ARCH=$(tc-arch-kernel) installkernel "${version}" "${image}" "${map}"
-	eend ${?} || die -n "Installing the kernel failed"
+	local success=
+	# not an actual loop but allows error handling with 'break'
+	while true; do
+		nonfatal mount-boot_check_status || break
+
+		ebegin "Installing the kernel via installkernel"
+		# note: .config is taken relatively to System.map;
+		# initrd relatively to bzImage
+		ARCH=$(tc-arch-kernel) installkernel "${version}" "${image}" "${map}" 
|| break
+		eend ${?} || die -n "Installing the kernel failed"
+
+		success=1
+		break
+	done
+
+	if [[ ! ${success} ]]; then
+		# Fallback string, if the identifier file is not found
+		local kernel="<name of your kernel pakcage>:<kernel version>"
+		# Try to read dist-kernel identifier to more accurately instruct users
+		local k_id_file=${image%$(dist-kernel_get_image_path)}/dist-kernel
+		if [[ -f ${k_id_file} ]]; then
+			kernel=\'\=$(<${k_id_file})\'
+		fi
+
+		eerror
+		eerror "The kernel was not deployed successfully. Inspect the failure"
+		eerror "in the logs above and once you resolve the problems please"
+		eerror "run the equivalent of the following command to try again:"
+		eerror
+		eerror "    emerge --config ${kernel}"
+		die "Kernel install failed, please fix the problems and run emerge 
--config"
+	fi
  }

  # @FUNCTION: dist-kernel_reinstall_initramfs
diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass
index f512d815fe098..77570a905ce11 100644
--- a/eclass/kernel-install.eclass
+++ b/eclass/kernel-install.eclass
@@ -17,9 +17,7 @@
  # /usr/src/linux-${PV} containing the kernel image in its standard
  # location and System.map.
  #
-# The eclass exports src_test, pkg_postinst and pkg_postrm.
-# Additionally, the inherited mount-boot eclass exports pkg_pretend.
-# It also stubs out pkg_preinst and pkg_prerm defined by mount-boot.
+# The eclass exports src_test, pkg_preinst, pkg_postinst and pkg_postrm.

  # @ECLASS_VARIABLE: KERNEL_IUSE_GENERIC_UKI
  # @PRE_INHERIT
@@ -50,7 +48,7 @@ case ${EAPI} in
  	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
  esac

-inherit dist-kernel-utils mount-boot multiprocessing toolchain-funcs
+inherit dist-kernel-utils mount-boot-utils multiprocessing toolchain-funcs

  SLOT="${PV}"
  IUSE="+initramfs test"
@@ -526,6 +524,10 @@ kernel-install_test() {
  kernel-install_pkg_pretend() {
  	debug-print-function ${FUNCNAME} "${@}"

+	# Check, but don't die because we can fix the problem and then
+	# emerge --config ... to re-run installation.
+	nonfatal mount-boot_check_status
+
  	if ! has_version -d sys-kernel/linux-firmware; then
  		ewarn "sys-kernel/linux-firmware not found installed on your system."
  		ewarn "This package provides various firmware files that may be needed"
@@ -665,27 +667,8 @@ kernel-install_install_all() {
  		fi
  	fi

-	local success=
-	# not an actual loop but allows error handling with 'break'
-	while :; do
-		nonfatal mount-boot_check_status || break
-
-		nonfatal dist-kernel_install_kernel "${module_ver}" \
-			"${kernel_dir}/${image_path}" "${kernel_dir}/System.map" || break
-
-		success=1
-		break
-	done
-
-	if [[ ! ${success} ]]; then
-		eerror
-		eerror "The kernel files were copied to disk successfully but the kernel"
-		eerror "was not deployed successfully.  Once you resolve the problems,"
-		eerror "please run the equivalent of the following command to try again:"
-		eerror
-		eerror "    emerge --config ${CATEGORY}/${PN}:${SLOT}"
-		die "Kernel install failed, please fix the problems and run emerge 
--config ${CATEGORY}/${PN}:${SLOT}"
-	fi
+	dist-kernel_install_kernel "${module_ver}" "${kernel_dir}/${image_path}" \
+		"${kernel_dir}/System.map"
  }

  # @FUNCTION: kernel-install_pkg_postinst
@@ -718,15 +701,6 @@ kernel-install_pkg_postinst() {
  	fi
  }

-# @FUNCTION: kernel-install_pkg_prerm
-# @DESCRIPTION:
-# Stub out mount-boot.eclass.
-kernel-install_pkg_prerm() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	# (no-op)
-}
-
  # @FUNCTION: kernel-install_pkg_postrm
  # @DESCRIPTION:
  # Clean up the generated initramfs from the removed kernel directory.
@@ -774,5 +748,5 @@ kernel-install_compress_modules() {

  fi

-EXPORT_FUNCTIONS src_test pkg_preinst pkg_postinst pkg_prerm pkg_postrm
+EXPORT_FUNCTIONS src_test pkg_preinst pkg_postinst pkg_postrm
  EXPORT_FUNCTIONS pkg_config pkg_pretend




^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [gentoo-dev] [PATCH 1/5 v2] mount-boot.eclass: check for ESP as well as /boot, split, eclass
  2024-06-27 14:24       ` [gentoo-dev] [PATCH 1/5 v2] " Andrew Nowa Ammerlaan
@ 2024-06-28  6:33         ` Ulrich Mueller
  2024-06-28  9:18           ` [gentoo-dev] [PATCH 1/5 v3] " Andrew Nowa Ammerlaan
  0 siblings, 1 reply; 13+ messages in thread
From: Ulrich Mueller @ 2024-06-28  6:33 UTC (permalink / raw
  To: Andrew Nowa Ammerlaan; +Cc: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 1083 bytes --]

>>>>> On Thu, 27 Jun 2024, Andrew Nowa Ammerlaan wrote:

> On 27/06/2024 06:00, Ulrich Mueller wrote:
>> AFAICS, no EAPI 6 ebuild inherits mount-boot, so EAPI 6 could be
>> dropped?

> Yes, might as well drop that now. Here's v2:

> +# @FUNCTION: mount-boot_is_disabled
> +# @INTERNAL
> +# @DESCRIPTION:
> +# Detect whether the current environment/build settings are such that
> we do not
> +# want to mess with any mounts.
> +mount-boot_is_disabled() {
> +	# Since this eclass only deals with /boot, skip things when
> EROOT is active.
> +	if [[ ${EROOT:-/} != / ]] ; then

This could be simplified to [[ -n ${EROOT} ]], because EROOT is
guaranteed not to end in a slash in EAPI 7 and later.

(Sorry, I had missed this one in v1.)

> +		return 0
> +	fi
> +
> +	# If we're only building a package, then there's no need to check things.
> +	if [[ ${MERGE_TYPE} == buildonly ]] ; then
> +		return 0
> +	fi
> +
> +	# The user wants us to leave things be.
> +	if [[ -n ${DONT_MOUNT_BOOT} ]] ; then
> +		return 0
> +	fi
> +
> +	# OK, we want to handle things ourselves.
> +	return 1
> +}

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 507 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [gentoo-dev] [PATCH 1/5 v3] mount-boot.eclass: check for ESP as well as /boot, split, eclass
  2024-06-28  6:33         ` Ulrich Mueller
@ 2024-06-28  9:18           ` Andrew Nowa Ammerlaan
  0 siblings, 0 replies; 13+ messages in thread
From: Andrew Nowa Ammerlaan @ 2024-06-28  9:18 UTC (permalink / raw
  To: gentoo-dev

On 28/06/2024 08:33, Ulrich Mueller wrote:
>>>>>> On Thu, 27 Jun 2024, Andrew Nowa Ammerlaan wrote:
> 
>> On 27/06/2024 06:00, Ulrich Mueller wrote:
>>> AFAICS, no EAPI 6 ebuild inherits mount-boot, so EAPI 6 could be
>>> dropped?
> 
>> Yes, might as well drop that now. Here's v2:
> 
> This could be simplified to [[ -n ${EROOT} ]], because EROOT is
> guaranteed not to end in a slash in EAPI 7 and later.
> 
> (Sorry, I had missed this one in v1.)
> 

Fixed! And also made the use of "]] ; then" versus "]]; then" consistent 
here.

 From bcbffbe3c691156e5e7d64dedf42fb5eb4dd02d0 Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
Date: Tue, 25 Jun 2024 15:08:49 +0200
Subject: [PATCH] mount-boot.eclass: check for ESP as well as /boot, split
  eclass

This eclass is used by when the dist-kernel has to re-installed.

Depending on the configuration of sys-kernel/installkernel, the files may be
installed to /boot or to the EFI System partition. Therefore, extend 
this eclass
to check if the ESP is mounted read-write as well on UEFI platforms.

Split off the main functions into a separate "inherit-safe" eclass so we can
safely use it in dist-kernel-utils.eclass and linux-mod-r1.eclass.

In the process we drop support for EAPI 6, since there are no EAPI 6 
consumers
left in ::gentoo.

Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
---
  eclass/mount-boot-utils.eclass | 109 +++++++++++++++++++++++++++++++++
  eclass/mount-boot.eclass       |  85 ++++---------------------
  2 files changed, 120 insertions(+), 74 deletions(-)
  create mode 100644 eclass/mount-boot-utils.eclass

diff --git a/eclass/mount-boot-utils.eclass b/eclass/mount-boot-utils.eclass
new file mode 100644
index 0000000000000..39f8e94b84ec7
--- /dev/null
+++ b/eclass/mount-boot-utils.eclass
@@ -0,0 +1,109 @@
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: mount-boot-utils.eclass
+# @MAINTAINER:
+# base-system@gentoo.org
+# @SUPPORTED_EAPIS: 6 7 8
+# @BLURB: functions for packages that install files into /boot or the ESP
+# @DESCRIPTION:
+# This eclass is really only useful for bootloaders and kernel 
installation.
+#
+# If the live system has a separate /boot partition or ESP configured, 
then this
+# function tries to ensure that it's mounted in rw mode, exiting with 
an error
+# if it can't.  It does nothing if /boot and ESP isn't a separate 
partition.
+#
+# This eclass provides the functions used by mount-boot.eclass in an 
"inherit-
+# safe" way. This allows these functions to be used in other eclasses 
cleanly.
+
+case ${EAPI} in
+	7|8) ;;
+	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+# @FUNCTION: mount-boot_is_disabled
+# @INTERNAL
+# @DESCRIPTION:
+# Detect whether the current environment/build settings are such that 
we do not
+# want to mess with any mounts.
+mount-boot_is_disabled() {
+	# Since this eclass only deals with /boot, skip things when EROOT is 
active.
+	if [[ -n ${EROOT} ]]; then
+		return 0
+	fi
+
+	# If we're only building a package, then there's no need to check things.
+	if [[ ${MERGE_TYPE} == buildonly ]]; then
+		return 0
+	fi
+
+	# The user wants us to leave things be.
+	if [[ -n ${DONT_MOUNT_BOOT} ]]; then
+		return 0
+	fi
+
+	# OK, we want to handle things ourselves.
+	return 1
+}
+
+# @FUNCTION: mount-boot_check_status
+# @INTERNAL
+# @DESCRIPTION:
+# Check if /boot and ESP is sane, i.e., mounted as read-write if on a 
separate
+# partition.  Die if conditions are not fulfilled.  If nonfatal is used,
+# the function will return a non-zero status instead.
+mount-boot_check_status() {
+	# Get out fast if possible.
+	mount-boot_is_disabled && return 0
+
+	local partition=
+	local part_is_not_mounted=
+	local part_is_read_only=
+	local candidates=( /boot )
+
+	# If system is booted with UEFI, check for ESP as well
+	if [[ -d /sys/firmware/efi ]]; then
+		# Use same candidates for ESP as installkernel and eclean-kernel
+		candidates+=( /efi /boot/efi /boot/EFI )
+	fi
+
+	for partition in ${candidates[@]}; do
+		# note that /dev/BOOT is in the Gentoo default /etc/fstab file
+		local fstabstate=$(awk "!/^[[:blank:]]*#|^\/dev\/BOOT/ && \$2 == 
\"${partition}\" \
+			{ print 1; exit }" /etc/fstab || die "awk failed")
+
+		if [[ -z ${fstabstate} ]]; then
+			einfo "Assuming you do not have a separate ${partition} partition."
+		else
+			local procstate=$(awk "\$2 == \"${partition}\" { split(\$4, a, \",\"); \
+				for (i in a) if (a[i] ~ /^r[ow]\$/) { print a[i]; break }; exit }" \
+				/proc/mounts || die "awk failed")
+
+			if [[ -z ${procstate} ]]; then
+				eerror "Your ${partition} partition is not mounted"
+				eerror "Please mount it and retry."
+				die -n "${partition} not mounted"
+				part_is_not_mounted=1
+			else
+				if [[ ${procstate} == ro ]]; then
+					eerror "Your ${partition} partition, was detected as being mounted," \
+						"but is mounted read-only."
+					eerror "Please remount it as read-write and retry."
+					die -n "${partition} mounted read-only"
+					part_is_read_only=1
+				else
+					einfo "Your ${partition} partition was detected as being mounted."
+					einfo "Files will be installed there for ${PN} to function correctly."
+				fi
+			fi
+		fi
+	done
+
+	if [[ -n ${part_is_not_mounted} ]]; then
+		return 1
+	elif [[ -n ${part_is_read_only} ]]; then
+		return 2
+	else
+		return 0
+	fi
+}
diff --git a/eclass/mount-boot.eclass b/eclass/mount-boot.eclass
index 73beb9adea670..ab02b39d6141e 100644
--- a/eclass/mount-boot.eclass
+++ b/eclass/mount-boot.eclass
@@ -1,90 +1,27 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
  # Distributed under the terms of the GNU General Public License v2

  # @ECLASS: mount-boot.eclass
  # @MAINTAINER:
  # base-system@gentoo.org
  # @SUPPORTED_EAPIS: 6 7 8
-# @BLURB: functions for packages that install files into /boot
+# @BLURB: eclass for packages that install files into /boot or the ESP
  # @DESCRIPTION:
-# This eclass is really only useful for bootloaders.
+# This eclass is really only useful for bootloaders and kernel 
installation.
  #
-# If the live system has a separate /boot partition configured, then this
-# function tries to ensure that it's mounted in rw mode, exiting with an
-# error if it can't.  It does nothing if /boot isn't a separate partition.
+# If the live system has a separate /boot partition or ESP configured, 
then this
+# function tries to ensure that it's mounted in rw mode, exiting with 
an error
+# if it can't.  It does nothing if /boot and ESP isn't a separate 
partition.
+#
+# This eclass exports the functions provided by mount-boot-utils.eclass to
+# the pkg_pretend and pkg_{pre,post}{inst,rm} phases.

  case ${EAPI} in
-	6|7|8) ;;
+	7|8) ;;
  	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
  esac

-# @FUNCTION: mount-boot_is_disabled
-# @INTERNAL
-# @DESCRIPTION:
-# Detect whether the current environment/build settings are such that 
we do not
-# want to mess with any mounts.
-mount-boot_is_disabled() {
-	# Since this eclass only deals with /boot, skip things when EROOT is 
active.
-	if [[ ${EROOT:-/} != / ]] ; then
-		return 0
-	fi
-
-	# If we're only building a package, then there's no need to check things.
-	if [[ ${MERGE_TYPE} == buildonly ]] ; then
-		return 0
-	fi
-
-	# The user wants us to leave things be.
-	if [[ -n ${DONT_MOUNT_BOOT} ]] ; then
-		return 0
-	fi
-
-	# OK, we want to handle things ourselves.
-	return 1
-}
-
-# @FUNCTION: mount-boot_check_status
-# @INTERNAL
-# @DESCRIPTION:
-# Check if /boot is sane, i.e., mounted as read-write if on a separate
-# partition.  Die if conditions are not fulfilled.  If nonfatal is used,
-# the function will return a non-zero status instead.
-mount-boot_check_status() {
-	# Get out fast if possible.
-	mount-boot_is_disabled && return 0
-
-	# note that /dev/BOOT is in the Gentoo default /etc/fstab file
-	local fstabstate=$(awk '!/^[[:blank:]]*#|^\/dev\/BOOT/ && $2 == "/boot" \
-		{ print 1; exit }' /etc/fstab || die "awk failed")
-
-	if [[ -z ${fstabstate} ]] ; then
-		einfo "Assuming you do not have a separate /boot partition."
-		return 0
-	fi
-
-	local procstate=$(awk '$2 == "/boot" { split($4, a, ","); \
-		for (i in a) if (a[i] ~ /^r[ow]$/) { print a[i]; break }; exit }' \
-		/proc/mounts || die "awk failed")
-
-	if [[ -z ${procstate} ]] ; then
-		eerror "Your boot partition is not mounted at /boot."
-		eerror "Please mount it and retry."
-		die -n "/boot not mounted"
-		return 1
-	fi
-
-	if [[ ${procstate} == ro ]] ; then
-		eerror "Your boot partition, detected as being mounted at /boot," \
-			"is read-only."
-		eerror "Please remount it as read-write and retry."
-		die -n "/boot mounted read-only"
-		return 2
-	fi
-
-	einfo "Your boot partition was detected as being mounted at /boot."
-	einfo "Files will be installed there for ${PN} to function correctly."
-	return 0
-}
+inherit mount-boot-utils

  mount-boot_pkg_pretend() {
  	mount-boot_check_status



^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-06-28  9:19 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-26 19:09 [gentoo-dev] [PATCH] kernel-build.eclass: identify dist-kernels, and warn users Andrew Nowa Ammerlaan
2024-06-26 20:06 ` [gentoo-dev] [PATCH 0/5] mount-boot.eclass: revises /boot checking for dist-kernels, add checks for ESP Andrew Nowa Ammerlaan
2024-06-26 20:06   ` [gentoo-dev] [PATCH 1/5] mount-boot.eclass: check for ESP as well as /boot, split, eclass Andrew Nowa Ammerlaan
2024-06-26 20:07     ` [gentoo-dev] [PATCH 2/5] kernel-install.eclass: move mount-boot check to, dist-kernel-utils.eclass Andrew Nowa Ammerlaan
2024-06-26 20:08       ` [gentoo-dev] [PATCH 3/5] linux-mod-r1.eclass: check /boot if we are re-installing, dist-kernel Andrew Nowa Ammerlaan
2024-06-26 20:08         ` [gentoo-dev] [PATCH 4/5] sys-kernel/linux-firmware: complain less when /boot is not, mounted Andrew Nowa Ammerlaan
2024-06-26 20:09           ` [gentoo-dev] [PATCH 5/5] sys-firmware/intel-microcode: " Andrew Nowa Ammerlaan
2024-06-27  4:07       ` [gentoo-dev] [PATCH 2/5] kernel-install.eclass: move mount-boot check to, dist-kernel-utils.eclass Ulrich Mueller
2024-06-27 14:26         ` [gentoo-dev] [PATCH 2/5 v2] " Andrew Nowa Ammerlaan
2024-06-27  4:00     ` [gentoo-dev] [PATCH 1/5] mount-boot.eclass: check for ESP as well as /boot, split, eclass Ulrich Mueller
2024-06-27 14:24       ` [gentoo-dev] [PATCH 1/5 v2] " Andrew Nowa Ammerlaan
2024-06-28  6:33         ` Ulrich Mueller
2024-06-28  9:18           ` [gentoo-dev] [PATCH 1/5 v3] " Andrew Nowa Ammerlaan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox