Hi Lianbo,
On 03/15/18 at 03:02pm, Lianbo Jiang wrote:
Kdump service runs too late, so early crashes will have no chance
to get kdump kernel booting. A proposal is add a dracut module to
load pre-built kernel and initramfs for early kdump, one can provide
"rd.early-kdump" in grub commandline to enable, then the service
rd.earlykdump looks better and easier to use.
can load those files like original kdump, which is disabled by
default.
For the normal kdump service in real root init path, it can check
whether the pre-built kernel and initramfs has been loaded. It has
no conflict with the early kdump.
Early kdump puts the pre-built kernel and initramfs for kdump into
the initramfs for boot, the rebuilt initramfs will become large.
By the way, we move some common functions from kdumpctl to
kdump-lib.sh. In addition, early kdump doesn't support fadump.
Signed-off-by: Lianbo Jiang <lijiang(a)redhat.com>
---
dracut-early-kdump-module-setup.sh | 23 +++++
dracut-early-kdump.service | 24 +++++
dracut-early-kdump.sh | 138 +++++++++++++++++++++++++++++
early-kdump-howto.txt | 58 ++++++++++++
kdump-lib.sh | 123 ++++++++++++++++++++++++++
kdump.sysconfig | 3 +
kdump.sysconfig.i386 | 3 +
kdump.sysconfig.ppc64 | 3 +
kdump.sysconfig.ppc64le | 3 +
kdump.sysconfig.s390x | 3 +
kdump.sysconfig.x86_64 | 3 +
kdumpctl | 177 +++++++++++--------------------------
kexec-tools.spec | 13 +++
mkdumprd.8 | 3 +
14 files changed, 454 insertions(+), 123 deletions(-)
create mode 100755 dracut-early-kdump-module-setup.sh
create mode 100644 dracut-early-kdump.service
create mode 100755 dracut-early-kdump.sh
create mode 100644 early-kdump-howto.txt
diff --git a/dracut-early-kdump-module-setup.sh b/dracut-early-kdump-module-setup.sh
new file mode 100755
index 0000000..bc4d7dc
--- /dev/null
+++ b/dracut-early-kdump-module-setup.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+check() {
+ if [ ! -f /etc/sysconfig/kdump ] || [ ! -f /lib/kdump/kdump-lib.sh ]
+ then
+ return 1
+ fi
+ return 0
+}
+
+depends() {
+ echo "base shutdown"
+ return 0
+}
+
+install() {
+ inst_simple "/etc/sysconfig/kdump" "/etc/sysconfig/kdump"
+ inst_simple "/usr/sbin/kexec" "/usr/sbin/kexec"
+ inst_script "/lib/kdump/kdump-lib.sh" "/lib/kdump-lib.sh"
+ inst_script "$moddir/early-kdump.sh" "/usr/bin/early-kdump"
+ inst_simple "$moddir/early-kdump.service"
"${systemdsystemunitdir}/early-kdump.service"
+ ln_r "${systemdsystemunitdir}/early-kdump.service"
"${systemdsystemunitdir}/initrd.target.wants/early-kdump.service"
+}
diff --git a/dracut-early-kdump.service b/dracut-early-kdump.service
new file mode 100644
index 0000000..8282c49
--- /dev/null
+++ b/dracut-early-kdump.service
@@ -0,0 +1,24 @@
+# This file is part of systemd.
+#
+# systemd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+
+# See systemd.special(7) for details
+
+[Unit]
+Description=early kdump
+DefaultDependencies=yes
+After=dracut-cmdline.service
+Before=dracut-pre-mount.service
As we talked offline, since this does not depend on systemd, we can
simply install a cmdline hook script without using a service. It will
be even early.
+
+[Service]
+Environment=DRACUT_SYSTEMD=1
+Type=oneshot
+ExecStart=/bin/early-kdump
+KillMode=process
+
+#Bash ignore SIGTERM, so we send SIGHUP instead, to ensure that bash
+#terminates cleanly.
+KillSignal=SIGHUP
diff --git a/dracut-early-kdump.sh b/dracut-early-kdump.sh
new file mode 100755
index 0000000..067ad5c
--- /dev/null
+++ b/dracut-early-kdump.sh
@@ -0,0 +1,138 @@
+#! /bin/sh
+
+KEXEC=/sbin/kexec
+standard_kexec_args="-p"
+
+EARLY_KDUMP_INITRD=""
+EARLY_KDUMP_KERNEL=""
+EARLY_KDUMP_CMDLINE=""
+EARLY_KDUMP_KERNELVER=""
+EARLY_KEXEC_ARGS=""
+
+#source lib and configure
+. /lib/dracut-lib.sh
+. /lib/kdump-lib.sh
+. /etc/sysconfig/kdump
Not sure if those lib sh depends on variables in sysconfig, it is better
to source sysconfig/kdump first.
+
+prepare_parameters()
+{
+ local cmdline id
+
+ if [ -z "$EARLY_KDUMP_CMDLINE" ]; then
+ cmdline=$(cat /proc/cmdline)
+ else
+ cmdline=${EARLY_KDUMP_CMDLINE}
+ fi
+
+ cmdline=$(remove_cmdline_param "$cmdline" crashkernel panic_on_warn)
+ cmdline=$(remove_cmdline_param "$cmdline" ${KDUMP_COMMANDLINE_REMOVE})
+
+ # Always remove "root=X", as we now explicitly generate all kinds
+ # of dump target mount information including root fs.
+ #
+ # We do this before KDUMP_COMMANDLINE_APPEND, if one really cares
+ # about it(e.g. for debug purpose), then can pass "root=X" using
+ # KDUMP_COMMANDLINE_APPEND.
+ cmdline=$(remove_cmdline_param "$cmdline" root)
+
+ # With the help of "--hostonly-cmdline", we can avoid some interitage.
+ cmdline=$(remove_cmdline_param "$cmdline" rd.lvm.lv rd.luks.uuid
rd.dm.uuid rd.md.uuid fcoe)
+ cmdline="${cmdline} ${KDUMP_COMMANDLINE_APPEND}"
+ id=$(get_bootcpu_apicid)
+ if [ ! -z ${id} ] ; then
+ cmdline=$(append_cmdline "${cmdline}" disable_cpu_apicid ${id})
+ fi
+ EARLY_KDUMP_CMDLINE=$cmdline
+
+ if [ -z "$KDUMP_BOOTDIR" ]; then
+ if ! is_atomic || [ "$(uname -m)" = "s390x" ]; then
+ KDUMP_BOOTDIR="/boot"
+ else
+ eval $(cat /proc/cmdline| grep "BOOT_IMAGE" | cut -d'
' -f1)
+ KDUMP_BOOTDIR="/boot"$(dirname $BOOT_IMAGE)
+ fi
+ fi
+
+ #make early-kdump kernel string
+ if [ -z "$EARLY_KDUMP_KERNELVER" ]; then
+ EARLY_KDUMP_KERNELVER=`uname -r`
+ fi
+
EARLY_KDUMP_KERNEL="${KDUMP_BOOTDIR}/${KDUMP_IMG}-${EARLY_KDUMP_KERNELVER}${KDUMP_IMG_EXT}"
+
+ #make early-kdump initrd string
+
EARLY_KDUMP_INITRD="${KDUMP_BOOTDIR}/initramfs-${EARLY_KDUMP_KERNELVER}kdump.img"
+}
Can this prepare cmdline be moved to lib file as well?
+
+early_kdump_load()
+{
+ check_kdump_feasibility
+ if [ $? -ne 0 ]; then
+ return 1
+ fi
+
+ if is_fadump_capable; then
+ echo "early kdump doesn't support fadump: [WARNING]"
In kdumpctl we use below style, messages here should be consistent:
echo "WARNING: ..."
+ return 1
+ fi
+
+ check_current_kdump_status
+ if [ $? == 0 ]; then
+ return 1
+ fi
+
+ prepare_parameters
+
+ ARCH=`uname -m`
+ if [ "$ARCH" == "i686" -o "$ARCH" == "i386"
]
+ then
+ need_64bit_headers
+ if [ $? == 1 ]
+ then
+ FOUND_ELF_ARGS=`echo $EARLY_KEXEC_ARGS | grep elf32-core-headers`
+ if [ -n "$FOUND_ELF_ARGS" ]
+ then
+ echo -n "Warning: elf32-core-headers overrides correct elf64
setting"
+ echo
+ else
+ EARLY_KEXEC_ARGS="$EARLY_KEXEC_ARGS --elf64-core-headers"
+ fi
+ else
+ FOUND_ELF_ARGS=`echo $EARLY_KEXEC_ARGS | grep elf64-core-headers`
+ if [ -z "$FOUND_ELF_ARGS" ]
+ then
+ EARLY_KEXEC_ARGS="$EARLY_KEXEC_ARGS --elf32-core-headers"
+ fi
+ fi
+ fi
Above elf header checking can also be a function in kdump-lib.sh to avoid
duplicate code.
+
+ #secure boot
No need the comment since it is clear.
+ if is_secure_boot_enforced; then
+ echo "Secure Boot is enabled. Using kexec file based syscall."
+ EARLY_KEXEC_ARGS="$EARLY_KEXEC_ARGS -s"
+ fi
+
+ $KEXEC ${EARLY_KEXEC_ARGS} $standard_kexec_args \
+ --command-line="$EARLY_KDUMP_CMDLINE" \
+ --initrd=$EARLY_KDUMP_INITRD $EARLY_KDUMP_KERNEL
+ if [ $? == 0 ]; then
+ echo "kexec: loaded early-kdump kernel"
+ return 0
+ else
+ echo "kexec: failed to load early-kdump kernel"
+ return 1
+ fi
+}
+
+setearlykdump()
+{
+ if getargbool 0 rd.early-kdump; then
+ echo "early-kdump is enabled."
+ early_kdump_load
+ else
+ echo "early-kdump is not enabled by default."
remove "by default"
+ fi
+
+ return 0
+}
+
+setearlykdump
diff --git a/early-kdump-howto.txt b/early-kdump-howto.txt
new file mode 100644
index 0000000..aae8d7b
--- /dev/null
+++ b/early-kdump-howto.txt
@@ -0,0 +1,58 @@
+Early Kdump HOWTO
+
+Introduction
+
+Kdump service runs too late, so early crashes will have no chance to get kdump
+kernel booting. A proposal is add a dracut module to load pre-built kernel and
+initramfs for early kdump, one can provide "rd.early-kdump" in grub
commandline
+to enable, then the service can load those files like original kdump, which is
+disabled by default.
+
+For the normal kdump service in real root init path, it can check whether the
+prebuilt kernel and initramfs have been loaded. It has no conflict with the early
+kdump.
+
+How to configure early kdump:
+
+We assume if you're reading this document, you should already have kexec-tools
+installed. If not, you install it via the following command:
+
+ # yum install kexec-tools
+
No need to say about installing kexec-tools
+For early kdump, you can set "EARLY_KDUMP_SUPPORT=yes" in
/etc/sysconfig/kdump
+if you want to rebuild the initramfs for early kdump, and then:
+ # kdumpctl restart
Thinking about this, IMO we can document the steps to generate the new
initrd instead of adding it in kdumpctl. I'm not too keen to replace
the system initrd automatically. The code will be simpler we do not
need add extra options in sysconfig. And include the kernel and initrd
in module-setup.sh seems good if it is not too hard to check the kernel
version defined in sysconfig.
[snip]
Thanks
Dave