Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 481506 - sys-apps/kexec-tools-2.0.4-r1 - /etc/init.d/kexec: issues with $INITRD, $DONT_MOUNT_BOOT
Summary: sys-apps/kexec-tools-2.0.4-r1 - /etc/init.d/kexec: issues with $INITRD, $DONT...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Justin Lecher (RETIRED)
URL:
Whiteboard:
Keywords: PATCH
: 486118 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-08-18 02:22 UTC by BobbyK
Modified: 2013-09-28 08:46 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Updated patch (kexec-tools-2.0.4-r1.patch,1.76 KB, patch)
2013-08-21 00:54 UTC, BobbyK
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description BobbyK 2013-08-18 02:22:17 UTC
The OpenRC init script for kexec has a few issues.  For instance, if INITRD is specified kexec will fail to stop (as $initrd is assigned the value ${BOOTPATH}/${INITRD}, and load_image fails is ${initrd} != ${INITRD}).

There are a couple of syntactical issues [ -n ${DONT_MOUNT_BOOT} ] is always true, so mount_boot always returns 1 and never mounts /boot (if present), so kernel image and initrd are not found.

Reproducible: Always

Steps to Reproduce:
1. Have a separate /boot partition
2. Install and configure kexec-tools-2.0.4-r1
3. Specify an INITRD in /etc/conf.d/kexec
Actual Results:  
kexec fails to stop, resulting in a regular reboot (via BIOS and bootloader)

Expected Results:  
kexec succeeds in stopping, resulting in a fast reboot (bypassing BIOS and bootloader)

I updated /etc/init.d/kexec as follows to get things working again:

--- 1/kexec      2013-08-17 21:44:08.000000000 -0400
+++ 2/kexec   2013-08-17 21:42:57.000000000 -0400
@@ -26,8 +26,13 @@
 initrd_path() {
        local x= kver=$(uname -r) karch=$(uname -m)
        BOOTPART="${BOOTPART:-/boot}"
-       for x in "${INITRD:-initrd}" \
-               initrd.img-${kver} initrd-${kver}.img \
+
+       if [ -e "${INITRD:-initrd}" ]; then
+               echo "${INITRD:-initrd}"
+               return 0
+       fi
+
+       for x in initrd.img-${kver} initrd-${kver}.img \
                initrd-${kver} initramfs-${kver}.img \
                initramfs-genkernel-${karch}-${kver} ; do
                if [ -e "${BOOTPART}/${x}" ]; then
@@ -42,7 +47,7 @@
 mount_boot(){
        local ret
 
-       [ -n ${DONT_MOUNT_BOOT} ] && return 1
+       [ -n "${DONT_MOUNT_BOOT}" ] && return 1
        grep -q " ${BOOTPART:-/boot} " /proc/mounts && return 1
 
        BOOTPART="${BOOTPART:-/boot}"
@@ -95,7 +100,7 @@
        [ -n "${initrd}" ] && [ -e "${initrd}" ] && initrdopt="--initrd=${initrd}"
 
        local msg=
-       [ -n ${initrd} ] && \
+       [ -n "${initrd}" ] && \
                msg="with ${initrd}"
        einfo "Using kernel image ${img} ${msg} for kexec"
Comment 1 BobbyK 2013-08-18 15:38:47 UTC
As an alternative to spltting the "for" in initrd_path to an "if" and a "for" the following from load_image:

        if [ -n "${INITRD}" ] && \
                ! [ "${INITRD}" = "${initrd}" ]; then

could be changed to:

        if [ -n "${INITRD}" ] && \
                ! [ "${BOOTPART:-/boot}"/"${INITRD}" = "${initrd}" ]; then

provided the path to initrd is removed from /etc/conf.d/kexec...
Comment 2 Justin Lecher (RETIRED) gentoo-dev 2013-08-20 08:58:08 UTC
Thanks for all the patches. I will look into that
Comment 3 BobbyK 2013-08-21 00:54:37 UTC
Created attachment 356552 [details, diff]
Updated patch

This patch also addresses warnings at boot time by mounting /boot (if present) before testing for existence of kernel image, and unmounts /boot if the init script needed to mount it to find the kernel.  This may introduce issues if run in parallel with other scripts that need to access /boot (are there any?), though removes potentially misleading warnings.
Comment 4 Hodur 2013-09-04 12:19:23 UTC
/etc/init.d/kexec doesn't detect an initrd image during startup.

Steps to Reproduce:

1. Compile a new devel kernel gentoo-sources-3.10.10 against a current kernel with older version (gentoo-sources-3.8.12 for example) via genkernel.

#ls -lh /boot/kernel-genkernel-x86_64-3.10.10-gentoo
-rw-r--r-- 1 root root 2.7M Sep  4 14:26 /boot/kernel-genkernel-x86_64-3.10.10-gentoo

#ls -lh /boot/initramfs-genkernel-x86_64-3.10.10-gentoo
-rw-r--r-- 1 root root 2.6M Sep  4 14:28 /boot/initramfs-genkernel-x86_64-3.10.10-gentoo


2. Edit the following lines in /etc/conf.d/kexec 
LOAD_DURING_SHUTDOWN="no"
KNAME="kernel-genkernel-x86_64-3.10.10-gentoo"
INITRD="/boot/initramfs-genkernel-x86_64-3.10.10-gentoo"

3. Start kexec

/etc/init.d/kexec start

/etc/init.d/kexec start
 * Configuring kexec ...
 * Requested initrd: /boot/initramfs-genkernel-x86_64-3.10.10-gentoo
 * could not be found                                                                                                               [ !! ]
 * ERROR: kexec failed to start


Comment "return 1" in /etc/init.d/kexec line 87

    if [ -n "${INITRD}" ] && \
        ! [ "${INITRD}" = "${initrd}" ]; then
        eerror "Requested initrd: ${INITRD}"
        eerror "could not be found"
#        return 1
    fi

Start kexec again

#/etc/init.d/kexec start
 * Caching service dependencies ...                                                                                                 [ ok ]
 * Configuring kexec ...
 * Requested initrd: /boot/initramfs-genkernel-x86_64-3.10.10-gentoo
 * could not be found
 * Using kernel image /boot/kernel-genkernel-x86_64-3.10.10-gentoo with /boot//boot/initramfs-genkernel-x86_64-3.10.10-gentoo for kexec
 * Setting kexec with  --reuse-cmdline -l /boot/kernel-genkernel-x86_64-3.10.10-gentoo root=/dev/sda2  --initrd=/boot//boot/initramfs-genkernel-x86_64-3.10.10-gentoo ...
Comment 5 Justin Lecher (RETIRED) gentoo-dev 2013-09-21 11:37:17 UTC
+*kexec-tools-2.0.4-r2 (21 Sep 2013)
+
+  21 Sep 2013; Justin Lecher <jlec@gentoo.org> +kexec-tools-2.0.4-r2.ebuild,
+  kexec-tools-9999.ebuild, -files/kexec.conf-2.0.3, -files/kexec.init-2.0.3,
+  +files/kexec.init-2.0.4-r2, +files/kexec.conf-9999, +files/kexec.init-9999,
+  files/kexec.conf, -files/kexec.init, -files/kexec.init-ng,
+  +files/kexec.service:
+  Add support for systemd, #478072; Fix issues with openrc init scripts,
+  #481506; thanks BobbyK for the patches
+


I applied your patches but also now test INITRD and KNAME directly and/or strip BOOTPART from them. PLease test if that works.
Comment 6 Justin Lecher (RETIRED) gentoo-dev 2013-09-28 08:46:06 UTC
*** Bug 486118 has been marked as a duplicate of this bug. ***