[gentoo-dev] 2024-02-26-debianutils-drops-installkernel-dep: add news item

2024-02-26 Thread Andrew Nowa Ammerlaan
This draft news item accompanies: 
https://github.com/gentoo/gentoo/pull/35533


Random packages requiring some tool from Debian should not cause the 
kernel installation process to change.


The dropping of the debianutils dependency in ca-certificates has 
already caused some surprises due to installkernel being depcleaned. The 
origin of the problem lies here in debianutils, users unknowingly use 
and rely on installkernel but do not have it in their world file because 
it was implicitly pulled in by some package that happens to use the 
run-parts command.


And also the other way around. If I am one of the users that wants to do 
everything manually, I should not have my 'make install' unknowingly 
altered by some package that I installed which pulled debianutils into 
the depgraph.


Drop this unused runtime dependency (which is against policy to begin 
with) and its accompanying flag.

This will be accompanied with the following news item:


Title: installkernel is no longer implicitly installed
Author: Andrew Ammerlaan 
Posted: 2024-02-26
Revision: 1
News-Item-Format: 2.0
Display-If-Installed: sys-kernel/installkernel
Display-If-Installed: >=sys-apps/debianutils-5.14-r1
Display-If-Installed: app-misc/ca-certificates

/sbin/installkernel is a script called by the kernels 'make install' as well
as by the distribution kernels post install phase. If you are reading this
then chances are you use and rely on installkernel and what follows is
essential for you.

Previously sys-kernel/installkernel was implicitly installed on many systems
via a dependency in sys-apps/debianutils. This dependency was toggled
by the "installkernel" USE flag, and enabled by default.

sys-apps/debianutils was in turn pulled in by app-misc/ca-certificates,
an essential package installed on many systems. However, this
dependency was recently removed. As a result many users may find that
sys-apps/debianutils and therefore sys-kernel/installkernel are no longer
part of the dependency graph and will therefore be cleaned up by
'emerge --depclean'.

Removing sys-kernel/installkernel from your system WILL change the
way kernels are installed by 'make install'! Instead of the versioned
/boot/vmlinuz-x.y.z that you are used to, 'make install' will simply
copy bzImage (or equivalent for you arch) into /boot. This image
may not be picked up by your bootloader or its configuration tools.

To avoid surprises from such implicit dependencies from happening
again in the future, the dependency on sys-kernel/installkernel in
sys-apps/debianutils is removed. And as such sys-kernel/installkernel
is only installed on the system if it is either explicitly selected or
pulled in via the distribution kernels (e.g. gentoo-kernel(-bin)).


User Action Required (all users)


Users who currently have sys-kernel/installkernel installed, must
ensure that it is explicitly selected by explicitly emerging it:

emerge --noreplace sys-kernel/installkernel

Users who find that sys-kernel/installkernel has already been
cleaned from their systems and are therefore effected by
the change in kernel installation described above should
re-install sys-kernel/installkernel and then re-install their
kernel.

emerge sys-kernel/installkernel
cd /usr/src/linux (or other location of the kernel sources)
make install

Note that this re-installation is not required for users of the
distribution kernels (e.g. gentoo-kernel(-bin)).


See also: https://wiki.gentoo.org/wiki/Installkernel



Re: [gentoo-dev] 2024-02-26-debianutils-drops-installkernel-dep: add news item

2024-02-26 Thread Andrew Nowa Ammerlaan

On 27/02/2024 03:28, Oskari Pirhonen wrote:

On Mon, Feb 26, 2024 at 22:39:13 +, Lucio Sauer wrote:

On Mon, Feb 26, 2024 at 06:13:32PM +0100, Andrew Nowa Ammerlaan wrote:

Previously sys-kernel/installkernel was implicitly installed on many systems
via a dependency in sys-apps/debianutils. This dependency was toggled
by the "installkernel" USE flag, and enabled by default.

sys-apps/debianutils was in turn pulled in by app-misc/ca-certificates,
an essential package installed on many systems. However, this
dependency was recently removed.


In my opinion, the last sentence reads as if app-misc/ca-certificates was
recently removed. I suggest rewording the passage as follows:

Until recently, sys-apps/debianutils was in turn pulled in by
app-misc/ca-certificates, an essential package installed on many systems.
This is no longer the case.


As a result many users may find that ...




Agreed. I was confused for a second reading it since it was the first
I'd heard of ca-certificates being removed before I realized that was
not the case at all.

- Oskari



Yes I see how this wording can be confusing. Fixed locally and in the 
GitHub PR, Thanks.


Best regards,
Andrew



Re: [gentoo-dev] Re: 2024-02-26-debianutils-drops-installkernel-dep: add news item

