#22 Add kdump-utils subpackage
Merged 11 days ago by coiby. Opened 2 months ago by coiby.
rpms/ coiby/kexec-tools kdump-utils-subpackage  into  rawhide

file removed
-31
@@ -1,31 +0,0 @@ 

- #!/usr/bin/bash

- 

- COMMAND="$1"

- KERNEL_VERSION="$2"

- 

- if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then

-     exit 0

- fi

- 

- # Currently, fadump is supported only in environments with

- # writable /boot directory.

- if [[ ! -w "/boot" ]]; then

-     exit 0

- fi

- 

- FADUMP_INITRD="/boot/.initramfs-${KERNEL_VERSION}.img.default"

- FADUMP_INITRD_CHECKSUM="$FADUMP_INITRD.checksum"

- 

- ret=0

- case "$COMMAND" in

-     add)

-         # Do nothing, fadump initramfs is strictly host only

-         # and managed by kdump service

-         ;;

-     remove)

-         rm -f -- "$FADUMP_INITRD"

-         rm -f -- "$FADUMP_INITRD_CHECKSUM"

-         ret=$?

-         ;;

- esac

- exit $ret

file removed
-36
@@ -1,36 +0,0 @@ 

- #!/usr/bin/bash

- 

- COMMAND="$1"

- KERNEL_VERSION="$2"

- KDUMP_INITRD_DIR_ABS="$3"

- KERNEL_IMAGE="$4"

- 

- if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then

-     exit 0

- fi

- 

- if [[ -d "$KDUMP_INITRD_DIR_ABS" ]]; then

-     KDUMP_INITRD="initrdkdump"

- else

-     # If `KDUMP_BOOTDIR` is not writable, then the kdump

-     # initrd must have been placed at `/var/lib/kdump`

-     if [[ ! -w "/boot" ]]; then

-         KDUMP_INITRD_DIR_ABS="/var/lib/kdump"

-     else

-         KDUMP_INITRD_DIR_ABS="/boot"

-     fi

-     KDUMP_INITRD="initramfs-${KERNEL_VERSION}kdump.img"

- fi

- 

- ret=0

- case "$COMMAND" in

-     add)

-         # Do nothing, kdump initramfs is strictly host only

-         # and managed by kdump service

-         ;;

-     remove)

-         rm -f -- "$KDUMP_INITRD_DIR_ABS/$KDUMP_INITRD"

-         ret=$?

-         ;;

- esac

- exit $ret

file removed
-13
@@ -1,13 +0,0 @@ 

- #!/usr/bin/bash

- 

- COMMAND="$1"

- KERNEL_VERSION="$2"

- KDUMP_INITRD_DIR_ABS="$3"

- KERNEL_IMAGE="$4"

- 

- case "$COMMAND" in

- add)

- 	kdumpctl _reset-crashkernel-for-installed_kernel "$KERNEL_VERSION"

- 	exit 0

- 	;;

- esac

file removed
-16
@@ -1,16 +0,0 @@ 

- SUBSYSTEM=="cpu", ACTION=="add", GOTO="kdump_reload"

- SUBSYSTEM=="cpu", ACTION=="remove", GOTO="kdump_reload"

- SUBSYSTEM=="memory", ACTION=="online", GOTO="kdump_reload"

- SUBSYSTEM=="memory", ACTION=="offline", GOTO="kdump_reload"

- 

- GOTO="kdump_reload_end"

- 

- LABEL="kdump_reload"

- 

- # If kdump is not loaded, calling kdump-udev-throttle will end up

- # doing nothing, but systemd-run will always generate extra logs for

- # each call, so trigger the kdump-udev-throttler only if kdump

- # service is active to avoid unnecessary logs

- RUN+="/bin/sh -c '/usr/bin/systemctl is-active kdump.service || exit 0; /usr/bin/systemd-run --quiet --no-block /usr/lib/udev/kdump-udev-throttler'"

- 

- LABEL="kdump_reload_end"

file removed
-22
@@ -1,22 +0,0 @@ 

- SUBSYSTEM=="cpu", ACTION=="online", GOTO="kdump_reload_cpu"

- SUBSYSTEM=="memory", ACTION=="online", GOTO="kdump_reload_mem"

- SUBSYSTEM=="memory", ACTION=="offline", GOTO="kdump_reload_mem"

- 

- GOTO="kdump_reload_end"

- 

- # If kdump is not loaded, calling kdump-udev-throttle will end up

- # doing nothing, but systemd-run will always generate extra logs for

- # each call, so trigger the kdump-udev-throttler only if kdump

- # service is active to avoid unnecessary logs

- 

- LABEL="kdump_reload_mem"

- 

- RUN+="/bin/sh -c '/usr/bin/systemctl is-active kdump.service || exit 0; /usr/bin/systemd-run --quiet --no-block /usr/lib/udev/kdump-udev-throttler'"

- 

- GOTO="kdump_reload_end"

- 

- LABEL="kdump_reload_cpu"

- 

- RUN+="/bin/sh -c '/usr/bin/systemctl is-active kdump.service || exit 0; ! test -f /sys/kernel/fadump/enabled || cat /sys/kernel/fadump/enabled | grep 0  || exit 0; /usr/bin/systemd-run --quiet --no-block /usr/lib/udev/kdump-udev-throttler'"

- 

- LABEL="kdump_reload_end"

file removed
-120
@@ -1,120 +0,0 @@ 

- Introduction

- ============

- 

- This document describes features the kexec-tools package provides for setting

- and estimating the crashkernel value.

- 

- Kdump lives in a pre-reserved chunk of memory, and the size of the reserved

- memory is specified by the `crashkernel=` kernel parameter. It's hard to

- estimate an accurate `crashkernel=` value, so it's always recommended to test

- kdump after you updated the `crashkernel=` value or changed the dump target.

- 

- 

- Default crashkernel value

- =========================

- 

- Latest kexec-tools provides "kdumpctl get-default-crashkernel" to retrieve

- the default crashkernel value,

- 

- 	$ echo $(kdumpctl get-default-crashkernel)

- 	1G-4G:192M,4G-64G:256M,64G-:512M

- 

- It will be taken as the default value of 'crashkernel=', you can use

- this value as a reference for setting crashkernel value manually.

- 

- 

- New installed system

- ====================

- 

- Anaconda is the OS installer which sets all the kernel boot cmdline on a newly

- installed system. If kdump is enabled during Anaconda installation, Anaconda

- will use the default crashkernel value as the default `crashkernel=` value on

- the newly installed system.

- 

- Users can override the value during Anaconda installation manually.

- 

- 

- Auto update of crashkernel boot parameter

- =========================================

- 

- A new release of kexec-tools could update the default crashkernel value.  By

- default, kexec-tools would reset crashkernel to the new default value if it

- detects the old default crashkernel value is used by installed kernels. If you

- don't want kexec-tools to update the old default crashkernel to the new default

- crashkernel, you can change auto_reset_crashkernel to no in kdump.conf.

- 

- Supported Bootloaders

- ---------------------

- 

- This auto update only works with GRUB2 and ZIPL, as kexec-tools heavily depends

