[PATCH] mkdumprd: allow spaces after 'path' config phrase when network dump
by Kazuhito Hagio
Without this patch, when there are two or more spaces after 'path'
configuration phrase with ssh or nfs setting, SAVE_PATH is set to
'/var/crash' in mkdumprd, and in most cases kdump service fails to
start.
ssh kdump(a)192.168.122.1
path /kdump
^^
This behavior would be too sensitive and different from the other
configurations. With this patch, mkdumprd allows such spaces.
Signed-off-by: Kazuhito Hagio <k-hagio(a)ab.jp.nec.com>
---
mkdumprd | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mkdumprd b/mkdumprd
index a6f7fe8..aa0abfd 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -13,7 +13,7 @@ export IN_KDUMP=1
conf_file="/etc/kdump.conf"
SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
-SAVE_PATH=$(grep ^path $conf_file| cut -d' ' -f2)
+SAVE_PATH=$(awk '/^path/ {print $2}' $conf_file)
[ -z "$SAVE_PATH" ] && SAVE_PATH=$DEFAULT_PATH
# strip the duplicated "/"
SAVE_PATH=$(echo $SAVE_PATH | tr -s /)
--
2.18.0
1 year
[PATCH v2] kdumpctl: Add kdumpctl estimate
by Kairui Song
Add a rough esitimation support, currently, following memory usage are
checked by this sub command:
- System RAM
- Kdump Initramfs size
- Kdump Kernel image size
- Kdump Kernel module size
- Kdump userspace user and other runtime allocated memory (currently
simply using a fixed value: 64M)
This will provide user three values as reference,
The output of kdumpctl estimate looks like this:
# kdumpctl estimate
Reserved crashkernel: 128M
Estimated crashkernel: 143M
Recommanded crashkernel: 160M
Kernel image size: 47M
Kernel modules size: 9M
Initramfs size: 22M
Runtime reservation: 64M
Large modules:
nouveau: 2281472
xfs: 1515520
WARNING: Current crashkernel size is lower than recommanded size 160M.
"Reserved crashkernel" is currently reserved crashkernel value.
"Baseline crashkernel" is the crashkernel size when `crashkernel=auto`
is used, based on crashkernel auto rules from RHEL.
"Estimated crashkernel" is the estimate value based on the memory usage
items listed above.
"Recommanded crashkernel" will use the largest value of estimated
crashkernel and the baseline crashkernel.
All values are rounded up and converted to MB.
All modules with static size larger than 1M will be listed as large
module.
Signed-off-by: Kairui Song <kasong(a)redhat.com>
---
Update from v1:
- Fix typos
- Remove "Baseline crashkernel:" from output
---
kdump-lib.sh | 67 +++++++++++++++++++++++++++++++++++++++
kdumpctl | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 153 insertions(+), 2 deletions(-)
diff --git a/kdump-lib.sh b/kdump-lib.sh
index 21271cf..d56622a 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -900,3 +900,70 @@ kdump_get_arch_recommend_size()
echo $result
return 0
}
+
+check_vmlinux()
+{
+ # Use readelf to check if it's a valid ELF
+ readelf -h $1 &>/dev/null || return 1
+}
+
+get_vmlinux_size()
+{
+ local size=0
+
+ while read _type _offset _virtaddr _physaddr _fsize _msize _flg _aln; do
+ size=$(( $size + $_msize ))
+ done <<< $(readelf -l -W $1 | grep "^ LOAD" 2>/dev/stderr)
+
+ echo $size
+}
+
+try_decompress()
+{
+ # The obscure use of the "tr" filter is to work around older versions of
+ # "grep" that report the byte offset of the line instead of the pattern.
+
+ # Try to find the header ($1) and decompress from here
+ for pos in `tr "$1\n$2" "\n$2=" < "$4" | grep -abo "^$2"`
+ do
+ if ! type -P $3 > /dev/null; then
+ ddebug "Signiature detected but '$3' is missing, skip this decompressor"
+ break
+ fi
+
+ pos=${pos%%:*}
+ tail -c+$pos "$img" | $3 > $5 2> /dev/null
+ if check_vmlinux $5; then
+ ddebug "Kernel is extracted with '$3'"
+ return 0
+ fi
+ done
+
+ return 1
+}
+
+# Borrowed from linux/scripts/extract-vmlinux
+get_kernel_size()
+{
+ # Prepare temp files:
+ local img=$1 tmp=$(mktemp /tmp/vmlinux-XXX)
+ trap "rm -f $tmp" 0
+
+ # Try to check if it's a vmlinux already
+ check_vmlinux $img && get_vmlinux_size $img && return 0
+
+ # That didn't work, so retry after decompression.
+ try_decompress '\037\213\010' xy gunzip $img $tmp || \
+ try_decompress '\3757zXZ\000' abcde unxz $img $tmp || \
+ try_decompress 'BZh' xy bunzip2 $img $tmp || \
+ try_decompress '\135\0\0\0' xxx unlzma $img $tmp || \
+ try_decompress '\211\114\132' xy 'lzop -d' $img $tmp || \
+ try_decompress '\002!L\030' xxx 'lz4 -d' $img $tmp || \
+ try_decompress '(\265/\375' xxx unzstd $img $tmp
+
+ # Finally check for uncompressed images or objects:
+ get_vmlinux_size $tmp && return 0
+
+ derror "Failed to get kernel image size"
+ return 1
+}
diff --git a/kdumpctl b/kdumpctl
index c3311ad..4109539 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -1246,6 +1246,87 @@ rebuild() {
return $?
}
+do_estimate() {
+ local kdump_mods
+ local -A large_mods
+ local baseline
+ local kernel_size mod_size initrd_size baseline_size runtime_size reserved_size estimated_size recommanded_size
+ local size_mb=$(( 1024 * 1024 ))
+
+ setup_initrd
+
+ if [ ! -f $TARGET_INITRD ]; then
+ derror "kdumpctl estimate: kdump initramfs is not built yet."
+ exit 1
+ fi
+
+ kdump_mods="$(lsinitrd $TARGET_INITRD -f /usr/lib/dracut/hostonly-kernel-modules.txt | tr '\n' ' ')"
+
+ baseline=$(kdump_get_arch_recommend_size)
+ if [[ "${baseline: -1}" == "M" ]]; then
+ baseline=${baseline%M}
+ elif [[ "${baseline: -1}" == "G" ]]; then
+ baseline=$(( ${baseline%G} * 1024 ))
+ elif [[ "${baseline: -1}" == "T" ]]; then
+ baseline=$(( ${baseline%Y} * 1048576 ))
+ fi
+
+ # The default value when using crashkernel=auto
+ baseline_size=$(( $baseline * $size_mb ))
+ # Current reserved crashkernel size
+ reserved_size=$(cat /sys/kernel/kexec_crash_size)
+ # A pre-estimated value for userspace usage and kernel
+ # runtime allocation, 64M should good for most cases
+ runtime_size=$(( 64 * $size_mb ))
+ # Kernel image size
+ kernel_size=$(get_kernel_size $KDUMP_KERNEL)
+ # Kdump initramfs size
+ initrd_size=$(du -b $TARGET_INITRD | awk '{print $1}')
+ # Kernel modules size after loaded
+ mod_size=0
+ while read -r _name _size _; do
+ if [[ ! " $kdump_mods " == *" $_name "* ]]; then
+ continue
+ fi
+ mod_size=$(( $mod_size + $_size ))
+
+ # Mark module with static size larger than 2M as large module
+ if [[ $(( $_size / $size_mb )) -ge 1 ]]; then
+ large_mods[$_name]=$_size
+ fi
+ done <<< "$(< /proc/modules)"
+
+ estimated_size=$(( $kernel_size + $mod_size + $initrd_size + $runtime_size ))
+
+ if [[ $baseline_size -gt $estimated_size ]]; then
+ recommanded_size=$baseline_size
+ else
+ recommanded_size=$estimated_size
+ fi
+
+ echo "Reserved crashkernel: $(( ( $reserved_size + $size_mb - 1 ) / $size_mb ))M"
+ echo "Estimated crashkernel: $(( ( $estimated_size + $size_mb - 1 ) / $size_mb ))M"
+ echo "Recommanded crashkernel: $(( ( $recommanded_size + $size_mb - 1 ) / $size_mb ))M"
+ echo
+ echo "Kernel image size: $(( ( $kernel_size + $size_mb - 1 ) / $size_mb ))M"
+ echo "Kernel modules size: $(( ( $mod_size + $size_mb - 1 ) / $size_mb ))M"
+ echo "Initramfs size: $(( ( $initrd_size + $size_mb - 1 ) / $size_mb ))M"
+ echo "Runtime reservation: $(( ( $runtime_size + $size_mb - 1 ) / $size_mb ))M"
+ echo -n "Large modules:"
+ if [[ "${#large_mods[@]}" -eq 0 ]]; then
+ echo " <none>"
+ else
+ echo ""
+ for _mod in "${!large_mods[@]}"; do
+ echo " $_mod: ${large_mods[$_mod]}"
+ done
+ fi
+
+ if [[ $reserved_size -le $recommanded_size ]]; then
+ echo "WARNING: Current crashkernel size is lower than recommanded size $(( ( $recommanded_size + 1023 ) / $size_mb ))M."
+ fi
+}
+
if [ ! -f "$KDUMP_CONFIG_FILE" ]; then
derror "Error: No kdump config file found!"
exit 1
@@ -1301,8 +1382,11 @@ main ()
showmem)
show_reserved_mem
;;
+ estimate)
+ do_estimate $2
+ ;;
*)
- dinfo $"Usage: $0 {start|stop|status|restart|reload|rebuild|propagate|showmem}"
+ dinfo $"Usage: $0 {start|stop|status|restart|reload|rebuild|propagate|showmem|estimate}"
exit 1
esac
}
@@ -1312,6 +1396,6 @@ single_instance_lock
# To avoid fd 9 leaking, we invoke a subshell, close fd 9 and call main.
# So that fd isn't leaking when main is invoking a subshell.
-(exec 9<&-; main $1)
+(exec 9<&-; main $@)
exit $?
--
2.29.2
2 years, 1 month
[PATCH] Don't iterate the whole /sys/devices just to find drm device
by Kairui Song
On some large systems, /sys/devices is huge and it's not a wise idea to
iterate it. `find` may cause tremendous contention on the kernfs_mutex
when there are already stress on /sys, and it will perform very very
poorly.
Simply check if drm class presents should be good enough.
Signed-off-by: Kairui Song <kasong(a)redhat.com>
---
dracut-module-setup.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index ac0f196..ce05de7 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -58,7 +58,7 @@ depends() {
_dep="$_dep znet"
fi
- if [ -n "$( find /sys/devices -name drm )" ] || [ -d /sys/module/hyperv_fb ]; then
+ if [ -n "$( ls -A /sys/class/drm 2>/dev/null )" ] || [ -d /sys/module/hyperv_fb ]; then
add_opt_module drm
fi
--
2.29.2
2 years, 1 month
[PATCH v2 1/2] Implement IP netmask calculation to replace "ipcalc -m"
by Coiby Xu
Recently, dracut-network drops depedency on dhcp-client which requires
ipcalc. Thus the dependency chain
"kexec-tools -> dracut-network -> dhcp-client -> ipcalc"
is broken. When NIC is configured to a static IP, kexec-tools depended
on "ipcalc -m" to get netmask. This commit implements the shell
equivalent of "ipcalc -m".
The following test code shows cal_netmask_by_prefix is consistent with
"ipcalc -m",
#!/bin/bash
. dracut-module-setup.sh
for i in {0..128}; do
mask_expected=$(ipcalc -m fe::/$i| cut -d"=" -f2)
mask_actual=$(cal_netmask_by_prefix $i true)
if [[ "$mask_expected" != "$mask_actual" ]]; then
echo $i, "expected=", $mask_expected, "acutal=", $mask_actual
fi
done
for i in {0..32}; do
mask_expected=$(ipcalc -m 8.8.8.8/$i| cut -d"=" -f2)
mask_actual=$(cal_netmask_by_prefix $i false)
if [[ "$mask_expected" != "$mask_actual" ]]; then
echo $i, "expected=", $mask_expected, "acutal=", $mask_actual
fi
done
Reported-by: Jie Li <jieli(a)redhat.com>
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
v1 -> v2:
1. Check subshell exit code when calling cal_netmask_by_prefix
2. Stop using die when bad prefix is passed to cal_netmask_by_prefix
3. Remove trailing spaces
---
dracut-module-setup.sh | 115 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 113 insertions(+), 2 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 8316589..ea6f7ea 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -121,17 +121,123 @@ kdump_setup_dns() {
done < "/etc/resolv.conf"
}
+# $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 or not
+# 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="$2"
+ 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 [[ "$_prefix" -lt 0 || ("$_ipv6" && "$_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=$(expr $_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
+}
+
#$1: netdev name
#$2: srcaddr
#if it use static ip echo it, or echo null
kdump_static_ip() {
local _netdev="$1" _srcaddr="$2" _ipv6_flag
- local _netmask _gateway _ipaddr _target _nexthop
+ local _netmask _gateway _ipaddr _target _nexthop _prefix
+ local _ipv6=false
_ipaddr=$(ip addr show dev $_netdev permanent | awk "/ $_srcaddr\/.* /{print \$2}")
if is_ipv6_address $_srcaddr; then
_ipv6_flag="-6"
+ _ipv6=true
fi
if [ -n "$_ipaddr" ]; then
@@ -144,7 +250,12 @@ kdump_static_ip() {
_srcaddr="[$_srcaddr]"
_gateway="[$_gateway]"
else
- _netmask=$(ipcalc -m $_ipaddr | cut -d'=' -f2)
+ _prefix=$(cut -d'/' -f2 <<< "$_ipaddr")
+ _netmask=$(cal_netmask_by_prefix "$_prefix" "$_ipv6")
+ if [[ "$?" -ne 0 ]]; then
+ derror "Failed to calculate netmask for $_ipaddr"
+ exit 1
+ fi
fi
echo -n "${_srcaddr}::${_gateway}:${_netmask}::"
fi
--
2.31.0
2 years, 1 month
[PATCH] kdumpctl: Write to `/var/lib/kdump` if $KDUMP_BOOTDIR not
writable
by Kelvin Fan
The /boot directory on some operating systems might be read-only.
If we cannot write to $KDUMP_BOOTDIR when generating the kdump
initrd, attempt to place the generated initrd at `/var/lib/kdump`
instead.
Signed-off by: Kelvin Fan <kfan(a)redhat.com>
---
kdumpctl | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/kdumpctl b/kdumpctl
index 24f5cf7..2107e3e 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -152,8 +152,15 @@ rebuild_kdump_initrd()
rebuild_initrd()
{
if [[ ! -w "$KDUMP_BOOTDIR" ]];then
- derror "$KDUMP_BOOTDIR does not have write permission. Can not rebuild $TARGET_INITRD"
- return 1
+ VAR_TARGET_INITRD_DIR="/var/lib/kdump"
+ mkdir -p "$VAR_TARGET_INITRD_DIR"
+ TARGET_INITRD_BASE="$(basename $TARGET_INITRD)"
+ TARGET_INITRD="$VAR_TARGET_INITRD_DIR/$TARGET_INITRD_BASE"
+ dwarn "$KDUMP_BOOTDIR does not have write permission. Rebuilding initrd at $TARGET_INITRD"
+ if [[ ! -w "$VAR_TARGET_INITRD_DIR" ]];then
+ derror "$VAR_TARGET_INITRD_DIR does not have write permission. Cannot rebuild $TARGET_INITRD"
+ return 1
+ fi
fi
if [ $DEFAULT_DUMP_MODE == "fadump" ]; then
@@ -656,6 +663,9 @@ load_kdump()
KEXEC_ARGS="$KEXEC_ARGS -s"
fi
+ # Relabel the target initrd for SELinux.
+ chcon -t boot_t $TARGET_INITRD
+
ddebug "$KEXEC $KEXEC_ARGS $standard_kexec_args --command-line=$KDUMP_COMMANDLINE --initrd=$TARGET_INITRD $KDUMP_KERNEL"
# The '12' represents an intermediate temporary file descriptor
--
2.29.2
2 years, 1 month
[PATCH 0/3] Use a standalone kdump emergency shell
by Kairui Song
Currently kdump use some wrapper around dracut emergency service and
emergency shell, this have many problems:
- If dracut-initqueue failed back to emergency mode due to timeout,
and faiure action is set to dump_to_rootfs, kdump will try start
initqueue again, lead to double timeout error.
- Dracut's emergency shell have many builtin actions, like
perform dracut emergency_action, ask for root password, generate
rdsosreport etc.
This series remove the emergency wrapper, and use a standalone kdump
emergency shell. Kdump will always perform final_action after kdump
shell, so simplified version works fine.
Kairui Song (3):
Don's try to restart dracut-initqueue if it's already there
Remove the kdump error handler isolation wrapper
Use a customized emergency shell
dracut-kdump-emergency.service | 25 +++++++++----------
dracut-kdump-error-handler.service | 33 ------------------------
dracut-module-setup.sh | 1 -
kdump-lib-initramfs.sh | 40 +++++++++++++++++++++++++-----
kexec-tools.spec | 2 --
5 files changed, 46 insertions(+), 55 deletions(-)
delete mode 100644 dracut-kdump-error-handler.service
--
2.29.2
2 years, 1 month
[PATCH v2] Doc: improve the kexec-kdump-howto.txt documentation
by Lianbo Jiang
Because there are some duplicated contents, this will remove the
infrequently used options descriptions from the "kexec-kdump-howto.txt",
only add the "KDUMP_COMMANDLINE_REMOVE" and "KDUMP_COMMANDLINE_APPEND".
Signed-off-by: Lianbo Jiang <lijiang(a)redhat.com>
---
kexec-kdump-howto.txt | 78 +++++++++++++++----------------------------
1 file changed, 27 insertions(+), 51 deletions(-)
diff --git a/kexec-kdump-howto.txt b/kexec-kdump-howto.txt
index 88af6078ae6e..d23dd24b3fc7 100644
--- a/kexec-kdump-howto.txt
+++ b/kexec-kdump-howto.txt
@@ -525,7 +525,7 @@ Advanced Setups
===============
About /etc/sysconfig/kdump
-------------------------------
+--------------------------
Currently, there are a few options in /etc/sysconfig/kdump, which are
usually used to control the behavior of kdump kernel. Basically, all of
@@ -533,51 +533,29 @@ these options have default values, usually we do not need to change them,
but sometimes, we may modify them in order to better control the behavior
of kdump kernel such as debug, etc.
--KDUMP_BOOTDIR
+Usually option of kexec utility is used to inherit the kernel cmdline
+from the 1st kernel for kdump kernel. E.g specifying --command-line=
+"`cat /proc/cmdline`" or simply using '--reuse-cmdline'. Then only need
+modify KDUMP_COMMANDLINE_APPEND and KDUMP_COMMANDLINE_REMOVE in the
+/etc/sysconfig/kdump to adjust the kernel cmdline of kdump as expected.
+
+For detailed description of each options, please refer to the file
+/etc/sysconfig/kdump directly.
+
+Kdump boot directory
+--------------------
Usually kdump kernel is the same as 1st kernel. So kdump will try to find
kdump kernel under /boot according to /proc/cmdline. E.g we execute below
command and get an output:
cat /proc/cmdline
BOOT_IMAGE=/xxx/vmlinuz-3.yyy.zzz root=xxxx .....
+Then kdump kernel will be /boot/xxx/vmlinuz-3.yyy.zzz.
+However a variable KDUMP_BOOTDIR in /etc/sysconfig/kdump is provided to
+user if kdump kernel is put in a different directory.
-Then kdump kernel will be /boot/xxx/vmlinuz-3.yyy.zzz. However, this option
-is provided to user if kdump kernel is put in a different directory.
-
--KDUMP_IMG
-
-This represents the image type used for kdump. The default value is "vmlinuz".
-
--KDUMP_IMG_EXT
-
-This represents the images extension. Relocatable kernels don't have one.
-Currently, it is a null string by default.
-
--KEXEC_ARGS
-
-Any additional kexec arguments required. For example:
-KEXEC_ARGS="--elf32-core-headers".
-
-In most situations, this should be left empty. But, sometimes we hope to get
-additional kexec loading debugging information, we can add the '-d' option
-for the debugging.
-
--KDUMP_KERNELVER
-
-This is a kernel version string for the kdump kernel. If the version is not
-specified, the init script will try to find a kdump kernel with the same
-version number as the running kernel.
-
--KDUMP_COMMANDLINE
-
-The value of 'KDUMP_COMMANDLINE' will be passed to kdump kernel as command
-line parameters, this will likely match the contents of the grub kernel line.
-
-In general, if a command line is not specified, which means that it is a null
-string such as KDUMP_COMMANDLINE="", the default will be taken automatically
-from the '/proc/cmdline'.
-
--KDUMP_COMMANDLINE_REMOVE
+KDUMP_COMMANDLINE_REMOVE
+------------------------
This option allows us to remove arguments from the current kdump command line.
If we don't specify any parameters for the KDUMP_COMMANDLINE, it will inherit
@@ -586,30 +564,28 @@ default kernel parameters could affect kdump, furthermore, that could cause
the failure of kdump kernel boot.
In addition, the option is also helpful to debug the kdump kernel, we can use
-this option to change kdump kernel command line.
+this option to change kdump kernel command line. For example:
-For more kernel parameters, please refer to kernel document.
+KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb"
--KDUMP_COMMANDLINE_APPEND
+For more kernel parameters, please refer to kernel document:
+Documentation/admin-guide/kernel-parameters.txt.
+
+KDUMP_COMMANDLINE_APPEND
+------------------------
This option allows us to append arguments to the current kdump command line
after processed by the KDUMP_COMMANDLINE_REMOVE. For kdump kernel, some
specific modules require to be disabled like the mce, cgroup, numa, hest_disable,
etc. Those modules may waste memory or kdump kernel doesn't need them,
-furthermore, there may affect kdump kernel boot.
+furthermore, there may affect kdump kernel boot. For example:
+
+KDUMP_COMMANDLINE_APPEND="cgroup_disable=memory"
Just like above option, it can be used to disable or enable some kernel
modules so that we can exclude any errors for kdump kernel, this is very
meaningful for debugging.
--KDUMP_STDLOGLVL | KDUMP_SYSLOGLVL | KDUMP_KMSGLOGLVL
-
-These variables are used to control the kdump log level in the first kernel.
-In the second kernel, kdump will use the rd.kdumploglvl option to set the log
-level in the above KDUMP_COMMANDLINE_APPEND.
-
-Logging levels: no logging(0), error(1), warn(2), info(3), debug(4)
-
Kdump Post-Capture Executable
-----------------------------
--
2.29.2
2 years, 2 months
[PATCH] Don't use die in dracut-module-setup.sh
by Coiby Xu
die (in dracut-lib.sh) is supposed to be used in the initramfs environment.
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
dracut-module-setup.sh | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 8316589..394317c 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -334,7 +334,10 @@ kdump_setup_znet() {
kdump_get_ip_route()
{
local _route=$(/sbin/ip -o route get to $1 2>&1)
- [ $? != 0 ] && die "Bad kdump network destination: $1"
+ if [[ $? != 0 ]]; then
+ derror "Bad kdump network destination: $1"
+ exit 1
+ fi
echo $_route
}
--
2.31.0
2 years, 2 months
Set up kdump network by parsing nmcli output and drop dependence on ifcfg scripts
by Coiby Xu
ifcfg scripts are deprecated. kexec-tools still set up network
based on ifcfg scripts which lead to the issues like [1] [2].
We can get network configuration including dns, bond and znet by
parsing nmcli output instead. Another benefit is we could potentially
avoid subtle bugs caused by namespace pollution because of sourcing
ifcfg scripts.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1919052
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1933679
Coiby Xu (8):
Parse option value from nmcli output
Get nmcli connection id by ifname
get nmcli connection show output by ifname
setup s390 znet cmdline by parsing nmcli connection show output
setup dns by parsing nmcli connection show output
setup bond by parsing nmcli connection show output
clean up codes related to ifcfg scripts
clean up unused is_nm_* functions
dracut-module-setup.sh | 72 +++++++++++++---------------
kdump-lib.sh | 106 ++++++++++++-----------------------------
2 files changed, 65 insertions(+), 113 deletions(-)
--
2.30.1
2 years, 2 months
[PATCH 1/2] Implement IP netmask caculation to replace "ipcalc -m"
by Coiby Xu
Recently, dracut-network drops depedency on dhcp-client which requires
ipcalc. Thus the dependency chain
"kexec-tools -> dracut-network -> dhcp-client -> ipcalc"
is broken. When NIC is configured to a static IP, kexec-tools depended
on "ipcalc -m" to get netmask. This commit implements the shell
equivalent of "ipcalc -m".
The following test code shows cal_netmask_by_prefix is consistent with
"ipcalc -m",
#!/bin/bash
. dracut-module-setup.sh
for i in {0..128}; do
mask_expected=$(ipcalc -m fe::/$i| cut -d"=" -f2)
mask_actual=$(cal_netmask_by_prefix $i true)
if [[ "$mask_expected" != "$mask_actual" ]]; then
echo $i, "expected=", $mask_expected, "acutal=", $mask_actual
fi
done
for i in {0..32}; do
mask_expected=$(ipcalc -m 8.8.8.8/$i| cut -d"=" -f2)
mask_actual=$(cal_netmask_by_prefix $i false)
if [[ "$mask_expected" != "$mask_actual" ]]; then
echo $i, "expected=", $mask_expected, "acutal=", $mask_actual
fi
done
Reported-by: Jie Li <jieli(a)redhat.com>
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
dracut-module-setup.sh | 107 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 105 insertions(+), 2 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 21143b4..bf6acf9 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -121,17 +121,119 @@ kdump_setup_dns() {
done < "/etc/resolv.conf"
}
+# $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 or not
+# 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="$2"
+ 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"; then
+ [ "$_prefix" -gt 128 ] || [ "$_prefix" -lt 0 ] && die "Wrong IPv6 prefix $_prefix"
+ _octets_per_group=2
+ _octets_total=16
+ _seperator=":"
+ else
+ [ "$_prefix" -gt 32 ] || [ "$_prefix" -lt 0 ] && die "Wrong IPv4 prefix $_prefix"
+ _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=$(expr $_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
+}
#$1: netdev name
#$2: srcaddr
#if it use static ip echo it, or echo null
kdump_static_ip() {
local _netdev="$1" _srcaddr="$2" _ipv6_flag
- local _netmask _gateway _ipaddr _target _nexthop
+ local _netmask _gateway _ipaddr _target _nexthop _prefix
+ local _ipv6=false
_ipaddr=$(ip addr show dev $_netdev permanent | awk "/ $_srcaddr\/.* /{print \$2}")
if is_ipv6_address $_srcaddr; then
_ipv6_flag="-6"
+ _ipv6=true
fi
if [ -n "$_ipaddr" ]; then
@@ -144,7 +246,8 @@ kdump_static_ip() {
_srcaddr="[$_srcaddr]"
_gateway="[$_gateway]"
else
- _netmask=$(ipcalc -m $_ipaddr | cut -d'=' -f2)
+ _prefix=$(cut -d'/' -f2 <<< "$_ipaddr")
+ _netmask=$(cal_netmask_by_prefix "$_prefix" "$_ipv6")
fi
echo -n "${_srcaddr}::${_gateway}:${_netmask}::"
fi
--
2.31.0
2 years, 2 months