2024-02-26 Thread Andrew Nowa Ammerlaan

On 27/02/2024 04:55, Duncan wrote:

Andrew Nowa Ammerlaan posted on Mon, 26 Feb 2024 18:13:32 +0100 as
excerpted:


Removing sys-kernel/installkernel from your system WILL change the way
kernels are installed by 'make install'! Instead of the versioned
/boot/vmlinuz-x.y.z that you are used to, 'make install' will simply
copy bzImage (or equivalent for you arch) into /boot. This image may not
be picked up by your bootloader or its configuration tools.


I'm uncomfortable with that unconditional, "SHOUTED" even, "WILL".

That isn't the case here -- I've been getting versioned images without the
debianutils-based installkernel script for years.


I'm going to disagree here, this *is* the case. If you have it installed 
and remove it, then the way the kernel is installed will change.


The point is that I have seen *many* users on our various support 
channels that thought they either:
- did not use installkernel before when they actually did and therefore 
disregard the instructions in the news item, or
- thought the news item did not apply to them because they misunderstand 
what 'make install' does, and therefore disregard essential instructions 
in the news item, or
- complain that they don't want automation, when they have in fact been 
using this tool for ages. Then remove installkernel.


Such misunderstandings can, and have, lead to systems breaking. I do not 
want this to happen again and therefore I want it to be very clear that 
if you remove installkernel that this will change things for you.



I long ago (when installkernel was still part of debianutils according to
comments in my version, presumably the debianutils default-enabled USE was
set when it was split out to avoid just this sort of surprise at that
time) created my own version based on the debianutils version, but
bashified/comment-and-var-name-clarified and with a config file that
determines various behavior (along with behavior for my other kernel-
related build/patch/config/etc scripts). 


Yes sure, you can make your own /sbin/installkernel. And that means you 
don't have sys-kernel/installkernel installed and therefore none of this 
applies to you.


But for users that do have it installed now, and have it depcleaned, 
behavior is changed always. It is therefore not a case of "will likely" 
because it will always.


As a side note, latest version of installkernel also supports reading a 
config (install.conf), not sure if this suits your needs but might be 
worth to check out.



Maybe "will likely", or "will, unless you've specifically configured other
behavior", or "will, unless you've previously setup your own solution"?
("Will" can then be SHOUTED or not, as desired, because the statement is
then sufficiently conditional regardless.)


If you have setup your own solution, then you a) don't have this package 
installed to begin with, and b) clearly know what you are doing. This 
news item is for those users that a) do currently have installkernel 
installed and b) often don't know the intricacies of what 'make install' 
and installkernel do.


Best regards,
Andrew




Re: [gentoo-dev] 2024-02-26-debianutils-drops-installkernel-dep: add news item v2

2024-02-26 Thread Andrew Nowa Ammerlaan

On 27/02/2024 07:26, Ulrich Mueller wrote:

On Mon, 26 Feb 2024, Andrew Nowa Ammerlaan wrote:



Title: installkernel is no longer implicitly installed
Author: Andrew Ammerlaan 
Posted: 2024-02-26
Revision: 1
News-Item-Format: 2.0
Display-If-Installed: sys-kernel/installkernel
Display-If-Installed: >=sys-apps/debianutils-5.14-r1
Display-If-Installed: app-misc/ca-certificates


I have only some small remarks about spelling and style:


Thanks for your comments. Here's version 2:

Title: installkernel is no longer implicitly installed
Author: Andrew Ammerlaan 
Posted: 2024-02-26
Revision: 1
News-Item-Format: 2.0
Display-If-Installed: sys-kernel/installkernel
Display-If-Installed: >=sys-apps/debianutils-5.14-r1
Display-If-Installed: app-misc/ca-certificates

/sbin/installkernel is a script called by the kernel's "make install"
as well as by the distribution kernel's post-install phase. If you are
reading this then chances are you use and rely on installkernel[1] and
what follows is essential for you.

Previously sys-kernel/installkernel was implicitly installed on many
systems via a dependency in sys-apps/debianutils. This dependency was
toggled by the "installkernel" USE flag, and enabled by default.

Until recently, sys-apps/debianutils was in turn pulled in by
app-misc/ca-certificates, an essential package installed on many
systems. This is no longer the case.[2]. As a result many users may find
that sys-apps/debianutils and therefore sys-kernel/installkernel are no
longer part of the dependency graph and will therefore be cleaned up by
"emerge --depclean".

Removing sys-kernel/installkernel from your system WILL change the way
kernels are installed by "make install"! Instead of the versioned
/boot/vmlinuz-x.y.z that you are used to, "make install" will simply
copy bzImage (or equivalent for your arch) into /boot. This image may
not be picked up by your bootloader or its configuration tools.