- on `grubby`. If other boot loaders are used, the user will have to update the

- `crashkernel=` value manually.

- 

- 

- Reset crashkernel to default value

- ==================================

- 

- kexec-tools only perform the auto update of crashkernel value when it can

- confirm the boot kernel's crashkernel value is using its corresponding default

- value and auto_reset_crashkernel=yes in kdump.conf. In other cases, the user

- can reset the crashkernel value by themselves.

- 

- Reset using kdumpctl

- --------------------

- 

- To make it easier to reset the `crashkernel=` kernel cmdline to this default

- value properly, `kdumpctl` also provides a sub-command:

- 

- 	`kdumpctl reset-crashkernel [--kernel=path_to_kernel] [--reboot]`

- 

- This command will reset the bootloader's kernel cmdline to the default value.

- It will also update bootloader config if the bootloader has a standalone config

- file. User will have to reboot the machine after this command to make it take

- effect if --reboot is not specified. For more details, please refer to the

- reset-crashkernel command in `man kdumpctl`.

- 

- Reset manually

- --------------

- 

- To reset the crashkernel value manually, it's recommended to use utils like

- `grubby`. A one liner script for resetting `crashkernel=` value of all installed

- kernels to the default value is:

- 

- 	grubby --update-kernel ALL --args "crashkernel=$(kdumpctl get-default-crashkernel)"

- 

- NOTE: On s390x you also need to run zipl for the change to take effect.

- 

- Estimate crashkernel

- ====================

- 

- The best way to estimate a usable crashkernel value is by testing kdump

- manually.  And you can set crashkernel to a large value, then adjust the

- crashkernel value to an acceptable value gradually.

- 

- `kdumpctl` also provides a sub-command for doing rough estimating without

- triggering kdump:

- 

- 	`kdumpctl estimate`

- 

- The output will be like this:

- 

- ```

-       Encrypted kdump target requires extra memory, assuming using the keyslot with minimum memory requirement

- 

-       Reserved crashkernel:    256M

-       Recommended crashkernel: 655M

- 

-       Kernel image size:   47M

-       Kernel modules size: 12M

-       Initramfs size:      19M

-       Runtime reservation: 64M

-       LUKS required size:  512M

-       Large modules:

-           xfs: 1892352

-           nouveau: 2318336

-       WARNING: Current crashkernel size is lower than recommended size 655M.

- ```

- 

- It will generate a summary report about the estimated memory consumption

- of each component of kdump. The value may not be accurate enough, but

- would be a good start for finding a suitable crashkernel value.

@@ -1,65 +0,0 @@ 

- #!/bin/bash

- 

- . /etc/sysconfig/kdump

- 

- KDUMP_KERNEL=""

- KDUMP_INITRD=""

- 

- check() {

-     if [[ ! -f /etc/sysconfig/kdump ]] || [[ ! -f /lib/kdump/kdump-lib.sh ]] \

-         || [[ -n ${IN_KDUMP} ]]; then

-         return 1

-     fi

-     return 255

- }

- 

- depends() {

-     echo "base shutdown"

-     return 0

- }

- 

- prepare_kernel_initrd() {

-     . /lib/kdump/kdump-lib.sh

- 

-     prepare_kdump_bootinfo

- 

-     # $kernel is a variable from dracut

-     if [[ $KDUMP_KERNELVER != "$kernel" ]]; then

-         dwarn "Using kernel version '$KDUMP_KERNELVER' for early kdump," \

-             "but the initramfs is generated for kernel version '$kernel'"

-     fi

- }

- 

- install() {

-     prepare_kernel_initrd

-     if [[ ! -f $KDUMP_KERNEL ]]; then

-         derror "Could not find required kernel for earlykdump," \

-             "earlykdump will not work!"

-         return 1

-     fi

-     if [[ ! -f $KDUMP_INITRD ]]; then

-         derror "Could not find required kdump initramfs for earlykdump," \

-             "please ensure kdump initramfs is generated first," \

-             "earlykdump will not work!"

-         return 1

-     fi

- 

-     inst_multiple tail find cut dirname hexdump

-     inst_simple "/etc/sysconfig/kdump"

-     inst_binary "/usr/sbin/kexec"

-     inst_binary "/usr/bin/gawk" "/usr/bin/awk"

-     inst_binary "/usr/bin/logger" "/usr/bin/logger"

-     inst_binary "/usr/bin/printf" "/usr/bin/printf"

-     inst_binary "/usr/bin/xargs" "/usr/bin/xargs"

-     inst_script "/lib/kdump/kdump-lib.sh" "/lib/kdump-lib.sh"

-     inst_script "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump/kdump-lib-initramfs.sh"

-     inst_script "/lib/kdump/kdump-logger.sh" "/lib/kdump-logger.sh"

-     inst_hook cmdline 00 "$moddir/early-kdump.sh"

-     inst_binary "$KDUMP_KERNEL"

-     inst_binary "$KDUMP_INITRD"

- 

-     ln_r "$KDUMP_KERNEL" "/boot/kernel-earlykdump"

-     ln_r "$KDUMP_INITRD" "/boot/initramfs-earlykdump"

- 

-     chmod -x "${initdir}/$KDUMP_KERNEL"

- }

file removed
-79
@@ -1,79 +0,0 @@ 

- #! /bin/bash

- 

- KEXEC=/sbin/kexec

- standard_kexec_args="-p"

- 

- EARLY_KDUMP_INITRD=""

- EARLY_KDUMP_KERNEL=""

- EARLY_KDUMP_CMDLINE=""

- EARLY_KEXEC_ARGS=""

- 

- . /etc/sysconfig/kdump

- . /lib/dracut-lib.sh

- . /lib/kdump-lib.sh

- . /lib/kdump-logger.sh

- 

- # initiate the kdump logger

- if ! dlog_init; then

-         echo "failed to initiate the kdump logger."

-         exit 1

- fi

- 

- prepare_parameters()

- {

-     EARLY_KDUMP_CMDLINE=$(prepare_cmdline "${KDUMP_COMMANDLINE}" "${KDUMP_COMMANDLINE_REMOVE}" "${KDUMP_COMMANDLINE_APPEND}")

-     EARLY_KDUMP_KERNEL="/boot/kernel-earlykdump"

-     EARLY_KDUMP_INITRD="/boot/initramfs-earlykdump"

- }

- 

- early_kdump_load()

