kdump-lib.sh: reformat with shfmt
This is a batch update done with: shfmt -s -w kdump-lib.sh Clean up code style and reduce code base size, no behaviour change. Signed-off-by: Kairui Song <kasong@redhat.com> Acked-by: Philipp Rudo <prudo@redhat.com>
This commit is contained in:
parent
20089dddd5
commit
4cdce1f489
198
kdump-lib.sh
198
kdump-lib.sh
@ -14,23 +14,25 @@ is_fadump_capable()
|
||||
# Check if firmware-assisted dump is enabled
|
||||
# if no, fallback to kdump check
|
||||
if [[ -f $FADUMP_ENABLED_SYS_NODE ]]; then
|
||||
rc=$(<$FADUMP_ENABLED_SYS_NODE)
|
||||
rc=$(< $FADUMP_ENABLED_SYS_NODE)
|
||||
[[ $rc -eq 1 ]] && return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
is_squash_available() {
|
||||
is_squash_available()
|
||||
{
|
||||
for kmodule in squashfs overlay loop; do
|
||||
if [[ -z "$KDUMP_KERNELVER" ]]; then
|
||||
modprobe --dry-run $kmodule &>/dev/null || return 1
|
||||
if [[ -z $KDUMP_KERNELVER ]]; then
|
||||
modprobe --dry-run $kmodule &> /dev/null || return 1
|
||||
else
|
||||
modprobe -S "$KDUMP_KERNELVER" --dry-run $kmodule &>/dev/null || return 1
|
||||
modprobe -S "$KDUMP_KERNELVER" --dry-run $kmodule &> /dev/null || return 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
perror_exit() {
|
||||
perror_exit()
|
||||
{
|
||||
derror "$@"
|
||||
exit 1
|
||||
}
|
||||
@ -54,7 +56,8 @@ is_generic_fence_kdump()
|
||||
[[ $(kdump_get_conf_val fence_kdump_nodes) ]]
|
||||
}
|
||||
|
||||
to_dev_name() {
|
||||
to_dev_name()
|
||||
{
|
||||
local dev="${1//\"/}"
|
||||
|
||||
case "$dev" in
|
||||
@ -66,6 +69,7 @@ to_dev_name() {
|
||||
;;
|
||||
*)
|
||||
echo "$dev"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
@ -79,10 +83,10 @@ get_user_configured_dump_disk()
|
||||
local _target
|
||||
|
||||
_target=$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw")
|
||||
[[ -n "$_target" ]] && echo "$_target" && return
|
||||
[[ -n $_target ]] && echo "$_target" && return
|
||||
|
||||
_target=$(get_dracut_args_target "$(kdump_get_conf_val "dracut_args")")
|
||||
[[ -b "$_target" ]] && echo "$_target"
|
||||
[[ -b $_target ]] && echo "$_target"
|
||||
}
|
||||
|
||||
get_block_dump_target()
|
||||
@ -94,12 +98,12 @@ get_block_dump_target()
|
||||
fi
|
||||
|
||||
_target=$(get_user_configured_dump_disk)
|
||||
[[ -n "$_target" ]] && to_dev_name "$_target" && return
|
||||
[[ -n $_target ]] && to_dev_name "$_target" && return
|
||||
|
||||
# Get block device name from local save path
|
||||
_path=$(get_save_path)
|
||||
_target=$(get_target_from_path "$_path")
|
||||
[[ -b "$_target" ]] && to_dev_name "$_target"
|
||||
[[ -b $_target ]] && to_dev_name "$_target"
|
||||
}
|
||||
|
||||
is_dump_to_rootfs()
|
||||
@ -114,7 +118,7 @@ get_failure_action_target()
|
||||
if is_dump_to_rootfs; then
|
||||
# Get rootfs device name
|
||||
_target=$(get_root_fs_device)
|
||||
[[ -b "$_target" ]] && to_dev_name "$_target" && return
|
||||
[[ -b $_target ]] && to_dev_name "$_target" && return
|
||||
# Then, must be nfs root
|
||||
echo "nfs"
|
||||
fi
|
||||
@ -127,7 +131,7 @@ get_kdump_targets()
|
||||
local kdump_targets
|
||||
|
||||
_target=$(get_block_dump_target)
|
||||
if [[ -n "$_target" ]]; then
|
||||
if [[ -n $_target ]]; then
|
||||
kdump_targets=$_target
|
||||
elif is_ssh_dump_target; then
|
||||
kdump_targets="ssh"
|
||||
@ -137,7 +141,7 @@ get_kdump_targets()
|
||||
|
||||
# Add the root device if dump_to_rootfs is specified.
|
||||
_root=$(get_failure_action_target)
|
||||
if [[ -n "$_root" ]] && [[ "$kdump_targets" != "$_root" ]]; then
|
||||
if [[ -n $_root ]] && [[ $kdump_targets != "$_root" ]]; then
|
||||
kdump_targets="$kdump_targets $_root"
|
||||
fi
|
||||
|
||||
@ -169,13 +173,13 @@ get_bind_mount_source()
|
||||
_fstype=$(get_mount_info FSTYPE target "$_mnt" -f)
|
||||
|
||||
# bind mount in fstab
|
||||
if [[ -d "$_src" ]] && [[ "$_fstype" = none ]] && (echo "$_opt" | grep -q "\bbind\b"); then
|
||||
if [[ -d $_src ]] && [[ $_fstype == none ]] && (echo "$_opt" | grep -q "\bbind\b"); then
|
||||
echo "$_src$_path" && return
|
||||
fi
|
||||
|
||||
# direct mount
|
||||
_src_nofsroot=$(get_mount_info SOURCE target "$_mnt" -v -f)
|
||||
if [[ $_src_nofsroot = "$_src" ]]; then
|
||||
if [[ $_src_nofsroot == "$_src" ]]; then
|
||||
echo "$_mnt$_path" && return
|
||||
fi
|
||||
|
||||
@ -184,7 +188,7 @@ get_bind_mount_source()
|
||||
_mnt=$(get_mount_info TARGET source "$_src_nofsroot" -f)
|
||||
|
||||
# for btrfs, _fsroot will also contain the subvol value as well, strip it
|
||||
if [[ "$_fstype" = btrfs ]]; then
|
||||
if [[ $_fstype == btrfs ]]; then
|
||||
local _subvol
|
||||
_subvol=${_opt#*subvol=}
|
||||
_subvol=${_subvol%,*}
|
||||
@ -209,10 +213,10 @@ get_kdump_mntpoint_from_target()
|
||||
# mount under /kdumproot if dump target is not mounted in first kernel
|
||||
# mount under /kdumproot/$_mntpoint in other cases in 2nd kernel.
|
||||
# systemd will be in charge to umount it.
|
||||
if [[ -z "$_mntpoint" ]];then
|
||||
if [[ -z $_mntpoint ]]; then
|
||||
_mntpoint="/kdumproot"
|
||||
else
|
||||
if [[ "$_mntpoint" = "/" ]];then
|
||||
if [[ $_mntpoint == "/" ]]; then
|
||||
_mntpoint="/sysroot"
|
||||
else
|
||||
_mntpoint="/kdumproot/$_mntpoint"
|
||||
@ -223,7 +227,8 @@ get_kdump_mntpoint_from_target()
|
||||
echo $_mntpoint | tr -s "/"
|
||||
}
|
||||
|
||||
kdump_get_persistent_dev() {
|
||||
kdump_get_persistent_dev()
|
||||
{
|
||||
local dev="${1//\"/}"
|
||||
|
||||
case "$dev" in
|
||||
@ -261,7 +266,7 @@ is_hostname()
|
||||
local _hostname
|
||||
|
||||
_hostname=$(echo "$1" | grep ":")
|
||||
if [[ -n "$_hostname" ]]; then
|
||||
if [[ -n $_hostname ]]; then
|
||||
return 1
|
||||
fi
|
||||
echo "$1" | grep -q "[a-zA-Z]"
|
||||
@ -273,13 +278,12 @@ get_hwaddr()
|
||||
if [[ -f "/sys/class/net/$1/address" ]]; then
|
||||
awk '{ print toupper($0) }' < "/sys/class/net/$1/address"
|
||||
elif [[ -d "/sys/class/net/$1" ]]; then
|
||||
LC_ALL="" LANG="" ip -o link show "$1" 2>/dev/null | \
|
||||
LC_ALL="" LANG="" ip -o link show "$1" 2> /dev/null |
|
||||
awk '{ print toupper(gensub(/.*link\/[^ ]* ([[:alnum:]:]*).*/,
|
||||
"\\1", 1)); }'
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# Get value by a field using "nmcli -g"
|
||||
# Usage: get_nmcli_value_by_field <field> <nmcli command>
|
||||
#
|
||||
@ -318,36 +322,36 @@ get_nmcli_connection_apath_by_ifname()
|
||||
get_ifcfg_by_device()
|
||||
{
|
||||
grep -E -i -l "^[[:space:]]*DEVICE=\"*${1}\"*[[:space:]]*$" \
|
||||
/etc/sysconfig/network-scripts/ifcfg-* 2>/dev/null | head -1
|
||||
/etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1
|
||||
}
|
||||
|
||||
get_ifcfg_by_hwaddr()
|
||||
{
|
||||
grep -E -i -l "^[[:space:]]*HWADDR=\"*${1}\"*[[:space:]]*$" \
|
||||
/etc/sysconfig/network-scripts/ifcfg-* 2>/dev/null | head -1
|
||||
/etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1
|
||||
}
|
||||
|
||||
get_ifcfg_by_uuid()
|
||||
{
|
||||
grep -E -i -l "^[[:space:]]*UUID=\"*${1}\"*[[:space:]]*$" \
|
||||
/etc/sysconfig/network-scripts/ifcfg-* 2>/dev/null | head -1
|
||||
/etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1
|
||||
}
|
||||
|
||||
get_ifcfg_by_name()
|
||||
{
|
||||
grep -E -i -l "^[[:space:]]*NAME=\"*${1}\"*[[:space:]]*$" \
|
||||
/etc/sysconfig/network-scripts/ifcfg-* 2>/dev/null | head -1
|
||||
/etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1
|
||||
}
|
||||
|
||||
is_nm_running()
|
||||
{
|
||||
[[ "$(LANG=C nmcli -t --fields running general status 2>/dev/null)" = "running" ]]
|
||||
[[ "$(LANG=C nmcli -t --fields running general status 2> /dev/null)" == "running" ]]
|
||||
}
|
||||
|
||||
is_nm_handling()
|
||||
{
|
||||
LANG=C nmcli -t --fields device,state dev status 2>/dev/null \
|
||||
| grep -q "^\(${1}:connected\)\|\(${1}:connecting.*\)$"
|
||||
LANG=C nmcli -t --fields device,state dev status 2> /dev/null |
|
||||
grep -q "^\(${1}:connected\)\|\(${1}:connecting.*\)$"
|
||||
}
|
||||
|
||||
# $1: netdev name
|
||||
@ -357,15 +361,15 @@ get_ifcfg_nmcli()
|
||||
local ifcfg_file
|
||||
|
||||
# Get the active nmcli config name of $1
|
||||
if is_nm_running && is_nm_handling "${1}" ; then
|
||||
if is_nm_running && is_nm_handling "${1}"; then
|
||||
# The configuration "uuid" and "name" generated by nm is wrote to
|
||||
# the ifcfg file as "UUID=<nm_uuid>" and "NAME=<nm_name>".
|
||||
nm_uuid=$(LANG=C nmcli -t --fields uuid,device c show --active 2>/dev/null \
|
||||
| grep "${1}" | head -1 | cut -d':' -f1)
|
||||
nm_name=$(LANG=C nmcli -t --fields name,device c show --active 2>/dev/null \
|
||||
| grep "${1}" | head -1 | cut -d':' -f1)
|
||||
nm_uuid=$(LANG=C nmcli -t --fields uuid,device c show --active 2> /dev/null |
|
||||
grep "${1}" | head -1 | cut -d':' -f1)
|
||||
nm_name=$(LANG=C nmcli -t --fields name,device c show --active 2> /dev/null |
|
||||
grep "${1}" | head -1 | cut -d':' -f1)
|
||||
ifcfg_file=$(get_ifcfg_by_uuid "${nm_uuid}")
|
||||
[[ -z "${ifcfg_file}" ]] && ifcfg_file=$(get_ifcfg_by_name "${nm_name}")
|
||||
[[ -z ${ifcfg_file} ]] && ifcfg_file=$(get_ifcfg_by_name "${nm_name}")
|
||||
fi
|
||||
|
||||
echo -n "${ifcfg_file}"
|
||||
@ -377,15 +381,15 @@ get_ifcfg_legacy()
|
||||
local ifcfg_file hwaddr
|
||||
|
||||
ifcfg_file="/etc/sysconfig/network-scripts/ifcfg-${1}"
|
||||
[[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return
|
||||
[[ -f ${ifcfg_file} ]] && echo -n "${ifcfg_file}" && return
|
||||
|
||||
ifcfg_file=$(get_ifcfg_by_name "${1}")
|
||||
[[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return
|
||||
[[ -f ${ifcfg_file} ]] && echo -n "${ifcfg_file}" && return
|
||||
|
||||
hwaddr=$(get_hwaddr "${1}")
|
||||
if [[ -n "$hwaddr" ]]; then
|
||||
if [[ -n $hwaddr ]]; then
|
||||
ifcfg_file=$(get_ifcfg_by_hwaddr "${hwaddr}")
|
||||
[[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return
|
||||
[[ -f ${ifcfg_file} ]] && echo -n "${ifcfg_file}" && return
|
||||
fi
|
||||
|
||||
ifcfg_file=$(get_ifcfg_by_device "${1}")
|
||||
@ -395,11 +399,12 @@ get_ifcfg_legacy()
|
||||
|
||||
# $1: netdev name
|
||||
# Return the ifcfg file whole name(including the path) of $1 if any.
|
||||
get_ifcfg_filename() {
|
||||
get_ifcfg_filename()
|
||||
{
|
||||
local ifcfg_file
|
||||
|
||||
ifcfg_file=$(get_ifcfg_nmcli "${1}")
|
||||
if [[ -z "${ifcfg_file}" ]]; then
|
||||
if [[ -z ${ifcfg_file} ]]; then
|
||||
ifcfg_file=$(get_ifcfg_legacy "${1}")
|
||||
fi
|
||||
|
||||
@ -408,14 +413,16 @@ get_ifcfg_filename() {
|
||||
|
||||
# returns 0 when omission of a module is desired in dracut_args
|
||||
# returns 1 otherwise
|
||||
is_dracut_mod_omitted() {
|
||||
is_dracut_mod_omitted()
|
||||
{
|
||||
local dracut_args dracut_mod=$1
|
||||
|
||||
set -- $(kdump_get_conf_val dracut_args)
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
-o|--omit)
|
||||
-o | --omit)
|
||||
[[ " ${2//[^[:alnum:]]/ } " == *" $dracut_mod "* ]] && return 0
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
@ -423,14 +430,15 @@ is_dracut_mod_omitted() {
|
||||
return 1
|
||||
}
|
||||
|
||||
is_wdt_active() {
|
||||
is_wdt_active()
|
||||
{
|
||||
local active
|
||||
|
||||
[[ -d /sys/class/watchdog ]] || return 1
|
||||
for dir in /sys/class/watchdog/*; do
|
||||
[[ -f "$dir/state" ]] || continue
|
||||
active=$(< "$dir/state")
|
||||
[[ "$active" = "active" ]] && return 0
|
||||
[[ $active == "active" ]] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
@ -447,7 +455,7 @@ check_crash_mem_reserved()
|
||||
{
|
||||
local mem_reserved
|
||||
|
||||
mem_reserved=$(</sys/kernel/kexec_crash_size)
|
||||
mem_reserved=$(< /sys/kernel/kexec_crash_size)
|
||||
if [[ $mem_reserved -eq 0 ]]; then
|
||||
derror "No memory reserved for crash kernel"
|
||||
return 1
|
||||
@ -468,12 +476,12 @@ check_kdump_feasibility()
|
||||
|
||||
check_current_kdump_status()
|
||||
{
|
||||
if [[ ! -f /sys/kernel/kexec_crash_loaded ]];then
|
||||
if [[ ! -f /sys/kernel/kexec_crash_loaded ]]; then
|
||||
derror "Perhaps CONFIG_CRASH_DUMP is not enabled in kernel"
|
||||
return 1
|
||||
fi
|
||||
|
||||
rc=$(</sys/kernel/kexec_crash_loaded)
|
||||
rc=$(< /sys/kernel/kexec_crash_loaded)
|
||||
if [[ $rc == 1 ]]; then
|
||||
return 0
|
||||
else
|
||||
@ -490,7 +498,7 @@ remove_cmdline_param()
|
||||
shift
|
||||
|
||||
for arg in "$@"; do
|
||||
cmdline=$(echo "$cmdline" | \
|
||||
cmdline=$(echo "$cmdline" |
|
||||
sed -e "s/\b$arg=[^ ]*//g" \
|
||||
-e "s/^$arg\b//g" \
|
||||
-e "s/[[:space:]]$arg\b//g" \
|
||||
@ -523,7 +531,7 @@ append_cmdline()
|
||||
local newstr=${cmdline/$2/""}
|
||||
|
||||
# unchanged str implies argument wasn't there
|
||||
if [[ "$cmdline" == "$newstr" ]]; then
|
||||
if [[ $cmdline == "$newstr" ]]; then
|
||||
cmdline="${cmdline} ${2}=${3}"
|
||||
fi
|
||||
|
||||
@ -558,26 +566,26 @@ is_secure_boot_enforced()
|
||||
if [[ -f /proc/device-tree/ibm,secureboot/os-secureboot-enforcing ]]; then
|
||||
return 0
|
||||
fi
|
||||
if [[ -f /proc/device-tree/ibm,secure-boot ]] && \
|
||||
if [[ -f /proc/device-tree/ibm,secure-boot ]] &&
|
||||
[[ $(lsprop /proc/device-tree/ibm,secure-boot | tail -1) -ge 2 ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Detect secure boot on x86 and arm64
|
||||
secure_boot_file=$(find /sys/firmware/efi/efivars -name "SecureBoot-*" 2>/dev/null)
|
||||
setup_mode_file=$(find /sys/firmware/efi/efivars -name "SetupMode-*" 2>/dev/null)
|
||||
secure_boot_file=$(find /sys/firmware/efi/efivars -name "SecureBoot-*" 2> /dev/null)
|
||||
setup_mode_file=$(find /sys/firmware/efi/efivars -name "SetupMode-*" 2> /dev/null)
|
||||
|
||||
if [[ -f "$secure_boot_file" ]] && [[ -f "$setup_mode_file" ]]; then
|
||||
if [[ -f $secure_boot_file ]] && [[ -f $setup_mode_file ]]; then
|
||||
secure_boot_byte=$(hexdump -v -e '/1 "%d\ "' "$secure_boot_file" | cut -d' ' -f 5)
|
||||
setup_mode_byte=$(hexdump -v -e '/1 "%d\ "' "$setup_mode_file" | cut -d' ' -f 5)
|
||||
|
||||
if [[ "$secure_boot_byte" = "1" ]] && [[ "$setup_mode_byte" = "0" ]]; then
|
||||
if [[ $secure_boot_byte == "1" ]] && [[ $setup_mode_byte == "0" ]]; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Detect secure boot on s390x
|
||||
if [[ -e "/sys/firmware/ipl/secure" && "$(</sys/firmware/ipl/secure)" == "1" ]]; then
|
||||
if [[ -e "/sys/firmware/ipl/secure" && "$(< /sys/firmware/ipl/secure)" == "1" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
@ -594,22 +602,18 @@ prepare_kexec_args()
|
||||
local found_elf_args
|
||||
|
||||
ARCH=$(uname -m)
|
||||
if [[ "$ARCH" == "i686" ]] || [[ "$ARCH" == "i386" ]]
|
||||
then
|
||||
if [[ $ARCH == "i686" ]] || [[ $ARCH == "i386" ]]; then
|
||||
need_64bit_headers
|
||||
if [[ $? == 1 ]]
|
||||
then
|
||||
if [[ $? == 1 ]]; then
|
||||
found_elf_args=$(echo "$kexec_args" | grep elf32-core-headers)
|
||||
if [[ -n "$found_elf_args" ]]
|
||||
then
|
||||
if [[ -n $found_elf_args ]]; then
|
||||
dwarn "Warning: elf32-core-headers overrides correct elf64 setting"
|
||||
else
|
||||
kexec_args="$kexec_args --elf64-core-headers"
|
||||
fi
|
||||
else
|
||||
found_elf_args=$(echo "$kexec_args" | grep elf64-core-headers)
|
||||
if [[ -z "$found_elf_args" ]]
|
||||
then
|
||||
if [[ -z $found_elf_args ]]; then
|
||||
kexec_args="$kexec_args --elf32-core-headers"
|
||||
fi
|
||||
fi
|
||||
@ -629,7 +633,7 @@ prepare_kdump_bootinfo()
|
||||
local boot_img boot_imglist boot_dirlist boot_initrdlist
|
||||
local machine_id
|
||||
|
||||
if [[ -z "$KDUMP_KERNELVER" ]]; then
|
||||
if [[ -z $KDUMP_KERNELVER ]]; then
|
||||
KDUMP_KERNELVER="$(uname -r)"
|
||||
fi
|
||||
|
||||
@ -639,7 +643,7 @@ prepare_kdump_bootinfo()
|
||||
|
||||
# Use BOOT_IMAGE as reference if possible, strip the GRUB root device prefix in (hd0,gpt1) format
|
||||
boot_img="$(sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/" /proc/cmdline)"
|
||||
if [[ -n "$boot_img" ]]; then
|
||||
if [[ -n $boot_img ]]; then
|
||||
boot_imglist="$boot_img $boot_imglist"
|
||||
fi
|
||||
|
||||
@ -652,7 +656,7 @@ prepare_kdump_bootinfo()
|
||||
done
|
||||
done
|
||||
|
||||
if ! [[ -e "$KDUMP_KERNEL" ]]; then
|
||||
if ! [[ -e $KDUMP_KERNEL ]]; then
|
||||
derror "Failed to detect kdump kernel location"
|
||||
return 1
|
||||
fi
|
||||
@ -673,7 +677,7 @@ prepare_kdump_bootinfo()
|
||||
# Create kdump initrd basename from default initrd basename
|
||||
# initramfs-5.7.9-200.fc32.x86_64.img => initramfs-5.7.9-200.fc32.x86_64kdump.img
|
||||
# initrd => initrdkdump
|
||||
if [[ -z "$defaut_initrd_base" ]]; then
|
||||
if [[ -z $defaut_initrd_base ]]; then
|
||||
kdump_initrd_base=initramfs-${KDUMP_KERNELVER}kdump.img
|
||||
elif [[ $defaut_initrd_base == *.* ]]; then
|
||||
kdump_initrd_base=${defaut_initrd_base%.*}kdump.${DEFAULT_INITRD##*.}
|
||||
@ -682,7 +686,7 @@ prepare_kdump_bootinfo()
|
||||
fi
|
||||
|
||||
# Place kdump initrd in $(/var/lib/kdump) if $(KDUMP_BOOTDIR) not writable
|
||||
if [[ ! -w "$KDUMP_BOOTDIR" ]];then
|
||||
if [[ ! -w $KDUMP_BOOTDIR ]]; then
|
||||
var_target_initrd_dir="/var/lib/kdump"
|
||||
mkdir -p "$var_target_initrd_dir"
|
||||
KDUMP_INITRD="$var_target_initrd_dir/$kdump_initrd_base"
|
||||
@ -699,7 +703,7 @@ get_watchdog_drvs()
|
||||
# device/modalias will return driver of this device
|
||||
[[ -f "$_dir/device/modalias" ]] || continue
|
||||
_drv=$(< "$_dir/device/modalias")
|
||||
_drv=$(modprobe --set-version "$KDUMP_KERNELVER" -R "$_drv" 2>/dev/null)
|
||||
_drv=$(modprobe --set-version "$KDUMP_KERNELVER" -R "$_drv" 2> /dev/null)
|
||||
for i in $_drv; do
|
||||
if ! [[ " $_wdtdrvs " == *" $i "* ]]; then
|
||||
_wdtdrvs="$_wdtdrvs $i"
|
||||
@ -718,8 +722,8 @@ prepare_cmdline()
|
||||
{
|
||||
local cmdline id arg
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
cmdline=$(</proc/cmdline)
|
||||
if [[ -z $1 ]]; then
|
||||
cmdline=$(< /proc/cmdline)
|
||||
else
|
||||
cmdline="$1"
|
||||
fi
|
||||
@ -750,7 +754,7 @@ prepare_cmdline()
|
||||
cmdline="${cmdline} $3"
|
||||
|
||||
id=$(get_bootcpu_apicid)
|
||||
if [[ -n ${id} ]] ; then
|
||||
if [[ -n ${id} ]]; then
|
||||
cmdline=$(append_cmdline "$cmdline" disable_cpu_apicid "$id")
|
||||
fi
|
||||
|
||||
@ -783,7 +787,7 @@ get_system_size()
|
||||
result="+$result"
|
||||
# replace '-' with '+0x' and '+' with '-0x'
|
||||
sum=$(echo "$result" | sed -e 's/-/K0x/g' -e 's/+/-0x/g' -e 's/K/+/g')
|
||||
size=$(printf "%d\n" $(($sum)))
|
||||
size=$(printf "%d\n" $((sum)))
|
||||
size=$((size / 1024 / 1024 / 1024))
|
||||
|
||||
echo "$size"
|
||||
@ -795,7 +799,7 @@ get_recommend_size()
|
||||
local _ck_cmdline=$2
|
||||
local OLDIFS="$IFS"
|
||||
|
||||
start=${_ck_cmdline: :1}
|
||||
start=${_ck_cmdline::1}
|
||||
if [[ $mem_size -lt $start ]]; then
|
||||
echo "0M"
|
||||
return
|
||||
@ -804,7 +808,7 @@ get_recommend_size()
|
||||
for i in $_ck_cmdline; do
|
||||
end=$(echo "$i" | awk -F "-" '{ print $2 }' | awk -F ":" '{ print $1 }')
|
||||
recommend=$(echo "$i" | awk -F "-" '{ print $2 }' | awk -F ":" '{ print $2 }')
|
||||
size=${end: : -1}
|
||||
size=${end::-1}
|
||||
unit=${end: -1}
|
||||
if [[ $unit == 'T' ]]; then
|
||||
size=$((size * 1024))
|
||||
@ -824,23 +828,23 @@ kdump_get_arch_recommend_size()
|
||||
{
|
||||
local kernel=$1 arch
|
||||
|
||||
if ! [[ -r "/proc/iomem" ]] ; then
|
||||
if ! [[ -r "/proc/iomem" ]]; then
|
||||
echo "Error, can not access /proc/iomem."
|
||||
return 1
|
||||
fi
|
||||
|
||||
[[ -z "$kernel" ]] && kernel=$(uname -r)
|
||||
ck_cmdline=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2>/dev/null)
|
||||
[[ -z $kernel ]] && kernel=$(uname -r)
|
||||
ck_cmdline=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2> /dev/null)
|
||||
|
||||
if [[ -n "$ck_cmdline" ]]; then
|
||||
if [[ -n $ck_cmdline ]]; then
|
||||
ck_cmdline=${ck_cmdline#crashkernel=}
|
||||
else
|
||||
arch=$(lscpu | grep Architecture | awk -F ":" '{ print $2 }' | tr '[:lower:]' '[:upper:]')
|
||||
if [[ "$arch" = "X86_64" ]] || [[ "$arch" = "S390X" ]]; then
|
||||
if [[ $arch == "X86_64" ]] || [[ $arch == "S390X" ]]; then
|
||||
ck_cmdline="1G-4G:160M,4G-64G:192M,64G-1T:256M,1T-:512M"
|
||||
elif [[ "$arch" = "AARCH64" ]]; then
|
||||
elif [[ $arch == "AARCH64" ]]; then
|
||||
ck_cmdline="2G-:448M"
|
||||
elif [[ "$arch" = "PPC64LE" ]]; then
|
||||
elif [[ $arch == "PPC64LE" ]]; then
|
||||
if is_fadump_capable; then
|
||||
ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G"
|
||||
else
|
||||
@ -879,7 +883,8 @@ get_luks_crypt_dev()
|
||||
# Example:
|
||||
# $ get_maj_min /dev/sda2
|
||||
# 8:2
|
||||
kdump_get_maj_min() {
|
||||
kdump_get_maj_min()
|
||||
{
|
||||
local _majmin
|
||||
_majmin="$(stat -L -c '%t:%T' "$1" 2> /dev/null)"
|
||||
printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))"
|
||||
@ -897,7 +902,7 @@ get_all_kdump_crypt_dev()
|
||||
check_vmlinux()
|
||||
{
|
||||
# Use readelf to check if it's a valid ELF
|
||||
readelf -h "$1" &>/dev/null || return 1
|
||||
readelf -h "$1" &> /dev/null || return 1
|
||||
}
|
||||
|
||||
get_vmlinux_size()
|
||||
@ -905,8 +910,8 @@ get_vmlinux_size()
|
||||
local size=0 _msize
|
||||
|
||||
while read -r _msize; do
|
||||
size=$(( size + _msize ))
|
||||
done <<< "$(readelf -l -W "$1" | awk '/^ LOAD/{print $6}' 2>/dev/stderr)"
|
||||
size=$((size + _msize))
|
||||
done <<< "$(readelf -l -W "$1" | awk '/^ LOAD/{print $6}' 2> /dev/stderr)"
|
||||
|
||||
echo $size
|
||||
}
|
||||
@ -917,8 +922,7 @@ try_decompress()
|
||||
# "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
|
||||
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
|
||||
@ -948,12 +952,12 @@ get_kernel_size()
|
||||
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 '\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:
|
||||
@ -962,7 +966,7 @@ get_kernel_size()
|
||||
# Fallback to use iomem
|
||||
local _size=0 _seg
|
||||
while read -r _seg; do
|
||||
_size=$(( _size + 0x${_seg#*-} - 0x${_seg%-*} ))
|
||||
_size=$((_size + 0x${_seg#*-} - 0x${_seg%-*}))
|
||||
done <<< "$(grep -E "Kernel (code|rodata|data|bss)" /proc/iomem | cut -d ":" -f 1)"
|
||||
echo $_size
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user