To avoid surprises from such implicit dependencies from happening again
in the future, the dependency on sys-kernel/installkernel in
sys-apps/debianutils is removed. And as such, sys-kernel/installkernel
is only installed on the system if it is either explicitly selected or
pulled in via the distribution kernels (e.g. gentoo-kernel(-bin)).


User Action Required (all users)


Users who currently have sys-kernel/installkernel installed, must
ensure that it is explicitly selected by emerging it:

emerge --noreplace sys-kernel/installkernel

Users who find that sys-kernel/installkernel has already been cleaned
from their systems and are therefore effected by the change in kernel
installation described above should re-install sys-kernel/installkernel
and then re-install their kernel.

emerge sys-kernel/installkernel
cd /usr/src/linux   # (or other location of the kernel sources)
make install

Note that this re-installation is not required for users of the
distribution kernels (e.g. gentoo-kernel(-bin)).


[1] https://wiki.gentoo.org/wiki/Installkernel
[2] 
https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6e6ccafd58bc7401fa371d2f255d72ddae0131e6







Re: [gentoo-dev] 2024-02-26-debianutils-drops-installkernel-dep: add news item v2

2024-02-28 Thread Andrew Nowa Ammerlaan

On 27/02/2024 18:24, Hank Leininger wrote:

On 2024-02-27, andrewammerlaan wrote:


Until recently, sys-apps/debianutils was in turn pulled in by
app-misc/ca-certificates, an essential package installed on many
systems. This is no longer the case.[2]. As a result many users may find
that sys-apps/debianutils and therefore sys-kernel/installkernel are no
longer part of the dependency graph and will therefore be cleaned up by
"emerge --depclean".


Sorry for speaking up late: I (mis)read the second sentence differently
from others in this thread, apparently.

"This is no longer the case." might apply to the first part of the
previous sentence, "was in turn pulled in by".

Or it might apply to the second part, "an essential package installed on
many systems."

I think what's meant is the former, it is no longer pulled in. But
someone reading this cold could be forgiven for reading that as
"ca-certificates is no longer an essential package".

Unfortunately my recommendation would be to restore the mention of a
dependency, in some form or fashion, which seems to be something that
was removed due to earlier feedback in this thread.

Maybe:

Until recently, sys-apps/debianutils was in turn pulled in by
app-misc/ca-certificates, an essential package installed on many
systems. That package no longer depends on sys-apps/debianutils.  As a
result many users may find that sys-apps/debianutils and therefore
sys-kernel/installkernel are no longer part of the dependency graph and
will therefore be cleaned up by "emerge --depclean".


I rewrote this paragraph like this:

Until recently, sys-apps/debianutils was in turn pulled in by
app-misc/ca-certificates, an essential package installed on many
systems. However, this dependency of app-misc/ca-certificates on
sys-apps/debianutils was removed[2]. As a result many users may find
that sys-apps/debianutils and therefore sys-kernel/installkernel are no
longer part of the dependency graph and will therefore be cleaned up by
"emerge --depclean".

I think this way it should be very clear what has changed to cause the 
problem.


Best regards,
Andrew



[gentoo-dev] Last rites: dev-python/anyqt

2024-03-09 Thread Andrew Nowa Ammerlaan

# Andrew Ammerlaan  (2024-03-09)
# Requires pyside2/shiboken2, which is unmaintained upstream and
# not compatible with llvm-16 and up or python-3.12 and up.
# No upstream activity for 2 years.
# dev-python/QtPy is an alternative that does support Qt6.
# Removal on: 2024-04-09.  Bug #926548
dev-python/anyqt



[gentoo-dev] Last rites: sci-libs/scikit-optimize

2024-03-10 Thread Andrew Nowa Ammerlaan

# Andrew Ammerlaan  (2024-03-10)
# Archived upstream, latest release is 3 years old. One test
# failure with python 3.11, more with python 3.12.
# Removal on: 2024-04-10.  Bug #920439
sci-libs/scikit-optimize



[gentoo-dev] Last-rites: sci-visualization/spectromatic

2024-04-18 Thread Andrew Nowa Ammerlaan

# Andrew Ammerlaan  (2024-04-18)
# Upstream gone, unfetchable, stuck on EAPI 6. Bug 605796
# Removal on 2024-05-18
sci-visualization/spectromatic



[gentoo-dev] [PATCH 0/7] Changes to dracut kernel module/microcode handling

2024-05-14 Thread Andrew Nowa Ammerlaan

Hi all,

This patch series essential moves the dist-kernel initramfs/UKI 
rebuilding out off zfs-kmod.ebuild and into linux-mod-r1.eclass.


