public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Andrew Nowa Ammerlaan <andrewammerlaan@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Subject: Re: [gentoo-dev] [PATCH 1/5 v3] mount-boot.eclass: check for ESP as well as /boot, split, eclass
Date: Fri, 28 Jun 2024 11:18:53 +0200	[thread overview]
Message-ID: <2332e779-0107-4f75-94b9-8a63f45c0a1e@gentoo.org> (raw)
In-Reply-To: <ur0chfug1@gentoo.org>

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



      reply	other threads:[~2024-06-28  9:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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           ` Andrew Nowa Ammerlaan [this message]

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=2332e779-0107-4f75-94b9-8a63f45c0a1e@gentoo.org \
    --to=andrewammerlaan@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox