summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Ammerlaan <andrewammerlaan@gentoo.org>2024-07-27 12:27:24 +0200
committerAndrew Ammerlaan <andrewammerlaan@gentoo.org>2024-08-06 09:32:27 +0200
commit8cb4582e9d05279ad58dd8282b7a927e53a2dbec (patch)
tree2b16875c8baf8db49cb9307be24f979c11065c92
parentdev-build/cmake: add 3.30.2 (diff)
downloadgentoo-8cb4582e9d05279ad58dd8282b7a927e53a2dbec.tar.gz
gentoo-8cb4582e9d05279ad58dd8282b7a927e53a2dbec.tar.bz2
gentoo-8cb4582e9d05279ad58dd8282b7a927e53a2dbec.zip
sys-apps/kexec-tools: remove broken installkernel hooks
and replace with little wrapper script that reads the latest kernel from the installkernel log file and uses the usual locations for the cmdline. Merge /etc/kexec.conf and /etc/conf.d/kexec, both config files are now basically the same, with the exception of some variables only being used by the openrc script. TODO (by someone on OpenRC): adapt the openrc init script so it also reads the installkernel.log. Closes: https://bugs.gentoo.org/585658 Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org> Closes: https://github.com/gentoo/gentoo/pull/37742 Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
-rwxr-xr-xsys-apps/kexec-tools/files/kexec-auto-load95
-rw-r--r--sys-apps/kexec-tools/files/kexec.conf42
-rw-r--r--sys-apps/kexec-tools/files/kexec.conf-2.0.46
-rw-r--r--sys-apps/kexec-tools/files/kexec.service4
-rw-r--r--sys-apps/kexec-tools/kexec-tools-2.0.29-r1.ebuild (renamed from sys-apps/kexec-tools/kexec-tools-2.0.29.ebuild)17
-rw-r--r--sys-apps/kexec-tools/kexec-tools-9999.ebuild17
6 files changed, 135 insertions, 46 deletions
diff --git a/sys-apps/kexec-tools/files/kexec-auto-load b/sys-apps/kexec-tools/files/kexec-auto-load
new file mode 100755
index 000000000000..62c828fd1c3d
--- /dev/null
+++ b/sys-apps/kexec-tools/files/kexec-auto-load
@@ -0,0 +1,95 @@
+#!/usr/bin/env bash
+
+# Defaults
+LAYOUT=compat
+BOOTPART=/boot
+KNAME=kernel
+INITRD=initramfs.img
+
+instkern_state=/var/lib/misc/installkernel
+if [[ -s ${instkern_state} ]]; then
+ # If we have a log file, set defaults from there.
+ IFS=$'\t' read -r -a LastKernArray <<< "$(tail -n1 ${instkern_state})"
+ LAYOUT="${LastKernArray[4]}"
+ BOOTPART="${LastKernArray[7]}"
+ KNAME="${LastKernArray[8]}"
+ if [[ "${LastKernArray[9]}" != unknown && ${LAYOUT} != uki ]]; then
+ INITRD="${LastKernArray[9]}"
+ else
+ INITRD=
+ fi
+fi
+
+if [[ ${LAYOUT} == uki ]]; then
+ echo "WARNING: kexec currently does not support UKIs"
+ KPARAM=
+else
+ if [[ -f /etc/kernel/cmdline ]]; then
+ KPARAM="$(tr -s "${IFS}" ' ' </etc/kernel/cmdline)"
+ elif [[ -f /usr/lib/kernel/cmdline ]]; then
+ KPARAM="$(tr -s "${IFS}" ' ' </usr/lib/kernel/cmdline)"
+ else
+ KPARAM=
+ fi
+fi
+
+
+# /etc/kexec.conf overrides installkernel.log
+kexec_conf=/etc/kexec.conf
+if [[ -f ${kexec_conf} ]]; then
+ source ${kexec_conf}
+fi
+
+if [[ -z ${DONT_MOUNT_BOOT} ]]; then
+ # Borrowed from mount-boot-utils.eclass
+ # note that /dev/BOOT is in the Gentoo default /etc/fstab file
+ fstabstate=$(awk "!/^[[:blank:]]*#|^\/dev\/BOOT/ && \$2 == \"${BOOTPART}\" \
+ { print 1; exit }" /etc/fstab || die "awk failed")
+
+ if [[ -z ${fstabstate} ]]; then
+ echo "Assuming you do not have a separate ${BOOTPART} partition."
+ else
+ procstate=$(awk "\$2 == \"${BOOTPART}\" { 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
+ echo "ERROR: Your ${BOOTPART} partition is not mounted"
+ exit 1
+ fi
+ fi
+fi
+
+if [[ ! -d ${BOOTPART} ]]; then
+ echo "ERROR: BOOTPART=${BOOTPART} not found"
+ exit 1
+fi
+
+KEXEC_ARGS=()
+
+if [[ -f ${BOOTPART}/${KNAME} ]]; then
+ KEXEC_ARGS+=( --load "${BOOTPART}/${KNAME}" )
+else
+ echo "ERROR: KNAME=${KNAME} not found"
+ exit 1
+fi
+
+if [[ -n ${INITRD} ]]; then
+ if [[ -f ${BOOTPART}/${INITRD} ]]; then
+ KEXEC_ARGS+=( --initrd "${BOOTPART}/${INITRD}" )
+ else
+ echo "WARNING: INITRD=${INITRD} not found"
+ fi
+fi
+
+if [[ -n ${KPARAM} ]]; then
+ KEXEC_ARGS+=( --command-line "${KPARAM}" )
+elif [[ ! -f /etc/kernel/cmdline && ! -f /usr/lib/kernel/cmdline ]]; then
+ # If it is still empty and we did not intentionally set it empty then reuse.
+ KEXEC_OPT_ARGS+=" --reuse-cmdline "
+fi
+
+KEXEC_ARGS+=( ${KEXEC_OPT_ARGS} )
+
+echo "Calling kexec with arguments: ${KEXEC_ARGS[@]}"
+exec kexec "${KEXEC_ARGS[@]}"
diff --git a/sys-apps/kexec-tools/files/kexec.conf b/sys-apps/kexec-tools/files/kexec.conf
index aa829b9c2349..34161117ec8f 100644
--- a/sys-apps/kexec-tools/files/kexec.conf
+++ b/sys-apps/kexec-tools/files/kexec.conf
@@ -1,16 +1,32 @@
-# Kernel image pathname, relative from /boot.
-KNAME="bzimage"
+# Kernel image partition.
+# Default: partition that last kernel image was installed on
+#BOOTPART="/boot"
+
+# Path to (unified) kernel image, relative to BOOTPART.
+# Default: last installed kernel image
+#KNAME="kernel"
+
+# Path to the initramfs image, relative to BOOTPART
+# Default: initramfs belonging to last kernel image, if any
+#INITRD="initramfs.img"
+
+# Kernel cmdline to use,
+# Default: contents of {/etc,/usr/lib}/kernel/cmdline if exists, otherwise --reuse-cmdline is used
+#KPARAM="quiet"
+
+# Additional arguments passed to kexec
+#KEXEC_OPT_ARGS=""
+
+# Do not try to mount /boot
+#DONT_MOUNT_BOOT="yes"
-# Additional arguments passed to kexec (8)
-# Following arguments are support:
-#
-# --reuse-cmdline
-# Use the current boot command line
-#
-# --command-line=string
-# Use a different command line
#
-# --initrd=file
-# Specify an initrd to use
+# The below is currently used by the OpenRC script only
#
-KEXEC_OPT_ARGS="--reuse-cmdline"
+
+# Load kexec kernel image into memory during shutdown instead of bootup
+# (default: yes)
+#LOAD_DURING_SHUTDOWN="yes"
+
+# Root partition (should be autodetected)
+#ROOTPART="/dev/hda3"
diff --git a/sys-apps/kexec-tools/files/kexec.conf-2.0.4 b/sys-apps/kexec-tools/files/kexec.conf-2.0.4
index b71ea2bae97f..215acca19d7a 100644
--- a/sys-apps/kexec-tools/files/kexec.conf-2.0.4
+++ b/sys-apps/kexec-tools/files/kexec.conf-2.0.4
@@ -13,12 +13,12 @@
#ROOTPART="/dev/hda3"
# Kernel image pathname, relative from BOOTPART.
-# If it's one of
+# If it's one of
# {kernel-genkernel,bzImage,vmlinuz,kernel}-<currently running kernel version>,
# or bzImage, vmlinuz (without suffix),
# then it's automaticaly detected.
# Setting it to "-" will disable kexec.
-#KNAME="vmlinuz-3.9.0"
+#KNAME="kernel"
# Initrd
# Same automatic detection restriction as for KNAME apply.
@@ -31,4 +31,4 @@
#KPARAM="splash=silent,theme:emergence"
# Do not try to mount /boot
-# DONT_MOUNT_BOOT="yes"
+#DONT_MOUNT_BOOT="yes"
diff --git a/sys-apps/kexec-tools/files/kexec.service b/sys-apps/kexec-tools/files/kexec.service
index 289aae0df0b1..ce9adf0e5da2 100644
--- a/sys-apps/kexec-tools/files/kexec.service
+++ b/sys-apps/kexec-tools/files/kexec.service
@@ -9,8 +9,8 @@ ConditionPathExists=!/nokexec
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/kexec.conf
-ExecStart=/usr/sbin/kexec -l /boot/${KNAME} ${KEXEC_OPT_ARGS}
-ExecStop=/usr/sbin/kexec -l /boot/${KNAME} ${KEXEC_OPT_ARGS}
+ExecStart=/usr/sbin/kexec-auto-load
+ExecStop=/usr/sbin/kexec-auto-load
[Install]
WantedBy=multi-user.target
diff --git a/sys-apps/kexec-tools/kexec-tools-2.0.29.ebuild b/sys-apps/kexec-tools/kexec-tools-2.0.29-r1.ebuild
index bedde55d9615..761057097d28 100644
--- a/sys-apps/kexec-tools/kexec-tools-2.0.29.ebuild
+++ b/sys-apps/kexec-tools/kexec-tools-2.0.29-r1.ebuild
@@ -3,7 +3,7 @@
EAPI=8
-inherit libtool linux-info optfeature systemd
+inherit libtool linux-info systemd
if [[ ${PV} == "9999" ]] ; then
inherit git-r3 autotools
@@ -92,24 +92,16 @@ src_install() {
dodoc "${FILESDIR}"/README.Gentoo
newinitd "${FILESDIR}"/kexec-r2.init kexec
- newconfd "${FILESDIR}"/kexec.conf-2.0.4 kexec
insinto /etc
doins "${FILESDIR}"/kexec.conf
+ dosym ../kexec.conf /etc/conf.d/kexec
- insinto /etc/kernel/postinst.d
- doins "${FILESDIR}"/90_kexec
-
+ dosbin "${FILESDIR}"/kexec-auto-load
systemd_dounit "${FILESDIR}"/kexec.service
}
pkg_postinst() {
- if systemd_is_booted || has_version sys-apps/systemd; then
- elog "For systemd support the new config file is"
- elog " /etc/kexec.conf"
- elog "Please adopt it to your needs as there is no autoconfig anymore"
- fi
-
local n_root_args=$(grep -o -- '\<root=' /proc/cmdline 2>/dev/null | wc -l)
local has_rootpart_set=no
if [[ -f "${EROOT}/etc/conf.d/kexec" ]]; then
@@ -125,7 +117,4 @@ pkg_postinst() {
ewarn "in case running system and initramfs do not agree on detected"
ewarn "root device name!"
fi
-
- optfeature "automatically updating /etc/kexec.conf on each kernel installation" \
- "sys-kernel/installkernel[-systemd]"
}
diff --git a/sys-apps/kexec-tools/kexec-tools-9999.ebuild b/sys-apps/kexec-tools/kexec-tools-9999.ebuild
index bedde55d9615..761057097d28 100644
--- a/sys-apps/kexec-tools/kexec-tools-9999.ebuild
+++ b/sys-apps/kexec-tools/kexec-tools-9999.ebuild
@@ -3,7 +3,7 @@
EAPI=8
-inherit libtool linux-info optfeature systemd
+inherit libtool linux-info systemd
if [[ ${PV} == "9999" ]] ; then
inherit git-r3 autotools
@@ -92,24 +92,16 @@ src_install() {
dodoc "${FILESDIR}"/README.Gentoo
newinitd "${FILESDIR}"/kexec-r2.init kexec
- newconfd "${FILESDIR}"/kexec.conf-2.0.4 kexec
insinto /etc
doins "${FILESDIR}"/kexec.conf
+ dosym ../kexec.conf /etc/conf.d/kexec
- insinto /etc/kernel/postinst.d
- doins "${FILESDIR}"/90_kexec
-
+ dosbin "${FILESDIR}"/kexec-auto-load
systemd_dounit "${FILESDIR}"/kexec.service
}
pkg_postinst() {
- if systemd_is_booted || has_version sys-apps/systemd; then
- elog "For systemd support the new config file is"
- elog " /etc/kexec.conf"
- elog "Please adopt it to your needs as there is no autoconfig anymore"
- fi
-
local n_root_args=$(grep -o -- '\<root=' /proc/cmdline 2>/dev/null | wc -l)
local has_rootpart_set=no
if [[ -f "${EROOT}/etc/conf.d/kexec" ]]; then
@@ -125,7 +117,4 @@ pkg_postinst() {
ewarn "in case running system and initramfs do not agree on detected"
ewarn "root device name!"
fi
-
- optfeature "automatically updating /etc/kexec.conf on each kernel installation" \
- "sys-kernel/installkernel[-systemd]"
}