In the process we fix several issues:
- zfs-kmod.ebuild binpkgs no longer rebuild currently running kernel, 
but uses instead the kernel version that matches the version the modules 
were built for (Bug 931213, commit 1,2,3,6,7).
- zfs.ebuild binpkgs no longer rebuild currently running kernel, but use 
the eselected kernel instead (commit 6,7). In most "normal" cases the 
eselected kernel version will match the kernel version zfs-kmod modules 
were built for due to the slot operator on the virtual/dist-kernel 
dependency in both ebuilds, and the automatic adjustments of the 
/usr/src/linux symlink when dist-kernels are used. (TODO: consider 
merging the zfs and zfs-kmod ebuilds to make this 100% robust).
- Which modules are and which ones are not included in the Dracut 
generated initramfs is now properly defined and won't change after 
random dist-kernel reinstallations (commit 1,2).
- As a result of the above, Dracut's "--reproducible" setting actually 
makes something that is reproducible (apart from package upgrades and 
configuration changes of course).
- It is now super easy for kernel module package maintainers to define 
that a module can be included in the initramfs, USE flags and 
(initramfs/UKI) rebuilds are taken care off by the eclass (commits 1,2)
- We mirror the changes to the kernel modules in the packages that 
install CPU microcode (linux-firmware and intel-microcode) by 
introducing the "dist-kernel" flag there which alters the behaviour of 
the "initramfs" flag to instead configure Dracut to include the 
microcode and then rebuild the Dracut initramfs/UKI. This ensures that 
microcode updates are always propagated into the initramfs. (commits 4,5)


Most users will not have to do anything, we are only setting defaults in 
/usr/lib/dracut/dracut.conf.d, the (existing) user configuration in 
/etc/dracut.conf.d takes precedence. Nonetheless, I wrote a news item to 
accompany these changes, users should ensure that they do not 
unintentionally overwrite USE=initramfs, and they may also want to get 
rid of custom configuration/workarounds they have set in /etc/dracut.conf.


Best regards,
Andrew


Title: Changes to dracut kernel module/microcode handling
Author: Andrew Ammerlaan 
Posted: 2024-05-10
Revision: 1
News-Item-Format: 2.0
Display-If-Installed: sys-kernel/dracut
Display-If-Installed: virtual/dist-kernel
Display-If-Installed: sys-kernel/linux-firmware
Display-If-Installed: sys-firmware/intel-microcode


Impact


Several changes were made regarding out-of-tree kernel modules, CPU
microcode, and how these are handled in initial RAM file systems
(initramfs) generated by sys-kernel/dracut for distribution kernels.
Depending on the local Dracut and USE flag configuration, some
configuration adjustments may be required as a result of these changes.

Background (the problem)


Previously Dracut implicitly included all out-of-tree kernel modules
it could find. This leads to several problems:
- It unnecessarily increases the size of the initramfs
- It creates a bit of a mess when using distribution kernels, consider
the following:
1) Distribution kernel is upgraded
2) Initramfs for the new kernel is generated, it does not 
include
any out-of-tree kernel modules.
3) Portage triggers rebuild of the out-of-tree kernel modules
4) If zfs is installed, its rebuild will trigger an initramfs
re-installation. Otherwise no rebuild is triggered.
Problem: What is and is not included in the initramfs is now
ambiguous. It depends on the emerge order of the kernel modules
when zfs is used. And will completely change if at some later stage
regeneration of the initramfs is triggered manually via e.g.:
emerge --config sys-kernel/gentoo-kernel
As a result, Dracut's "--reproducible" setting is not working. And
the functionality of the initramfs may change (seemingly) at random.

Background (the fix)


Several things have been changed:
- Out-of-tree kernel modules installed by portage are explicitly omitted
from the initramfs generated by Dracut by default.
- Packages that install a kernel module for which it might make sense to
have it in the initramfs, have gained the "initramfs" USE flag. When
this flag is enabled, Dracut is instructed to include the installed
kernel modules. Packages for which it is essential that its kernel
modules are included in the initramfs have this new flag enabled
by default.
- When distribution kernels are used (USE=dist-kernel), and a module
that should be in the initramfs is installed (USE=initramfs) the
initramfs is always re-generated.
- 

[gentoo-dev] [PATCH] kernel-build.eclass: identify dist-kernels, and warn users

2024-06-26 Thread Andrew Nowa Ammerlaan

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

From c88eee66089333fbcee6377b5f580e70a4ec2a8c Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan 
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 
---
 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"




[gentoo-dev] [PATCH 0/5] mount-boot.eclass: revises /boot checking for dist-kernels, add checks for ESP

2024-06-26 Thread Andrew Nowa Ammerlaan

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.