- {

-     if ! check_kdump_feasibility; then

-         return 1

-     fi

- 

-     if is_fadump_capable; then

-         dwarn "WARNING: early kdump doesn't support fadump."

-         return 1

-     fi

- 

-     if is_kernel_loaded "kdump"; then

-         return 1

-     fi

- 

-     prepare_parameters

- 

-     EARLY_KEXEC_ARGS=$(prepare_kexec_args "${KEXEC_ARGS}")

- 

-     # Here, only output the messages, but do not save these messages

-     # to a file because the target disk may not be mounted yet, the

-     # earlykdump is too early.

-     ddebug "earlykdump: $KEXEC ${EARLY_KEXEC_ARGS} $standard_kexec_args \

- 	--command-line=$EARLY_KDUMP_CMDLINE --initrd=$EARLY_KDUMP_INITRD \

- 	$EARLY_KDUMP_KERNEL"

- 

-     # shellcheck disable=SC2086

-     if $KEXEC $EARLY_KEXEC_ARGS $standard_kexec_args \

-         --command-line="$EARLY_KDUMP_CMDLINE" \

-         --initrd=$EARLY_KDUMP_INITRD $EARLY_KDUMP_KERNEL; then

-         dinfo "kexec: loaded early-kdump kernel"

-         return 0

-     else

-         derror "kexec: failed to load early-kdump kernel"

-         return 1

-     fi

- }

- 

- set_early_kdump()

- {

-     if getargbool 0 rd.earlykdump; then

-         dinfo "early-kdump is enabled."

-         early_kdump_load

-     else

-         dinfo "early-kdump is disabled."

-     fi

- 

-     return 0

- }

- 

- set_early_kdump

@@ -1,48 +0,0 @@ 

- #!/bin/sh

- export PATH=/usr/bin:/usr/sbin

- export SYSTEMD_IN_INITRD=lenient

- 

- [ -e /proc/mounts ] ||

- 	(mkdir -p /proc && mount -t proc -o nosuid,noexec,nodev proc /proc)

- 

- grep -q '^sysfs /sys sysfs' /proc/mounts ||

- 	(mkdir -p /sys && mount -t sysfs -o nosuid,noexec,nodev sysfs /sys)

- 

- grep -q '^none / ' /proc/mounts || grep -q '^rootfs / ' /proc/mounts && ROOTFS_IS_RAMFS=1

- 

- if [ -f /proc/device-tree/rtas/ibm,kernel-dump ] || [ -f /proc/device-tree/ibm,opal/dump/mpipl-boot ]; then

- 	mkdir /newroot

- 	mount -t ramfs ramfs /newroot

- 

- 	if [ $ROOTFS_IS_RAMFS ]; then

- 		for FILE in $(ls -A /fadumproot/); do

- 			mv /fadumproot/$FILE /newroot/

- 		done

- 		exec switch_root /newroot /init

- 	else

- 		mkdir /newroot/sys /newroot/proc /newroot/dev /newroot/run /newroot/oldroot

- 

- 		grep -q '^devtmpfs /dev devtmpfs' /proc/mounts && mount --move /dev /newroot/dev

- 		grep -q '^tmpfs /run tmpfs' /proc/mounts && mount --move /run /newroot/run

- 		mount --move /sys /newroot/sys

- 		mount --move /proc /newroot/proc

- 

- 		cp --reflink=auto --sparse=auto --preserve=mode,timestamps,links -dfr /fadumproot/. /newroot/

- 		cd /newroot && pivot_root . oldroot

- 

- 		loop=1

- 		while [ $loop ]; do

- 			unset loop

- 			while read -r _ mp _; do

- 				case $mp in

- 				/oldroot/*) umount -d "$mp" && loop=1 ;;

- 				esac

- 			done </proc/mounts

- 		done

- 		umount -d -l oldroot

- 

- 		exec /init

- 	fi

- else

- 	exec /init.dracut

- fi

@@ -1,23 +0,0 @@ 

- #!/bin/bash

- 

- check() {

-     return 255

- }

- 

- depends() {

-     return 0

- }

- 

- install() {

-     mv -f "$initdir/init" "$initdir/init.dracut"

-     inst_script "$moddir/init-fadump.sh" /init

-     chmod a+x "$initdir/init"

- 

-     # Install required binaries for the init script (init-fadump.sh)

-     inst_multiple sh modprobe grep mkdir mount

-     if dracut_module_included "squash"; then

-         inst_multiple cp pivot_root umount

-     else

-         inst_multiple ls mv switch_root

-     fi

- }

@@ -1,30 +0,0 @@ 

- #  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.

- 

- [Unit]

- Description=Kdump Vmcore Save Service

- After=initrd.target initrd-parse-etc.service sysroot.mount

- After=dracut-initqueue.service dracut-pre-mount.service dracut-mount.service dracut-pre-pivot.service

- Before=initrd-cleanup.service

- ConditionPathExists=/etc/initrd-release

- OnFailure=emergency.target

- OnFailureJobMode=isolate

- 

- [Service]

- Environment=DRACUT_SYSTEMD=1

- Environment=NEWROOT=/sysroot

- Type=oneshot

- ExecStart=/bin/kdump.sh

- StandardInput=null

- StandardOutput=journal

- StandardError=journal+console

- KillMode=process

- RemainAfterExit=yes

- 

- # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash

- # terminates cleanly.

- KillSignal=SIGHUP

@@ -1,27 +0,0 @@ 

- # This service will run the real kdump error handler code. Executing the

- # failure action configured in kdump.conf

- 

- [Unit]

- Description=Kdump Error Handler

- DefaultDependencies=no

- After=systemd-vconsole-setup.service

- Wants=systemd-vconsole-setup.service

- 

- [Service]

- Environment=HOME=/

- Environment=DRACUT_SYSTEMD=1

- Environment=NEWROOT=/sysroot

- WorkingDirectory=/

- ExecStart=/bin/kdump.sh --error-handler

- ExecStopPost=-/bin/rm -f -- /.console_lock

- Type=oneshot

- StandardInput=tty-force

- StandardOutput=inherit

- StandardError=inherit

- KillMode=process

- IgnoreSIGPIPE=no

- TasksMax=infinity

- 

- # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash

- # terminates cleanly.

- KillSignal=SIGHUP

@@ -1,14 +0,0 @@ 

- #  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.

- 

- [Unit]

- Description=Emergency Mode

- Documentation=man:systemd.special(7)

- Requires=emergency.service

- After=emergency.service

- AllowIsolate=yes

- IgnoreOnIsolate=yes

file removed
-624
@@ -1,624 +0,0 @@ 

- #!/bin/sh

- #

- # The main kdump routine in capture kernel, bash may not be the

- # default shell. Any code added must be POSIX compliant.

- 

- . /lib/dracut-lib.sh

- . /lib/kdump-logger.sh

- . /lib/kdump-lib-initramfs.sh

- 

- #initiate the kdump logger

- if ! dlog_init; then

- 	echo "failed to initiate the kdump logger."

- 	exit 1

- fi

- 

- KDUMP_PATH="/var/crash"

- KDUMP_LOG_FILE="/run/initramfs/kexec-dmesg.log"

- KDUMP_LOG_DEST=""

- KDUMP_LOG_OP=""

- CORE_COLLECTOR=""

- DEFAULT_CORE_COLLECTOR="makedumpfile -l --message-level 7 -d 31"

- DMESG_COLLECTOR="/sbin/vmcore-dmesg"

- FAILURE_ACTION="systemctl reboot -f"

- DATEDIR=$(date +%Y-%m-%d-%T)

- HOST_IP='127.0.0.1'

- DUMP_INSTRUCTION=""

- SSH_KEY_LOCATION=$DEFAULT_SSHKEY

- DD_BLKSIZE=512

- FINAL_ACTION="systemctl reboot -f"

- KDUMP_PRE=""

- KDUMP_POST=""

- NEWROOT="/sysroot"

- OPALCORE="/sys/firmware/opal/mpipl/core"

- KDUMP_CONF_PARSED="/tmp/kdump.conf.$$"

- 

- # POSIX doesn't have pipefail, only apply when using bash

- # shellcheck disable=SC3040

- [ -n "$BASH" ] && set -o pipefail

- 

- DUMP_RETVAL=0

- 

- kdump_read_conf > $KDUMP_CONF_PARSED

- 

- get_kdump_confs()

- {

- 	while read -r config_opt config_val; do

- 		# remove inline comments after the end of a directive.

- 		case "$config_opt" in

- 		path)

- 			KDUMP_PATH="$config_val"

- 			;;

- 		core_collector)

- 			[ -n "$config_val" ] && CORE_COLLECTOR="$config_val"

- 			;;

- 		sshkey)

- 			if [ -f "$config_val" ]; then

- 				SSH_KEY_LOCATION=$config_val

- 			fi

- 			;;

- 		kdump_pre)

- 			KDUMP_PRE="$config_val"

- 			;;

- 		kdump_post)

- 			KDUMP_POST="$config_val"

- 			;;

- 		fence_kdump_args)

- 			FENCE_KDUMP_ARGS="$config_val"

- 			;;

- 		fence_kdump_nodes)

- 			FENCE_KDUMP_NODES="$config_val"

- 			;;

- 		failure_action | default)

- 			case $config_val in

- 			shell)

- 				FAILURE_ACTION="kdump_emergency_shell"

- 				;;

- 			reboot)

- 				FAILURE_ACTION="systemctl reboot -f && exit"

- 				;;

- 			halt)

- 				FAILURE_ACTION="halt && exit"

- 				;;

- 			poweroff)

- 				FAILURE_ACTION="systemctl poweroff -f && exit"

- 				;;

- 			dump_to_rootfs)

- 				FAILURE_ACTION="dump_to_rootfs"

- 				;;

- 			esac

- 			;;

- 		final_action)

- 			case $config_val in

- 			reboot)

- 				FINAL_ACTION="systemctl reboot -f"

- 				;;

- 			halt)

- 				FINAL_ACTION="halt"

- 				;;

- 			poweroff)

- 				FINAL_ACTION="systemctl poweroff -f"

- 				;;

- 			esac

- 			;;

- 		esac

- 	done < "$KDUMP_CONF_PARSED"

- 

- 	if [ -z "$CORE_COLLECTOR" ]; then

- 		CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR"

- 		if is_ssh_dump_target || is_raw_dump_target; then

- 			CORE_COLLECTOR="$CORE_COLLECTOR -F"

- 		fi

- 	fi

- }

- 

- # store the kexec kernel log to a file.

- save_log()

- {

- 	# LOG_OP is empty when log can't be saved, eg. raw target

- 	[ -n "$KDUMP_LOG_OP" ] || return

- 

- 	dmesg -T > $KDUMP_LOG_FILE

- 

- 	if command -v journalctl > /dev/null; then

- 		journalctl -ab >> $KDUMP_LOG_FILE

- 	fi

- 	chmod 600 $KDUMP_LOG_FILE

- 

- 	dinfo "saving the $KDUMP_LOG_FILE to $KDUMP_LOG_DEST/"

- 

- 	eval "$KDUMP_LOG_OP"

- }

- 

- # $1: dump path, must be a mount point

- dump_fs()

- {

- 	ddebug "dump_fs _mp=$1"

- 

- 	if ! is_mounted "$1"; then

- 		dinfo "dump path '$1' is not mounted, trying to mount..."

- 		if ! mount --target "$1"; then

- 			derror "failed to dump to '$1', it's not a mount point!"

- 			return 1

- 		fi

- 	fi

- 

- 	# Remove -F in makedumpfile case. We don't want a flat format dump here.

- 	case $CORE_COLLECTOR in

- 	*makedumpfile*)

- 		CORE_COLLECTOR=$(echo "$CORE_COLLECTOR" | sed -e "s/-F//g")

- 		;;

- 	esac

- 

- 	_dump_fs_path=$(echo "$1/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /)

- 	dinfo "saving to $_dump_fs_path"

- 

- 	# Only remount to read-write mode if the dump target is mounted read-only.

- 	_dump_mnt_op=$(get_mount_info OPTIONS target "$1" -f)

- 	case $_dump_mnt_op in

- 	ro*)

- 		dinfo "Remounting the dump target in rw mode."

- 		mount -o remount,rw "$1" || return 1

- 		;;

- 	esac

- 

- 	mkdir -p "$_dump_fs_path" || return 1

- 

- 	save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_dump_fs_path"

- 	save_opalcore_fs "$_dump_fs_path"

- 

- 	dinfo "saving vmcore"

- 	KDUMP_LOG_DEST=$_dump_fs_path/

- 	KDUMP_LOG_OP="mv '$KDUMP_LOG_FILE' '$KDUMP_LOG_DEST/'"

- 

- 	$CORE_COLLECTOR /proc/vmcore "$_dump_fs_path/vmcore-incomplete"

- 	_dump_exitcode=$?

- 	if [ $_dump_exitcode -eq 0 ]; then

- 		sync -f "$_dump_fs_path/vmcore-incomplete"

- 		_sync_exitcode=$?

- 		if [ $_sync_exitcode -eq 0 ]; then

- 			mv "$_dump_fs_path/vmcore-incomplete" "$_dump_fs_path/vmcore"

- 			dinfo "saving vmcore complete"

- 		else

- 			derror "sync vmcore failed, exitcode:$_sync_exitcode"

- 			return 1

- 		fi

- 	else

- 		derror "saving vmcore failed, exitcode:$_dump_exitcode"

- 		return 1

- 	fi

- 

- 	# improper kernel cmdline can cause the failure of echo, we can ignore this kind of failure

- 	return 0

- }

- 

- # $1: dmesg collector

- # $2: dump path

- save_vmcore_dmesg_fs()

- {

- 	dinfo "saving vmcore-dmesg.txt to $2"

- 	if $1 /proc/vmcore > "$2/vmcore-dmesg-incomplete.txt"; then

- 		mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt"

- 		chmod 600 "$2/vmcore-dmesg.txt"

- 

- 		# Make sure file is on disk. There have been instances where later

- 		# saving vmcore failed and system rebooted without sync and there

- 		# was no vmcore-dmesg.txt available.

- 		sync

- 		dinfo "saving vmcore-dmesg.txt complete"

- 	else

- 		if [ -f "$2/vmcore-dmesg-incomplete.txt" ]; then

- 			chmod 600 "$2/vmcore-dmesg-incomplete.txt"

- 		fi

- 		derror "saving vmcore-dmesg.txt failed"

- 	fi

- }

- 

- # $1: dump path

- save_opalcore_fs()

- {

- 	if [ ! -f $OPALCORE ]; then

- 		# Check if we are on an old kernel that uses a different path

- 		if [ -f /sys/firmware/opal/core ]; then

- 			OPALCORE="/sys/firmware/opal/core"

- 		else

- 			return 0

- 		fi

- 	fi

- 

- 	dinfo "saving opalcore:$OPALCORE to $1/opalcore"

- 	if ! cp $OPALCORE "$1/opalcore"; then

- 		derror "saving opalcore failed"

- 		return 1

- 	fi

- 

- 	sync

- 	dinfo "saving opalcore complete"

- 	return 0

- }

- 

- dump_to_rootfs()

- {

- 

- 	if [ "$(systemctl status dracut-initqueue | sed -n "s/^\s*Active: \(\S*\)\s.*$/\1/p")" = "inactive" ]; then

- 		dinfo "Trying to bring up initqueue for rootfs mount"

- 		systemctl start dracut-initqueue

- 	fi

- 

- 	dinfo "Clean up dead systemd services"

- 	systemctl cancel

- 	dinfo "Waiting for rootfs mount, will timeout after 90 seconds"

- 	systemctl start --no-block sysroot.mount

- 

- 	_loop=0

- 	while [ $_loop -lt 90 ] && ! is_mounted /sysroot; do

- 		sleep 1

- 		_loop=$((_loop + 1))

- 	done

- 

- 	if ! is_mounted /sysroot; then

- 		derror "Failed to mount rootfs"

- 		return

- 	fi

- 

- 	ddebug "NEWROOT=$NEWROOT"

- 	dump_fs $NEWROOT

- }

- 

- kdump_emergency_shell()

- {

- 	ddebug "Switching to kdump emergency shell..."

- 

- 	[ -f /etc/profile ] && . /etc/profile

- 	export PS1='kdump:${PWD}# '

- 

- 	. /lib/dracut-lib.sh

- 	if [ -f /dracut-state.sh ]; then

- 		. /dracut-state.sh 2> /dev/null

- 	fi

- 

- 	source_conf /etc/conf.d

- 

- 	type plymouth > /dev/null 2>&1 && plymouth quit

- 

- 	source_hook "emergency"

- 	while read -r _tty rest; do

- 		(

- 			echo

- 			echo

- 			echo 'Entering kdump emergency mode.'

- 			echo 'Type "journalctl" to view system logs.'

- 			echo 'Type "rdsosreport" to generate a sosreport, you can then'

- 			echo 'save it elsewhere and attach it to a bug report.'

- 			echo

- 			echo

- 		) > "/dev/$_tty"

- 	done < /proc/consoles

- 	sh -i -l

- 	/bin/rm -f -- /.console_lock

- }

- 

- do_failure_action()

- {

- 	dinfo "Executing failure action $FAILURE_ACTION"

- 	eval $FAILURE_ACTION

- }

- 

- do_final_action()

- {

- 	dinfo "Executing final action $FINAL_ACTION"

- 	eval $FINAL_ACTION

- }

- 

- do_dump()

- {

- 	eval $DUMP_INSTRUCTION

- 	_ret=$?

- 

- 	if [ $_ret -ne 0 ]; then

- 		derror "saving vmcore failed"

- 	fi

- 

- 	return $_ret

- }

- 

- do_kdump_pre()

- {

- 	if [ -n "$KDUMP_PRE" ]; then

- 		"$KDUMP_PRE"

- 		_ret=$?

- 		if [ $_ret -ne 0 ]; then

- 			derror "$KDUMP_PRE exited with $_ret status"

- 			return $_ret

- 		fi

- 	fi

- 

- 	# if any script fails, it just raises warning and continues

- 	if [ -d /etc/kdump/pre.d ]; then

- 		for file in /etc/kdump/pre.d/*; do

- 			"$file"

- 			_ret=$?

- 			if [ $_ret -ne 0 ]; then

- 				derror "$file exited with $_ret status"

- 			fi

- 		done

- 	fi

- 	return 0

- }

- 

- do_kdump_post()

- {

- 	if [ -d /etc/kdump/post.d ]; then

- 		for file in /etc/kdump/post.d/*; do

- 			"$file" "$1"

- 			_ret=$?

- 			if [ $_ret -ne 0 ]; then

- 				derror "$file exited with $_ret status"

- 			fi

- 		done

- 	fi

- 

- 	if [ -n "$KDUMP_POST" ]; then

- 		"$KDUMP_POST" "$1"

- 		_ret=$?

- 		if [ $_ret -ne 0 ]; then

- 			derror "$KDUMP_POST exited with $_ret status"

- 		fi

- 	fi

- }

- 

- # $1: block target, eg. /dev/sda

- dump_raw()

- {

- 	[ -b "$1" ] || return 1

- 

- 	dinfo "saving to raw disk $1"

- 

- 	if ! echo "$CORE_COLLECTOR" | grep -q makedumpfile; then

- 		_src_size=$(stat --format %s /proc/vmcore)

- 		_src_size_mb=$((_src_size / 1048576))

- 		/kdumpscripts/monitor_dd_progress $_src_size_mb &

- 	fi

- 

- 	dinfo "saving vmcore"

- 	$CORE_COLLECTOR /proc/vmcore | dd of="$1" bs=$DD_BLKSIZE >> /tmp/dd_progress_file 2>&1 || return 1

- 	sync

- 

- 	dinfo "saving vmcore complete"

- 	return 0

- }

- 

- # $1: ssh key file

- # $2: ssh address in <user>@<host> format

- dump_ssh()

- {

- 	_ret=0

- 	_ssh_opt="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes"

- 	_ssh_dir="$KDUMP_PATH/$HOST_IP-$DATEDIR"

- 	if is_ipv6_address "$2"; then

- 		_scp_address=${2%@*}@"[${2#*@}]"

- 	else

- 		_scp_address=$2

- 	fi

- 

- 	dinfo "saving to $2:$_ssh_dir"

- 

- 	cat /var/lib/random-seed > /dev/urandom

- 	ssh -q $_ssh_opt "$2" mkdir -p "$_ssh_dir" || return 1

- 

- 	save_vmcore_dmesg_ssh "$DMESG_COLLECTOR" "$_ssh_dir" "$_ssh_opt" "$2"

- 

- 	dinfo "saving vmcore"

- 

- 	KDUMP_LOG_DEST=$2:$_ssh_dir/

- 	KDUMP_LOG_OP="scp -q $_ssh_opt '$KDUMP_LOG_FILE' '$_scp_address:$_ssh_dir/'"

- 

- 	save_opalcore_ssh "$_ssh_dir" "$_ssh_opt" "$2" "$_scp_address"

- 

- 	if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then

- 		scp -q $_ssh_opt /proc/vmcore "$_scp_address:$_ssh_dir/vmcore-incomplete"

- 		_ret=$?

- 		_vmcore="vmcore"

- 	else

- 		$CORE_COLLECTOR /proc/vmcore | ssh $_ssh_opt "$2" "umask 0077 && dd bs=512 of='$_ssh_dir/vmcore-incomplete'"

- 		_ret=$?

- 		_vmcore="vmcore.flat"

- 	fi

- 

- 	if [ $_ret -eq 0 ]; then

- 		ssh $_ssh_opt "$2" "mv '$_ssh_dir/vmcore-incomplete' '$_ssh_dir/$_vmcore'"

- 		_ret=$?

- 		if [ $_ret -ne 0 ]; then

- 			derror "moving vmcore failed, exitcode:$_ret"

- 		else

- 			dinfo "saving vmcore complete"

- 		fi

- 	else

- 		derror "saving vmcore failed, exitcode:$_ret"

- 	fi

- 

- 	return $_ret

- }

- 

- # $1: dump path

- # $2: ssh opts

- # $3: ssh address in <user>@<host> format

- # $4: scp address, similar with ssh address but IPv6 addresses are quoted

- save_opalcore_ssh()

- {

- 	if [ ! -f $OPALCORE ]; then

- 		# Check if we are on an old kernel that uses a different path

- 		if [ -f /sys/firmware/opal/core ]; then

- 			OPALCORE="/sys/firmware/opal/core"

- 		else

- 			return 0

- 		fi

- 	fi

- 

- 	dinfo "saving opalcore:$OPALCORE to $3:$1"

- 

- 	if ! scp $2 $OPALCORE "$4:$1/opalcore-incomplete"; then

- 		derror "saving opalcore failed"

- 		return 1

- 	fi

- 

- 	ssh $2 "$3" mv "$1/opalcore-incomplete" "$1/opalcore"

- 	dinfo "saving opalcore complete"

- 	return 0

- }

- 

- # $1: dmesg collector

- # $2: dump path

- # $3: ssh opts

- # $4: ssh address in <user>@<host> format

- save_vmcore_dmesg_ssh()

- {

- 	dinfo "saving vmcore-dmesg.txt to $4:$2"

- 	if $1 /proc/vmcore | ssh $3 "$4" "umask 0077 && dd of='$2/vmcore-dmesg-incomplete.txt'"; then

- 		ssh -q $3 "$4" mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt"

- 		dinfo "saving vmcore-dmesg.txt complete"

- 	else

- 		derror "saving vmcore-dmesg.txt failed"

- 	fi

- }

- 

- wait_online_network()

- {

- 	# In some cases, network may still not be ready because nm-online is called

- 	# with "-s" which means to wait for NetworkManager startup to complete, rather

- 	# than waiting for network connectivity specifically. Wait 10mins more for the

- 	# network to be truely ready in these cases.

- 	_loop=0

- 	while [ $_loop -lt 600 ]; do

- 		sleep 1

- 		_loop=$((_loop + 1))

- 		if _route=$(kdump_get_ip_route "$1" 2> /dev/null); then

- 			printf "%s" "$_route"

- 			return

- 		else

- 			dwarn "Waiting for network to be ready (${_loop}s / 10min)"

- 		fi

- 	done

- 

- 	derror "Oops. The network still isn't ready after waiting 10mins."

- 	exit 1

- }

- 

- get_host_ip()

- {

- 

- 	if ! is_nfs_dump_target && ! is_ssh_dump_target; then

- 		return 0

- 	fi

- 

- 	_kdump_remote_ip=$(getarg kdump_remote_ip=)

- 

- 	if [ -z "$_kdump_remote_ip" ]; then

- 		derror "failed to get remote IP address!"

- 		return 1

- 	fi

- 

- 	if ! _route=$(wait_online_network "$_kdump_remote_ip"); then

- 		return 1

- 	fi

- 

- 	_netdev=$(kdump_get_ip_route_field "$_route" "dev")

- 

- 	if ! _kdumpip=$(ip addr show dev "$_netdev" | grep '[ ]*inet'); then

- 		derror "Failed to get IP of $_netdev"

- 		return 1

- 	fi

- 

- 	_kdumpip=$(echo "$_kdumpip" | head -n 1 | awk '{print $2}')

- 	_kdumpip="${_kdumpip%%/*}"

- 	HOST_IP=$_kdumpip

- }

- 

- read_kdump_confs()

- {

- 	if [ ! -f "$KDUMP_CONFIG_FILE" ]; then

- 		derror "$KDUMP_CONFIG_FILE not found"

- 		return

- 	fi

- 

- 	get_kdump_confs

- 

- 	# rescan for add code for dump target

- 	while read -r config_opt config_val; do

- 		# remove inline comments after the end of a directive.

- 		case "$config_opt" in

- 		dracut_args)

- 			config_val=$(get_dracut_args_target "$config_val")

- 			if [ -n "$config_val" ]; then

- 				config_val=$(get_mntpoint_from_target "$config_val")

- 				DUMP_INSTRUCTION="dump_fs $config_val"

- 			fi

- 			;;

- 		ext[234] | xfs | btrfs | minix | nfs | virtiofs)

- 			config_val=$(get_mntpoint_from_target "$config_val")

- 			DUMP_INSTRUCTION="dump_fs $config_val"

- 			;;

- 		raw)

- 			DUMP_INSTRUCTION="dump_raw $config_val"

- 			;;

- 		ssh)

- 			DUMP_INSTRUCTION="dump_ssh $SSH_KEY_LOCATION $config_val"

- 			;;

- 		esac

- 	done < "$KDUMP_CONF_PARSED"

- }

- 

- fence_kdump_notify()

- {

- 	if [ -n "$FENCE_KDUMP_NODES" ]; then

- 		# shellcheck disable=SC2086

- 		$FENCE_KDUMP_SEND $FENCE_KDUMP_ARGS $FENCE_KDUMP_NODES &

- 	fi

- }

- 

- if [ "$1" = "--error-handler" ]; then

- 	get_kdump_confs

- 	do_failure_action

- 	do_final_action

- 

- 	exit $?

- fi

- 

- # continue here only if we have to save dump.

- if [ -f /etc/fadump.initramfs ] && [ ! -f /proc/device-tree/rtas/ibm,kernel-dump ] && [ ! -f /proc/device-tree/ibm,opal/dump/mpipl-boot ]; then

- 	exit 0

- fi

- 

- read_kdump_confs

- fence_kdump_notify

- 

- if ! get_host_ip; then

- 	derror "get_host_ip exited with non-zero status!"

- 	exit 1

- fi

- 

- if [ -z "$DUMP_INSTRUCTION" ]; then

- 	DUMP_INSTRUCTION="dump_fs $NEWROOT"

- fi

- 

- if ! do_kdump_pre; then

- 	derror "kdump_pre script exited with non-zero status!"

- 	do_final_action

- 	# During systemd service to reboot the machine, stop this shell script running

- 	exit 1

- fi

- make_trace_mem "kdump saving vmcore" '1:shortmem' '2+:mem' '3+:slab'

- do_dump

- DUMP_RETVAL=$?

- 

- if ! do_kdump_post $DUMP_RETVAL; then

- 	derror "kdump_post script exited with non-zero status!"

- fi

- 

- save_log

- 

- if [ $DUMP_RETVAL -ne 0 ]; then

- 	exit 1

- fi

- 

- do_final_action

file removed
-1084
@@ -1,1084 +0,0 @@ 

- #!/bin/bash

- 

- _DRACUT_KDUMP_NM_TMP_DIR="$DRACUT_TMPDIR/$$-DRACUT_KDUMP_NM"

- 

- _save_kdump_netifs() {

-     unique_netifs[$1]=1

- }

- 

- _get_kdump_netifs() {

-     echo -n "${!unique_netifs[@]}"

- }

- 

- kdump_module_init() {

-     if ! [[ -d "${initdir}/tmp" ]]; then

-         mkdir -p "${initdir}/tmp"

-     fi

- 

-     mkdir -p "$_DRACUT_KDUMP_NM_TMP_DIR"

- 

-     . /lib/kdump/kdump-lib.sh

- }

- 

- check() {

-     [[ $debug ]] && set -x

-     #kdumpctl sets this explicitly

-     if [[ -z $IN_KDUMP ]] || [[ ! -f /etc/kdump.conf ]]; then

-         return 1

-     fi

-     if [[ "$(uname -m)" == "s390x" ]]; then

- 	require_binaries chzdev || return 1

-     fi

-     return 0

- }

- 

- depends() {

-     local _dep="base shutdown"

- 

-     kdump_module_init

- 

-     add_opt_module() {

-         [[ " $omit_dracutmodules " != *\ $1\ * ]] && _dep="$_dep $1"

-     }

- 

-     if is_squash_available; then

-         add_opt_module squash

-     else

-         dwarning "Required modules to build a squashed kdump image is missing!"

-     fi

- 

-     if is_wdt_active; then

-         add_opt_module watchdog

-     fi

- 

-     if is_ssh_dump_target; then

-         _dep="$_dep ssh-client"

-     fi

- 

-     if is_lvm2_thinp_dump_target; then

-         if dracut --list-modules | grep -q lvmthinpool-monitor; then

-             add_opt_module lvmthinpool-monitor

-         else

-             dwarning "Required lvmthinpool-monitor modules is missing! Please upgrade dracut >= 057."

-         fi

-     fi

- 

-     if [[ "$(uname -m)" == "s390x" ]]; then

-         _dep="$_dep znet"

-     fi

- 

-     if [[ -n "$(ls -A /sys/class/drm 2> /dev/null)" ]] || [[ -d /sys/module/hyperv_fb ]]; then

-         add_opt_module drm

-     fi

- 

-     if is_generic_fence_kdump || is_pcs_fence_kdump; then

-         _dep="$_dep network"

-     fi

- 

-     echo "$_dep"

- }

- 

- kdump_is_bridge() {

-     [[ -d /sys/class/net/"$1"/bridge ]]

- }

- 

- kdump_is_bond() {

-     [[ -d /sys/class/net/"$1"/bonding ]]

- }

- 

- kdump_is_team() {

-     [[ -f /usr/bin/teamnl ]] && teamnl "$1" ports &> /dev/null

- }

- 

- kdump_is_vlan() {

-     [[ -f /proc/net/vlan/"$1" ]]

- }

- 

- # $1: repeat times

- # $2: string to be repeated

- # $3: separator

- repeatedly_join_str() {

-     local _count="$1"

-     local _str="$2"

-     local _separator="$3"

-     local i _res

- 

-     if [[ $_count -le 0 ]]; then

-         echo -n ""

-         return

-     fi

- 

-     i=0

-     _res="$_str"

-     ((_count--))

- 

-     while [[ $i -lt $_count ]]; do

-         ((i++))

-         _res="${_res}${_separator}${_str}"

-     done

-     echo -n "$_res"

- }

- 

- # $1: prefix

- # $2: ipv6_flag="-6" indicates it's IPv6

- # Given a prefix, calculate the netmask (equivalent of "ipcalc -m")

- # by concatenating three parts,

- #  1) the groups with all bits set 1

- #  2) a group with partial bits set to 0

- #  3) the groups with all bits set to 0

- cal_netmask_by_prefix() {

-     local _prefix="$1"

-     local _ipv6_flag="$2" _ipv6

-     local _bits_per_octet=8

-     local _count _res _octets_per_group _octets_total _seperator _total_groups

-     local _max_group_value _max_group_value_repr _bits_per_group _tmp _zero_bits

- 

-     if [[ $_ipv6_flag == "-6" ]]; then

-         _ipv6=1

-     else

-         _ipv6=0

-     fi

- 

-     if [[ $_prefix -lt 0 || $_prefix -gt 128 ]] \

-         || ( ((!_ipv6)) && [[ $_prefix -gt 32 ]]); then

-         derror "Bad prefix:$_prefix for calculating netmask"

-         exit 1

-     fi

- 

-     if ((_ipv6)); then

-         _octets_per_group=2

-         _octets_total=16

-         _seperator=":"

-     else

-         _octets_per_group=1

-         _octets_total=4

-         _seperator="."

-     fi

- 

-     _total_groups=$((_octets_total / _octets_per_group))

-     _bits_per_group=$((_octets_per_group * _bits_per_octet))

-     _max_group_value=$(((1 << _bits_per_group) - 1))

- 

-     if ((_ipv6)); then

-         _max_group_value_repr=$(printf "%x" $_max_group_value)

-     else

-         _max_group_value_repr="$_max_group_value"

-     fi

- 

-     _count=$((_prefix / _octets_per_group / _bits_per_octet))

-     _first_part=$(repeatedly_join_str "$_count" "$_max_group_value_repr" "$_seperator")

-     _res="$_first_part"

- 

-     _tmp=$((_octets_total * _bits_per_octet - _prefix))

-     _zero_bits=$((_tmp % _bits_per_group))

-     if [[ $_zero_bits -ne 0 ]]; then

-         _second_part=$((_max_group_value >> _zero_bits << _zero_bits))

-         if ((_ipv6)); then

-             _second_part=$(printf "%x" $_second_part)

-         fi

-         ((_count++))

-         if [[ -z $_first_part ]]; then

-             _res="$_second_part"

-         else

-             _res="${_first_part}${_seperator}${_second_part}"

-         fi

-     fi

- 

-     _count=$((_total_groups - _count))

-     if [[ $_count -eq 0 ]]; then

-         echo -n "$_res"

-         return

-     fi

- 

-     if ((_ipv6)) && [[ $_count -gt 1 ]]; then

-         # use condensed notion for IPv6

-         _third_part=":"

-     else

-         _third_part=$(repeatedly_join_str "$_count" "0" "$_seperator")

-     fi

- 

-     if [[ -z $_res ]] && ((!_ipv6)); then

-         echo -n "${_third_part}"

-     else

-         echo -n "${_res}${_seperator}${_third_part}"

-     fi

- }

- 

- kdump_get_mac_addr() {

-     cat "/sys/class/net/$1/address"

- }

- 

- #Bonding or team master modifies the mac address

- #of its slaves, we should use perm address

- kdump_get_perm_addr() {

-     local addr

-     addr=$(ethtool -P "$1" | sed -e 's/Permanent address: //')

-     if [[ -z $addr ]] || [[ $addr == "00:00:00:00:00:00" ]]; then

-         derror "Can't get the permanent address of $1"

-     else

-         echo "$addr"

-     fi

- }

- 

- apply_nm_initrd_generator_timeouts() {

-     local _timeout_conf

- 

-     _timeout_conf=$_DRACUT_KDUMP_NM_TMP_DIR/timeout_conf

-     cat << EOF > "$_timeout_conf"

- [device-95-kdump]

- carrier-wait-timeout=30000

- 

- [connection-95-kdump]

- ipv4.dhcp-timeout=90

- ipv6.dhcp-timeout=90

- EOF

- 

-     inst "$_timeout_conf" "/etc/NetworkManager/conf.d/95-kdump-timeouts.conf"

- }

- 

- use_ipv4_or_ipv6() {

-     local _netif=$1 _uuid=$2

- 

-     if [[ -v "ipv4_usage[$_netif]" ]]; then

-         nmcli connection modify --temporary "$_uuid" ipv4.may-fail no &> >(ddebug)

-     fi

- 

-     if [[ -v "ipv6_usage[$_netif]" ]]; then

-         nmcli connection modify --temporary "$_uuid" ipv6.may-fail no &> >(ddebug)

-     fi

- 

-     if [[ -v "ipv4_usage[$_netif]" ]] && [[ ! -v "ipv6_usage[$_netif]" ]]; then

-         nmcli connection modify --temporary "$_uuid" ipv6.method disabled &> >(ddebug)

-     elif [[ ! -v "ipv4_usage[$_netif]" ]] && [[ -v "ipv6_usage[$_netif]" ]]; then

-         nmcli connection modify --temporary "$_uuid" ipv4.method disabled &> >(ddebug)

-     fi

- }

- 

- _clone_nmconnection() {

-     local _clone_output _name _unique_id

- 

-     _unique_id=$1

-     _name=$(nmcli --get-values connection.id connection show "$_unique_id")

-     if _clone_output=$(nmcli connection clone --temporary uuid "$_unique_id" "$_name"); then

-         sed -E -n "s/.* \(.*\) cloned as.*\((.*)\)\.$/\1/p" <<< "$_clone_output"

-         return 0

-     fi

- 

-     return 1

- }

- 

- _match_nmconnection_by_mac() {

-     local _unique_id _dev _mac _mac_field

- 

-     _unique_id=$1

-     _dev=$2

- 

-     _mac=$(kdump_get_perm_addr "$_dev")

-     [[ $_mac != 'not set' ]] || return

-     _mac_field=$(nmcli --get-values connection.type connection show "$_unique_id").mac-address

-     nmcli connection modify --temporary "$_unique_id" "$_mac_field" "$_mac" &> >(ddebug)

-     nmcli connection modify --temporary "$_unique_id" "connection.interface-name" "" &> >(ddebug)

- }

- 

- # Clone and modify NM connection profiles

- #

- # This function makes use of "nmcli clone" to automatically convert ifcfg-*

- # files to Networkmanager .nmconnection connection profiles and also modify the

- # properties of .nmconnection if necessary.

- clone_and_modify_nmconnection() {

-     local _dev _cloned_nmconnection_file_path _tmp_nmconnection_file_path _old_uuid _uuid

- 

-     _dev=$1

-     _nmconnection_file_path=$2

- 

-     _old_uuid=$(nmcli --get-values connection.uuid connection show filename "$_nmconnection_file_path")

- 

-     if ! _uuid=$(_clone_nmconnection "$_old_uuid"); then

-         derror "Failed to clone $_old_uuid"

-         exit 1

-     fi

- 

-     use_ipv4_or_ipv6 "$_dev" "$_uuid"

- 

-     nmcli connection modify --temporary uuid "$_uuid" connection.wait-device-timeout 60000 &> >(ddebug)

-     # For physical NIC i.e. non-user created NIC, ask NM to match a

-     # connection profile based on MAC address

-     _match_nmconnection_by_mac "$_uuid" "$_dev"

- 

-     # If a value contain ":", nmcli by default escape it with "\:" because it

-     # also uses ":" as the delimiter to separate values. In our case, escaping is not needed.

-     _cloned_nmconnection_file_path=$(nmcli --escape no --get-values UUID,FILENAME connection show | sed -n "s/^${_uuid}://p")

-     _tmp_nmconnection_file_path=$_DRACUT_KDUMP_NM_TMP_DIR/$(basename "$_nmconnection_file_path")

-     cp "$_cloned_nmconnection_file_path" "$_tmp_nmconnection_file_path"

-     # change uuid back to old value in case it's refered by other connection

-     # profile e.g. connection.master could be interface name of the master

-     # device or UUID of the master connection.

-     sed -i -E "s/(^uuid=).*$/\1${_old_uuid}/g" "$_tmp_nmconnection_file_path"

-     nmcli connection del "$_uuid" &> >(ddebug)

-     echo -n "$_tmp_nmconnection_file_path"

- }

- 

- _install_nmconnection() {

-     local _src _nmconnection_name _dst

- 

-     _src=$1

-     _nmconnection_name=$(basename "$_src")

-     _dst="/etc/NetworkManager/system-connections/$_nmconnection_name"

-     inst "$_src" "$_dst"

- }

- 

- kdump_install_nmconnections() {

-     local _netif _nm_conn_path _cloned_nm_path

- 

-     while IFS=: read -r _netif _nm_conn_path; do

-         [[ -v "unique_netifs[$_netif]" ]] || continue

-         if _cloned_nm_path=$(clone_and_modify_nmconnection "$_netif" "$_nm_conn_path"); then

-             _install_nmconnection "$_cloned_nm_path"

-         else

-             derror "Failed to install the .nmconnection for $_netif"

-             exit 1

-         fi

-     done <<< "$(nmcli -t -f device,filename connection show --active)"

- 

-     # Stop dracut 35network-manger to calling nm-initrd-generator.

-     # Note this line of code can be removed after NetworkManager >= 1.35.2

-     # gets released.

-     echo > "${initdir}/usr/libexec/nm-initrd-generator"

- }

- 

- kdump_install_nm_netif_allowlist() {

-     local _netif _except_netif _netif_allowlist _netif_allowlist_nm_conf

- 

-     for _netif in $1; do

-         _per_mac=$(kdump_get_perm_addr "$_netif")

-         if [[ "$_per_mac" != 'not set' ]]; then

-             _except_netif="mac:$_per_mac"

-         else

-             _except_netif="interface-name:$_netif"

-         fi

-         _netif_allowlist="${_netif_allowlist}except:${_except_netif};"

-     done

- 

-     _netif_allowlist_nm_conf=$_DRACUT_KDUMP_NM_TMP_DIR/netif_allowlist_nm_conf

-     cat << EOF > "$_netif_allowlist_nm_conf"

- [device-others]

- match-device=${_netif_allowlist}

- managed=false

- EOF

- 

-     inst "$_netif_allowlist_nm_conf" "/etc/NetworkManager/conf.d/10-kdump-netif_allowlist.conf"

- }

- 

- _get_nic_driver() {

-     ethtool -i "$1" | sed -n -E "s/driver: (.*)/\1/p"

- }