[gentoo-dev] [PATCH 1/5] mount-boot.eclass: check for ESP as well as /boot, split, eclass

2024-06-26 Thread Andrew Nowa Ammerlaan

From 53f844361df57d480480b5e0ab0f35d2788ebf6a Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan 
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 
---
 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 0..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-sys...@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."
+

Re: [gentoo-dev] [PATCH 2/5] kernel-install.eclass: move mount-boot check to, dist-kernel-utils.eclass

2024-06-26 Thread Andrew Nowa Ammerlaan

From c4c5ef732670f8b23f20b1215af49cdceacd28a3 Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan 
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 
---
 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=":"
+   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 

[gentoo-dev] [PATCH 3/5] linux-mod-r1.eclass: check /boot if we are re-installing, dist-kernel

2024-06-26 Thread Andrew Nowa Ammerlaan

From 3c5267472fb72223336063007173157a5de3f0cc Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan 
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 
---
 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




[gentoo-dev] [PATCH 4/5] sys-kernel/linux-firmware: complain less when /boot is not, mounted

2024-06-26 Thread Andrew Nowa Ammerlaan

From 45a34aecafa64a666976e3d3d7944f8c8ff1e058 Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan 
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 
---
 .../linux-firmware-20240410.ebuild| 21 +--
 .../linux-firmware-20240513.ebuild| 21 +--
 .../linux-firmware-20240610.ebuild| 21 +--
 .../linux-firmware-.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 1bb6

[gentoo-dev] [PATCH 5/5] sys-firmware/intel-microcode: complain less when /boot is not, mounted

2024-06-26 Thread Andrew Nowa Ammerlaan

From c5cf62a41038e344312d8758a4ba232fcd726053 Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan 
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 
---
 .../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 !0x0686"

 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 !0x0686"

 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_posti

Re: [gentoo-dev] [PATCH 1/5 v2] mount-boot.eclass: check for ESP as well as /boot, split, eclass

2024-06-27 Thread Andrew Nowa Ammerlaan

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 
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 
---
 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 0..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-sys...@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
+ 

Re: [gentoo-dev] [PATCH 2/5 v2] kernel-install.eclass: move mount-boot check to, dist-kernel-utils.eclass

2024-06-27 Thread Andrew Nowa Ammerlaan

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 
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 
---
 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=":"
+   # 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
-  

Re: [gentoo-dev] [PATCH 1/5 v3] mount-boot.eclass: check for ESP as well as /boot, split, eclass

2024-06-28 Thread Andrew Nowa Ammerlaan

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 
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 
---
 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 0..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-sys...@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 }" \
+

Re: [gentoo-dev] Pakackages up for grabs

2024-07-05 Thread Andrew Nowa Ammerlaan

On 04/07/2024 00:01, Matthias Maier wrote:

Dear all,

I have had little time to contribute to Gentoo over the last 24
months. Therefore, I need to downsize in actively maintained packages.


I will drop myself as maintainer from the following packages in the next
couple days. Please adopt them if you're interested:




   app-crypt/sbsigntools


I'll take this one. We use it in kernel-build.eclass to sign the 
distribution kernels.



Best,
Matthias






[gentoo-dev] [PATCH] kernel-install: Improve warning, consider alternate initrd generators

2024-07-15 Thread Andrew Nowa Ammerlaan

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

From f442d70bdbd0d410809ede4c23fe476177eee55d Mon Sep 17 00:00:00 2001
From: Zen 
Date: Fri, 28 Jun 2024 13:04:35 -0500
Subject: [PATCH] kernel-install: Improve warning, consider alternate initrd
 generators

Signed-off-by: Zen 
---
 eclass/kernel-install.eclass | 35 ---
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass
index 77570a905ce11..9698b6be3562a 100644
--- a/eclass/kernel-install.eclass
+++ b/eclass/kernel-install.eclass
@@ -63,7 +63,10 @@ _IDEPEND_BASE="
>=sys-kernel/installkernel-14
)
initramfs? (
-   >=sys-kernel/installkernel-14[dracut(-)]
+   || (
+   >=sys-kernel/installkernel-14[dracut(-)]
+   >=sys-kernel/installkernel-14[ugrd(-)]
+   )
)
 "

@@ -190,7 +193,7 @@ if [[ ${KERNEL_IUSE_GENERIC_UKI} ]]; then
"
IDEPEND="
generic-uki? (
-   >=sys-kernel/installkernel-14[-dracut(-),-ukify(-)]
+   
>=sys-kernel/installkernel-14[-dracut(-),-ugrd(-),-ukify(-)]
)
!generic-uki? (
${_IDEPEND_BASE}
@@ -543,16 +546,26 @@ kernel-install_pkg_pretend() {

if ! use initramfs && ! has_version "${CATEGORY}/${PN}[-initramfs]"; 
then
ewarn
-   ewarn "WARNING: The standard configuration of the Gentoo 
distribution"
-   ewarn "kernels requires an initramfs! You have disabled the 
initramfs"
-		ewarn "USE flag and as a result dracut was not pulled in as a 
dependency."

-   ewarn "Please ensure that you are either overriding the 
standard"
-   ewarn "configuration or that an alternative initramfs generation 
plugin"
-   ewarn "is installed for your installkernel implementation!"
-   ewarn
-   ewarn "This is an advanced use case, you are on your own to 
ensure"
-   ewarn "that your system is bootable!"
+		ewarn "WARNING: The default distribution kernel configuration is 
designed"
+		ewarn "to be used with an initramfs! Although possible, there is no 
guarantee"

+   ewarn "that distribution kernels will boot without an 
initramfs."
ewarn
+		ewarn "You have disabled the initramfs USE flag, and as a result the 
package manager"
+ewarn "will not enforce the configuration of an initramfs 
generator in"

+ewarn "sys-kernel/installkernel."
+ewarn
+		ewarn "If you wish to use a custom initramfs generator, then please 
ensure that"
+ewarn "/sbin/installkernel is capable of calling it via a 
kernel installation hook,"
+ewarn "and is also configured to use it via 
/etc/kernel/install.conf."

+ewarn
+ewarn "If you wish to boot without an initramfs, then please 
ensure that"
+ewarn "all kernel drivers required to boot your system are 
built into the"
+ewarn "kernel by modifying the default distribution kernel 
configuration"

+ewarn "using /etc/kernel/config.d"
+ewarn
+		ewarn "Please refer to the installkernel and distribution kernel 
documentation:"

+   ewarn "https://wiki.gentoo.org/wiki/Installkernel";
+ewarn " 
https://wiki.gentoo.org/wiki/Project:Distribution_Kernel";

fi
 }




[gentoo-dev] [PATCH 1/4] kernel-{build,install}.eclass: make kernel install paths match release

2024-07-15 Thread Andrew Nowa Ammerlaan

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

From d57b75ed204432c11ae643ea3526b46dab40c746 Mon Sep 17 00:00:00 2001
From: James Calligeros 
Date: Thu, 27 Jun 2024 05:56:44 +
Subject: [PATCH] kernel-{build,install}.eclass: make kernel install paths
 match release

dist-kernel releases are required to match the package's version, with
'_' substituted for '-' as per kernel release format rules. Curiously,
we made no such substitution on the kernel install directory names.

The consequence of this is that Catalyst has technically only been
working with dist-kernels by pure coincidence - it had never been tested
with kernels containing '_' in ${PV}. When attempting to build install
media for the Gentoo Asahi project, which necessitates using kernels
versioned with '_p*', Catalyst's call to Dracut's --kver argument
passes in the name of the source directory while Dracut expects
the kernel release (module directory).

Make sure that all directories installed by the kernel match the
kernel's own idea of its version exactly. This fixes Catalyst,
makes directories like /usr/src/linux-* consistent with /lib/modules

For compatibility with existing bin kernels, KV_FULL will be
set to ${PV}${KV_LOCALVERSION} in kernel-install.eclass if it
has not been explicitly set elsewhere.

Signed-off-by: James Calligeros 
---
 eclass/kernel-build.eclass   | 46 +++-
 eclass/kernel-install.eclass | 59 +---
 2 files changed, 60 insertions(+), 45 deletions(-)

diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index 86c7cd4a172d5..7d4b98ac027d9 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -20,6 +20,14 @@
 # the kernel and installing it along with its modules and subset
 # of sources needed to build external modules.

+# @ECLASS_VARIABLE: KV_FULL
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# A string containing the full kernel release version, e.g.
+# '6.9.6-gentoo-dist'. This is used to ensure consistency between the
+# kernel's release version and Gentoo's tooling. This is set by
+# kernel-build_src_configure() once we have a kernel.release file.
+
 case ${EAPI} in
8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
@@ -225,6 +233,12 @@ kernel-build_src_configure() {
emake O="${WORKDIR}"/modprep "${MAKEARGS[@]}" olddefconfig
emake O="${WORKDIR}"/modprep "${MAKEARGS[@]}" modules_prepare
cp -pR "${WORKDIR}"/modprep "${WORKDIR}"/build || die
+
+   # Now that we have a release file, set KV_FULL
+   if [[ -z ${KV_FULL} ]]; then
+   local relfile=${WORKDIR}/build/include/config/kernel.release
+   KV_FULL=$(<"${relfile}") || die
+   fi
 }

 # @FUNCTION: kernel-build_src_compile
@@ -254,20 +268,15 @@ kernel-build_src_test() {
INSTALL_MOD_PATH="${T}" INSTALL_MOD_STRIP="${strip_args}" \
modules_install

-   local dir_ver=${PV}${KV_LOCALVERSION}
-   local relfile=${WORKDIR}/build/include/config/kernel.release
-   local module_ver
-   module_ver=$(<"${relfile}") || die
-
-   kernel-install_test "${module_ver}" \
+   kernel-install_test "${KV_FULL}" \
"${WORKDIR}/build/$(dist-kernel_get_image_path)" \
-   "${T}/lib/modules/${module_ver}"
+   "${T}/lib/modules/${KV_FULL}"
 }

 # @FUNCTION: kernel-build_src_install
 # @DESCRIPTION:
 # Install the built kernel along with subset of sources
-# into /usr/src/linux-${PV}.  Install the modules.  Save the config.
+# into /usr/src/linux-${KV_FULL}.  Install the modules.  Save the config.
 kernel-build_src_install() {
debug-print-function ${FUNCNAME} "${@}"

@@ -304,8 +313,7 @@ kernel-build_src_install() {
# note: we're using mv rather than doins to save space and time
# install main and arch-specific headers first, and scripts
local kern_arch=$(tc-arch-kernel)
-   local dir_ver=${PV}${KV_LOCALVERSION}
-   local kernel_dir=/usr/src/linux-${dir_ver}
+   local kernel_dir=/usr/src/linux-${KV_FULL}

if use sparc ; then
# We don't want tc-arch-kernel's sparc64, even though we do
@@ -378,10 +386,6 @@ kernel-build_src_install() {
# strip empty directories
find "${D}" -type d -empty -exec rmdir {} + || die

-   local relfile=${ED}${kernel_dir}/include/config/kernel.release
-   local module_ver
-   module_ver=$(<"${relfile}") || die
-
# warn when trying to "make" a dist-kernel
cat <<-EOF >> "${ED}${kernel_dir}/Makefile" || die

@@ -399,12 +403,12 @@ kernel-build_src_install() {
 	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"
+   dosym "../../../${kernel_dir}" "/lib/modules/${KV_FULL}/build"
+ 

Re: [gentoo-dev] [PATCH 2/4] kernel-build.eclass: sanity check the prepared kernel's release string

2024-07-15 Thread Andrew Nowa Ammerlaan

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

From 021915604b90ee45332dc373f401e52afa832370 Mon Sep 17 00:00:00 2001
From: James Calligeros 
Date: Sat, 29 Jun 2024 01:55:12 +
Subject: [PATCH] kernel-build.eclass: sanity check the prepared kernel's
 release string

Previously, this was only checked by kernel-install_pkg_preinst(). This
means that the entire kernel would have to be built and stripped before
we knew if we had built the correct kernel or not.

Duplicate this check in kernel-build_src_configure() so that we don't waste
time and energy building an incorrectly-versioned kernel.

Signed-off-by: James Calligeros 
---
 eclass/kernel-build.eclass | 13 +
 1 file changed, 13 insertions(+)

diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index 7d4b98ac027d9..408837c4c57a7 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -239,6 +239,19 @@ kernel-build_src_configure() {
local relfile=${WORKDIR}/build/include/config/kernel.release
KV_FULL=$(<"${relfile}") || die
fi
+
+   # Make sure we are about to build the correct kernel
+   if [[ ${PV} != * ]]; then
+   local expected_ver=$(dist-kernel_PV_to_KV "${PV}")
+
+   if [[ ${KV_FULL} != ${expected_ver}* ]]; then
+   eerror "Kernel version does not match PV!"
+   eerror "Source version: ${KV_FULL}"
+   eerror "Expected (PV*): ${expected_ver}*"
+   eerror "Please ensure you are applying the correct 
patchset."
+   die "Kernel version mismatch: got ${KV_FULL}, expected 
${expected_ver}*"
+   fi
+   fi
 }

 # @FUNCTION: kernel-build_src_compile




Re: [gentoo-dev] [PATCH 3/4] kernel-build.eclass: sanity check the prepared kernel's release string

2024-07-15 Thread Andrew Nowa Ammerlaan

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

From ec4e55ae9fd7cc6a4833981040f051ad2a3df15b Mon Sep 17 00:00:00 2001
From: James Calligeros 
Date: Sat, 29 Jun 2024 03:44:38 +
Subject: [PATCH] kernel-build.eclass: check that KV_FULL matches the kernel
 release

We want to ensure all our installed directories are consistent and
match the kernel's own idea of its release version. Do an extra
sanity check to ensure that KV_FULL is indeed what it is supposed
to be, and bail out if it isn't.

Signed-off-by: James Calligeros 
---
 eclass/kernel-build.eclass | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index 408837c4c57a7..6658435b92587 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -235,14 +235,22 @@ kernel-build_src_configure() {
cp -pR "${WORKDIR}"/modprep "${WORKDIR}"/build || die

# Now that we have a release file, set KV_FULL
+   local relfile=${WORKDIR}/build/include/config/kernel.release
if [[ -z ${KV_FULL} ]]; then
-   local relfile=${WORKDIR}/build/include/config/kernel.release
KV_FULL=$(<"${relfile}") || die
fi

# Make sure we are about to build the correct kernel
if [[ ${PV} != * ]]; then
local expected_ver=$(dist-kernel_PV_to_KV "${PV}")
+   local expected_rel=$(<"${relfile}")
+
+   if [[ ${KV_FULL} != ${expected_rel} ]]; then
+   eerror "KV_FULL mismatch!"
+   eerror "KV_FULL:  ${KV_FULL}"
+   eerror "Expected: ${expected_rel}"
+   die "KV_FULL mismatch: got ${KV_FULL}, expected 
${expected_rel}"
+   fi

if [[ ${KV_FULL} != ${expected_ver}* ]]; then
eerror "Kernel version does not match PV!"



Re: [gentoo-dev] [PATCH 4/4] kernel-install.eclass: improve kernel version check

2024-07-15 Thread Andrew Nowa Ammerlaan

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

From bcbc9191becab3cda6af8f9f2c0e1da6ebe395e1 Mon Sep 17 00:00:00 2001
From: James Calligeros 
Date: Sat, 13 Jul 2024 22:47:33 +1000
Subject: [PATCH] kernel-install.eclass: improve kernel version check

Now that we have an improved version check in kernel-build.eclass,
copy it here so that the two eclasses match.

Signed-off-by: James Calligeros 
---
 eclass/kernel-install.eclass | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass
index e0716b63a2489..59bab9c0af08d 100644
--- a/eclass/kernel-install.eclass
+++ b/eclass/kernel-install.eclass
@@ -595,11 +595,11 @@ kernel-install_pkg_preinst() {
local expected_ver=$(dist-kernel_PV_to_KV "${PV}")

if [[ ${KV_FULL} != ${expected_ver}* ]]; then
-   eerror "Kernel release mismatch!"
-   eerror "  expected (PV): ${expected_ver}*"
-   eerror "  found: ${KV_FULL}"
-   eerror "Please verify that you are applying the correct 
patches."
-   die "Kernel release mismatch (${KV_FULL} instead of 
${expected_ver}*)"
+   eerror "Kernel version does not match PV!"
+   eerror "Source version: ${KV_FULL}"
+   eerror "Expected (PV*): ${expected_ver}*"
+   eerror "Please ensure you are applying the correct 
patchset."
+   die "Kernel version mismatch: got ${KV_FULL}, expected 
${expected_ver}*"
fi
fi




Re: [gentoo-dev] [PATCH] kernel-install.eclass: run depmod after compressing modules

2024-08-09 Thread Andrew Nowa Ammerlaan

On 09/08/2024 18:11, Michał Górny wrote:

On Fri, 2024-08-09 at 17:49 +0200, Andrew Ammerlaan wrote:

(de)compressing modules changes the path of the module files so we need to
run depmod to ensure that tools such as modprobe/modinfo work.

Note that depmod is often, but *not* always, run by sys-kernel/installkernel.
Systemd installs a hook to do this, but there is no equivalent on openrc
systems. So instead just ensure that the tree of modules we install is
consistent here in the eclass.

Signed-off-by: Andrew Ammerlaan 
---
  eclass/kernel-install.eclass | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass
index 496e258815d2..930640188c26 100644
--- a/eclass/kernel-install.eclass
+++ b/eclass/kernel-install.eclass
@@ -796,6 +796,9 @@ kernel-install_compress_modules() {
find "${ED}/lib/modules/${KV_FULL}" -name '*.ko' -print0 |
xargs -0 -P "$(makeopts_jobs)" -n 128 "${compress[@]}"
assert "Compressing kernel modules failed"
+
+   # Module paths have changed, run depmod
+   depmod --all --basedir "${ED}" ${KV_FULL} || die
fi
  }
  


Are you actually supposed to run it on ED and not EROOT?  


Either works, but doing it in ED ensures that the 
gentoo-kernel-bin[modules-compress] install image is the same as the 
gentoo-kernel[modules-compress] install image.



Won't that
cause file collisions (even if we circumvent them via CONFIG_PROTECT).


No, it does not install any files that we are not installing anyway, it 
just updates them.