|
|
4a6108 |
#!/bin/bash
|
|
|
db7d74 |
#
|
|
|
db7d74 |
# Kdump common variables and functions
|
|
|
db7d74 |
#
|
|
|
db7d74 |
|
|
|
4a6108 |
. /usr/lib/kdump/kdump-lib-initramfs.sh
|
|
|
4a6108 |
|
|
|
db7d74 |
FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled"
|
|
|
db7d74 |
|
|
|
db7d74 |
is_fadump_capable()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
# Check if firmware-assisted dump is enabled
|
|
|
4a6108 |
# if no, fallback to kdump check
|
|
|
4a6108 |
if [[ -f $FADUMP_ENABLED_SYS_NODE ]]; then
|
|
|
4a6108 |
rc=$(< $FADUMP_ENABLED_SYS_NODE)
|
|
|
4a6108 |
[[ $rc -eq 1 ]] && return 0
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
return 1
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
4a6108 |
is_squash_available()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
for kmodule in squashfs overlay loop; do
|
|
|
4a6108 |
if [[ -z $KDUMP_KERNELVER ]]; then
|
|
|
4a6108 |
modprobe --dry-run $kmodule &> /dev/null || return 1
|
|
|
4a6108 |
else
|
|
|
4a6108 |
modprobe -S "$KDUMP_KERNELVER" --dry-run $kmodule &> /dev/null || return 1
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
done
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
455616 |
is_zstd_command_available()
|
|
|
455616 |
{
|
|
|
455616 |
[[ -x "$(command -v zstd)" ]]
|
|
|
455616 |
}
|
|
|
455616 |
|
|
|
4a6108 |
perror_exit()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
derror "$@"
|
|
|
4a6108 |
exit 1
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# Check if fence kdump is configured in Pacemaker cluster
|
|
|
db7d74 |
is_pcs_fence_kdump()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
# no pcs or fence_kdump_send executables installed?
|
|
|
4a6108 |
type -P pcs > /dev/null || return 1
|
|
|
4a6108 |
[[ -x $FENCE_KDUMP_SEND ]] || return 1
|
|
|
db7d74 |
|
|
|
4a6108 |
# fence kdump not configured?
|
|
|
4a6108 |
(pcs cluster cib | grep 'type="fence_kdump"') &> /dev/null || return 1
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# Check if fence_kdump is configured using kdump options
|
|
|
db7d74 |
is_generic_fence_kdump()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
[[ -x $FENCE_KDUMP_SEND ]] || return 1
|
|
|
db7d74 |
|
|
|
4a6108 |
[[ $(kdump_get_conf_val fence_kdump_nodes) ]]
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
4a6108 |
to_dev_name()
|
|
|
4a6108 |
{
|
|
|
4a6108 |
local dev="${1//\"/}"
|
|
|
4a6108 |
|
|
|
4a6108 |
case "$dev" in
|
|
|
4a6108 |
UUID=*)
|
|
|
4a6108 |
blkid -U "${dev#UUID=}"
|
|
|
4a6108 |
;;
|
|
|
4a6108 |
LABEL=*)
|
|
|
4a6108 |
blkid -L "${dev#LABEL=}"
|
|
|
4a6108 |
;;
|
|
|
4a6108 |
*)
|
|
|
4a6108 |
echo "$dev"
|
|
|
4a6108 |
;;
|
|
|
4a6108 |
esac
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
is_user_configured_dump_target()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
[[ $(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw\|nfs\|ssh") ]] || is_mount_in_dracut_args
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
get_user_configured_dump_disk()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local _target
|
|
|
db7d74 |
|
|
|
4a6108 |
_target=$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw")
|
|
|
4a6108 |
[[ -n $_target ]] && echo "$_target" && return
|
|
|
db7d74 |
|
|
|
4a6108 |
_target=$(get_dracut_args_target "$(kdump_get_conf_val "dracut_args")")
|
|
|
4a6108 |
[[ -b $_target ]] && echo "$_target"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
get_block_dump_target()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local _target _path
|
|
|
db7d74 |
|
|
|
4a6108 |
if is_ssh_dump_target || is_nfs_dump_target; then
|
|
|
4a6108 |
return
|
|
|
4a6108 |
fi
|
|
|
db7d74 |
|
|
|
4a6108 |
_target=$(get_user_configured_dump_disk)
|
|
|
4a6108 |
[[ -n $_target ]] && to_dev_name "$_target" && return
|
|
|
db7d74 |
|
|
|
4a6108 |
# Get block device name from local save path
|
|
|
4a6108 |
_path=$(get_save_path)
|
|
|
4a6108 |
_target=$(get_target_from_path "$_path")
|
|
|
4a6108 |
[[ -b $_target ]] && to_dev_name "$_target"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
is_dump_to_rootfs()
|
|
|
db7d74 |
{
|
|
|
455616 |
[[ $(kdump_get_conf_val 'failure_action\|default') == dump_to_rootfs ]]
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
get_failure_action_target()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local _target
|
|
|
4a6108 |
|
|
|
4a6108 |
if is_dump_to_rootfs; then
|
|
|
4a6108 |
# Get rootfs device name
|
|
|
4a6108 |
_target=$(get_root_fs_device)
|
|
|
4a6108 |
[[ -b $_target ]] && to_dev_name "$_target" && return
|
|
|
4a6108 |
# Then, must be nfs root
|
|
|
4a6108 |
echo "nfs"
|
|
|
4a6108 |
fi
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# Get kdump targets(including root in case of dump_to_rootfs).
|
|
|
db7d74 |
get_kdump_targets()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local _target _root
|
|
|
4a6108 |
local kdump_targets
|
|
|
4a6108 |
|
|
|
4a6108 |
_target=$(get_block_dump_target)
|
|
|
4a6108 |
if [[ -n $_target ]]; then
|
|
|
4a6108 |
kdump_targets=$_target
|
|
|
4a6108 |
elif is_ssh_dump_target; then
|
|
|
4a6108 |
kdump_targets="ssh"
|
|
|
4a6108 |
else
|
|
|
4a6108 |
kdump_targets="nfs"
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
|
|
|
4a6108 |
# Add the root device if dump_to_rootfs is specified.
|
|
|
4a6108 |
_root=$(get_failure_action_target)
|
|
|
4a6108 |
if [[ -n $_root ]] && [[ $kdump_targets != "$_root" ]]; then
|
|
|
4a6108 |
kdump_targets="$kdump_targets $_root"
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
|
|
|
4a6108 |
echo "$kdump_targets"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# Return the bind mount source path, return the path itself if it's not bind mounted
|
|
|
db7d74 |
# Eg. if /path/to/src is bind mounted to /mnt/bind, then:
|
|
|
db7d74 |
# /mnt/bind -> /path/to/src, /mnt/bind/dump -> /path/to/src/dump
|
|
|
db7d74 |
#
|
|
|
db7d74 |
# findmnt uses the option "-v, --nofsroot" to exclusive the [/dir]
|
|
|
db7d74 |
# in the SOURCE column for bind-mounts, then if $_src equals to
|
|
|
db7d74 |
# $_src_nofsroot, the mountpoint is not bind mounted directory.
|
|
|
db7d74 |
#
|
|
|
db7d74 |
# Below is just an example for mount info
|
|
|
db7d74 |
# /dev/mapper/atomicos-root[/ostree/deploy/rhel-atomic-host/var], if the
|
|
|
db7d74 |
# directory is bind mounted. The former part represents the device path, rest
|
|
|
db7d74 |
# part is the bind mounted directory which quotes by bracket "[]".
|
|
|
db7d74 |
get_bind_mount_source()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local _mnt _path _src _opt _fstype
|
|
|
4a6108 |
local _fsroot _src_nofsroot
|
|
|
db7d74 |
|
|
|
4a6108 |
_mnt=$(df "$1" | tail -1 | awk '{print $NF}')
|
|
|
4a6108 |
_path=${1#$_mnt}
|
|
|
db7d74 |
|
|
|
4a6108 |
_src=$(get_mount_info SOURCE target "$_mnt" -f)
|
|
|
4a6108 |
_opt=$(get_mount_info OPTIONS target "$_mnt" -f)
|
|
|
4a6108 |
_fstype=$(get_mount_info FSTYPE target "$_mnt" -f)
|
|
|
db7d74 |
|
|
|
4a6108 |
# bind mount in fstab
|
|
|
4a6108 |
if [[ -d $_src ]] && [[ $_fstype == none ]] && (echo "$_opt" | grep -q "\bbind\b"); then
|
|
|
4a6108 |
echo "$_src$_path" && return
|
|
|
4a6108 |
fi
|
|
|
db7d74 |
|
|
|
4a6108 |
# direct mount
|
|
|
4a6108 |
_src_nofsroot=$(get_mount_info SOURCE target "$_mnt" -v -f)
|
|
|
4a6108 |
if [[ $_src_nofsroot == "$_src" ]]; then
|
|
|
4a6108 |
echo "$_mnt$_path" && return
|
|
|
4a6108 |
fi
|
|
|
db7d74 |
|
|
|
4a6108 |
_fsroot=${_src#${_src_nofsroot}[}
|
|
|
4a6108 |
_fsroot=${_fsroot%]}
|
|
|
4a6108 |
_mnt=$(get_mount_info TARGET source "$_src_nofsroot" -f)
|
|
|
db7d74 |
|
|
|
4a6108 |
# for btrfs, _fsroot will also contain the subvol value as well, strip it
|
|
|
4a6108 |
if [[ $_fstype == btrfs ]]; then
|
|
|
4a6108 |
local _subvol
|
|
|
4a6108 |
_subvol=${_opt#*subvol=}
|
|
|
4a6108 |
_subvol=${_subvol%,*}
|
|
|
4a6108 |
_fsroot=${_fsroot#$_subvol}
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
echo "$_mnt$_fsroot$_path"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
get_mntopt_from_target()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
get_mount_info OPTIONS source "$1" -f
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# Get the path where the target will be mounted in kdump kernel
|
|
|
db7d74 |
# $1: kdump target device
|
|
|
db7d74 |
get_kdump_mntpoint_from_target()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local _mntpoint
|
|
|
db7d74 |
|
|
|
4a6108 |
_mntpoint=$(get_mntpoint_from_target "$1")
|
|
|
4a6108 |
# mount under /sysroot if dump to root disk or mount under
|
|
|
4a6108 |
# mount under /kdumproot if dump target is not mounted in first kernel
|
|
|
4a6108 |
# mount under /kdumproot/$_mntpoint in other cases in 2nd kernel.
|
|
|
4a6108 |
# systemd will be in charge to umount it.
|
|
|
4a6108 |
if [[ -z $_mntpoint ]]; then
|
|
|
4a6108 |
_mntpoint="/kdumproot"
|
|
|
4a6108 |
else
|
|
|
4a6108 |
if [[ $_mntpoint == "/" ]]; then
|
|
|
4a6108 |
_mntpoint="/sysroot"
|
|
|
4a6108 |
else
|
|
|
4a6108 |
_mntpoint="/kdumproot/$_mntpoint"
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
fi
|
|
|
db7d74 |
|
|
|
4a6108 |
# strip duplicated "/"
|
|
|
4a6108 |
echo $_mntpoint | tr -s "/"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
4a6108 |
kdump_get_persistent_dev()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local dev="${1//\"/}"
|
|
|
4a6108 |
|
|
|
4a6108 |
case "$dev" in
|
|
|
4a6108 |
UUID=*)
|
|
|
4a6108 |
dev=$(blkid -U "${dev#UUID=}")
|
|
|
4a6108 |
;;
|
|
|
4a6108 |
LABEL=*)
|
|
|
4a6108 |
dev=$(blkid -L "${dev#LABEL=}")
|
|
|
4a6108 |
;;
|
|
|
4a6108 |
esac
|
|
|
4a6108 |
echo $(get_persistent_dev "$dev")
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
4a6108 |
is_atomic()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
grep -q "ostree" /proc/cmdline
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# get ip address or hostname from nfs/ssh config value
|
|
|
db7d74 |
get_remote_host()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local _config_val=$1
|
|
|
4a6108 |
|
|
|
4a6108 |
# ipv6 address in kdump.conf is around with "[]",
|
|
|
4a6108 |
# factor out the ipv6 address
|
|
|
4a6108 |
_config_val=${_config_val#*@}
|
|
|
4a6108 |
_config_val=${_config_val%:/*}
|
|
|
4a6108 |
_config_val=${_config_val#[}
|
|
|
4a6108 |
_config_val=${_config_val%]}
|
|
|
4a6108 |
echo "$_config_val"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
is_hostname()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local _hostname
|
|
|
db7d74 |
|
|
|
4a6108 |
_hostname=$(echo "$1" | grep ":")
|
|
|
4a6108 |
if [[ -n $_hostname ]]; then
|
|
|
4a6108 |
return 1
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
echo "$1" | grep -q "[a-zA-Z]"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# Copied from "/etc/sysconfig/network-scripts/network-functions"
|
|
|
db7d74 |
get_hwaddr()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
if [[ -f "/sys/class/net/$1/address" ]]; then
|
|
|
4a6108 |
awk '{ print toupper($0) }' < "/sys/class/net/$1/address"
|
|
|
4a6108 |
elif [[ -d "/sys/class/net/$1" ]]; then
|
|
|
4a6108 |
LC_ALL="" LANG="" ip -o link show "$1" 2> /dev/null |
|
|
|
4a6108 |
awk '{ print toupper(gensub(/.*link\/[^ ]* ([[:alnum:]:]*).*/,
|
|
|
db7d74 |
"\\1", 1)); }'
|
|
|
4a6108 |
fi
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# Get value by a field using "nmcli -g"
|
|
|
4a6108 |
# Usage: get_nmcli_value_by_field <field> <nmcli command>
|
|
|
db7d74 |
#
|
|
|
db7d74 |
# "nmcli --get-values" allows us to retrive value(s) by field, for example,
|
|
|
db7d74 |
# nmcli --get-values <field> connection show /org/freedesktop/NetworkManager/ActiveConnection/1
|
|
|
db7d74 |
# returns the following value for the corresponding field respectively,
|
|
|
db7d74 |
# Field Value
|
|
|
db7d74 |
# IP4.DNS "10.19.42.41 | 10.11.5.19 | 10.5.30.160"
|
|
|
db7d74 |
# 802-3-ethernet.s390-subchannels ""
|
|
|
db7d74 |
# bond.options "mode=balance-rr"
|
|
|
db7d74 |
get_nmcli_value_by_field()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
LANG=C nmcli --get-values "$@"
|
|
|
4a6108 |
}
|
|
|
db7d74 |
|
|
|
4a6108 |
# Get nmcli field value of an connection apath (a D-Bus active connection path)
|
|
|
4a6108 |
# Usage: get_nmcli_field_by_apath <field> <apath>
|
|
|
4a6108 |
get_nmcli_field_by_conpath()
|
|
|
4a6108 |
{
|
|
|
4a6108 |
local _field=$1 _apath=$2
|
|
|
db7d74 |
|
|
|
4a6108 |
get_nmcli_value_by_field "$_field" connection show "$_apath"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# Get nmcli connection apath (a D-Bus active connection path ) by ifname
|
|
|
db7d74 |
#
|
|
|
db7d74 |
# apath is used for nmcli connection operations, e.g.
|
|
|
db7d74 |
# $ nmcli connection show $apath
|
|
|
db7d74 |
get_nmcli_connection_apath_by_ifname()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local _ifname=$1
|
|
|
db7d74 |
|
|
|
4a6108 |
get_nmcli_value_by_field "GENERAL.CON-PATH" device show "$_ifname"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
get_ifcfg_by_device()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
grep -E -i -l "^[[:space:]]*DEVICE=\"*${1}\"*[[:space:]]*$" \
|
|
|
4a6108 |
/etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
get_ifcfg_by_hwaddr()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
grep -E -i -l "^[[:space:]]*HWADDR=\"*${1}\"*[[:space:]]*$" \
|
|
|
4a6108 |
/etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
get_ifcfg_by_uuid()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
grep -E -i -l "^[[:space:]]*UUID=\"*${1}\"*[[:space:]]*$" \
|
|
|
4a6108 |
/etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
get_ifcfg_by_name()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
grep -E -i -l "^[[:space:]]*NAME=\"*${1}\"*[[:space:]]*$" \
|
|
|
4a6108 |
/etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
is_nm_running()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
[[ "$(LANG=C nmcli -t --fields running general status 2> /dev/null)" == "running" ]]
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
is_nm_handling()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
LANG=C nmcli -t --fields device,state dev status 2> /dev/null |
|
|
|
4a6108 |
grep -q "^\(${1}:connected\)\|\(${1}:connecting.*\)$"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# $1: netdev name
|
|
|
db7d74 |
get_ifcfg_nmcli()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local nm_uuid nm_name
|
|
|
4a6108 |
local ifcfg_file
|
|
|
4a6108 |
|
|
|
4a6108 |
# Get the active nmcli config name of $1
|
|
|
4a6108 |
if is_nm_running && is_nm_handling "${1}"; then
|
|
|
4a6108 |
# The configuration "uuid" and "name" generated by nm is wrote to
|
|
|
4a6108 |
# the ifcfg file as "UUID=<nm_uuid>" and "NAME=<nm_name>".
|
|
|
4a6108 |
nm_uuid=$(LANG=C nmcli -t --fields uuid,device c show --active 2> /dev/null |
|
|
|
4a6108 |
grep "${1}" | head -1 | cut -d':' -f1)
|
|
|
4a6108 |
nm_name=$(LANG=C nmcli -t --fields name,device c show --active 2> /dev/null |
|
|
|
4a6108 |
grep "${1}" | head -1 | cut -d':' -f1)
|
|
|
4a6108 |
ifcfg_file=$(get_ifcfg_by_uuid "${nm_uuid}")
|
|
|
4a6108 |
[[ -z ${ifcfg_file} ]] && ifcfg_file=$(get_ifcfg_by_name "${nm_name}")
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
|
|
|
4a6108 |
echo -n "${ifcfg_file}"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# $1: netdev name
|
|
|
db7d74 |
get_ifcfg_legacy()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local ifcfg_file hwaddr
|
|
|
db7d74 |
|
|
|
4a6108 |
ifcfg_file="/etc/sysconfig/network-scripts/ifcfg-${1}"
|
|
|
4a6108 |
[[ -f ${ifcfg_file} ]] && echo -n "${ifcfg_file}" && return
|
|
|
db7d74 |
|
|
|
4a6108 |
ifcfg_file=$(get_ifcfg_by_name "${1}")
|
|
|
4a6108 |
[[ -f ${ifcfg_file} ]] && echo -n "${ifcfg_file}" && return
|
|
|
db7d74 |
|
|
|
4a6108 |
hwaddr=$(get_hwaddr "${1}")
|
|
|
4a6108 |
if [[ -n $hwaddr ]]; then
|
|
|
4a6108 |
ifcfg_file=$(get_ifcfg_by_hwaddr "${hwaddr}")
|
|
|
4a6108 |
[[ -f ${ifcfg_file} ]] && echo -n "${ifcfg_file}" && return
|
|
|
4a6108 |
fi
|
|
|
db7d74 |
|
|
|
4a6108 |
ifcfg_file=$(get_ifcfg_by_device "${1}")
|
|
|
db7d74 |
|
|
|
4a6108 |
echo -n "${ifcfg_file}"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# $1: netdev name
|
|
|
db7d74 |
# Return the ifcfg file whole name(including the path) of $1 if any.
|
|
|
4a6108 |
get_ifcfg_filename()
|
|
|
4a6108 |
{
|
|
|
4a6108 |
local ifcfg_file
|
|
|
db7d74 |
|
|
|
4a6108 |
ifcfg_file=$(get_ifcfg_nmcli "${1}")
|
|
|
4a6108 |
if [[ -z ${ifcfg_file} ]]; then
|
|
|
4a6108 |
ifcfg_file=$(get_ifcfg_legacy "${1}")
|
|
|
4a6108 |
fi
|
|
|
db7d74 |
|
|
|
4a6108 |
echo -n "${ifcfg_file}"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# returns 0 when omission of a module is desired in dracut_args
|
|
|
db7d74 |
# returns 1 otherwise
|
|
|
4a6108 |
is_dracut_mod_omitted()
|
|
|
4a6108 |
{
|
|
|
4a6108 |
local dracut_args dracut_mod=$1
|
|
|
4a6108 |
|
|
|
4a6108 |
set -- $(kdump_get_conf_val dracut_args)
|
|
|
4a6108 |
while [ $# -gt 0 ]; do
|
|
|
4a6108 |
case $1 in
|
|
|
4a6108 |
-o | --omit)
|
|
|
4a6108 |
[[ " ${2//[^[:alnum:]]/ } " == *" $dracut_mod "* ]] && return 0
|
|
|
4a6108 |
;;
|
|
|
4a6108 |
esac
|
|
|
4a6108 |
shift
|
|
|
4a6108 |
done
|
|
|
4a6108 |
|
|
|
4a6108 |
return 1
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
4a6108 |
is_wdt_active()
|
|
|
4a6108 |
{
|
|
|
4a6108 |
local active
|
|
|
db7d74 |
|
|
|
4a6108 |
[[ -d /sys/class/watchdog ]] || return 1
|
|
|
4a6108 |
for dir in /sys/class/watchdog/*; do
|
|
|
4a6108 |
[[ -f "$dir/state" ]] || continue
|
|
|
4a6108 |
active=$(< "$dir/state")
|
|
|
4a6108 |
[[ $active == "active" ]] && return 0
|
|
|
4a6108 |
done
|
|
|
4a6108 |
return 1
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
455616 |
have_compression_in_dracut_args()
|
|
|
455616 |
{
|
|
|
455616 |
[[ "$(kdump_get_conf_val dracut_args)" =~ \
|
|
|
455616 |
(^|[[:space:]])--(gzip|bzip2|lzma|xz|lzo|lz4|zstd|no-compress|compress)([[:space:]]|$) ]]
|
|
|
455616 |
}
|
|
|
455616 |
|
|
|
db7d74 |
# If "dracut_args" contains "--mount" information, use it
|
|
|
db7d74 |
# directly without any check(users are expected to ensure
|
|
|
db7d74 |
# its correctness).
|
|
|
db7d74 |
is_mount_in_dracut_args()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
[[ " $(kdump_get_conf_val dracut_args)" =~ .*[[:space:]]--mount[=[:space:]].* ]]
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
check_crash_mem_reserved()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local mem_reserved
|
|
|
db7d74 |
|
|
|
4a6108 |
mem_reserved=$(< /sys/kernel/kexec_crash_size)
|
|
|
4a6108 |
if [[ $mem_reserved -eq 0 ]]; then
|
|
|
4a6108 |
derror "No memory reserved for crash kernel"
|
|
|
4a6108 |
return 1
|
|
|
4a6108 |
fi
|
|
|
db7d74 |
|
|
|
4a6108 |
return 0
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
check_kdump_feasibility()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
if [[ ! -e /sys/kernel/kexec_crash_loaded ]]; then
|
|
|
4a6108 |
derror "Kdump is not supported on this kernel"
|
|
|
4a6108 |
return 1
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
check_crash_mem_reserved
|
|
|
4a6108 |
return $?
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
check_current_kdump_status()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
if [[ ! -f /sys/kernel/kexec_crash_loaded ]]; then
|
|
|
4a6108 |
derror "Perhaps CONFIG_CRASH_DUMP is not enabled in kernel"
|
|
|
4a6108 |
return 1
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
|
|
|
4a6108 |
rc=$(< /sys/kernel/kexec_crash_loaded)
|
|
|
4a6108 |
if [[ $rc == 1 ]]; then
|
|
|
4a6108 |
return 0
|
|
|
4a6108 |
else
|
|
|
4a6108 |
return 1
|
|
|
4a6108 |
fi
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# remove_cmdline_param <kernel cmdline> <param1> [<param2>] ... [<paramN>]
|
|
|
db7d74 |
# Remove a list of kernel parameters from a given kernel cmdline and print the result.
|
|
|
db7d74 |
# For each "arg" in the removing params list, "arg" and "arg=xxx" will be removed if exists.
|
|
|
db7d74 |
remove_cmdline_param()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local cmdline=$1
|
|
|
4a6108 |
shift
|
|
|
4a6108 |
|
|
|
4a6108 |
for arg in "$@"; do
|
|
|
4a6108 |
cmdline=$(echo "$cmdline" |
|
|
|
4a6108 |
sed -e "s/\b$arg=[^ ]*//g" \
|
|
|
4a6108 |
-e "s/^$arg\b//g" \
|
|
|
4a6108 |
-e "s/[[:space:]]$arg\b//g" \
|
|
|
4a6108 |
-e "s/\s\+/ /g")
|
|
|
4a6108 |
done
|
|
|
4a6108 |
echo "$cmdline"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
#
|
|
|
db7d74 |
# This function returns the "apicid" of the boot
|
|
|
db7d74 |
# cpu (cpu 0) if present.
|
|
|
db7d74 |
#
|
|
|
db7d74 |
get_bootcpu_apicid()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
awk ' \
|
|
|
db7d74 |
BEGIN { CPU = "-1"; } \
|
|
|
db7d74 |
$1=="processor" && $2==":" { CPU = $NF; } \
|
|
|
db7d74 |
CPU=="0" && /^apicid/ { print $NF; } \
|
|
|
4a6108 |
' \
|
|
|
4a6108 |
/proc/cpuinfo
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
#
|
|
|
db7d74 |
# append_cmdline <kernel cmdline> <parameter name> <parameter value>
|
|
|
db7d74 |
# This function appends argument "$2=$3" to string ($1) if not already present.
|
|
|
db7d74 |
#
|
|
|
db7d74 |
append_cmdline()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local cmdline=$1
|
|
|
4a6108 |
local newstr=${cmdline/$2/""}
|
|
|
db7d74 |
|
|
|
4a6108 |
# unchanged str implies argument wasn't there
|
|
|
4a6108 |
if [[ $cmdline == "$newstr" ]]; then
|
|
|
4a6108 |
cmdline="${cmdline} ${2}=${3}"
|
|
|
4a6108 |
fi
|
|
|
db7d74 |
|
|
|
4a6108 |
echo "$cmdline"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# This function check iomem and determines if we have more than
|
|
|
db7d74 |
# 4GB of ram available. Returns 1 if we do, 0 if we dont
|
|
|
db7d74 |
need_64bit_headers()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
return "$(tail -n 1 /proc/iomem | awk '{ split ($1, r, "-");
|
|
|
4a6108 |
print (strtonum("0x" r[2]) > strtonum("0xffffffff")); }')"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# Check if secure boot is being enforced.
|
|
|
db7d74 |
#
|
|
|
db7d74 |
# Per Peter Jones, we need check efivar SecureBoot-$(the UUID) and
|
|
|
db7d74 |
# SetupMode-$(the UUID), they are both 5 bytes binary data. The first four
|
|
|
db7d74 |
# bytes are the attributes associated with the variable and can safely be
|
|
|
db7d74 |
# ignored, the last bytes are one-byte true-or-false variables. If SecureBoot
|
|
|
db7d74 |
# is 1 and SetupMode is 0, then secure boot is being enforced.
|
|
|
db7d74 |
#
|
|
|
db7d74 |
# Assume efivars is mounted at /sys/firmware/efi/efivars.
|
|
|
db7d74 |
is_secure_boot_enforced()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local secure_boot_file setup_mode_file
|
|
|
4a6108 |
local secure_boot_byte setup_mode_byte
|
|
|
db7d74 |
|
|
|
41d07d |
# On powerpc, secure boot is enforced if:
|
|
|
41d07d |
# host secure boot: /ibm,secure-boot/os-secureboot-enforcing DT property exists
|
|
|
41d07d |
# guest secure boot: /ibm,secure-boot >= 2
|
|
|
4a6108 |
if [[ -f /proc/device-tree/ibm,secureboot/os-secureboot-enforcing ]]; then
|
|
|
db7d74 |
return 0
|
|
|
4a6108 |
fi
|
|
|
41d07d |
if [[ -f /proc/device-tree/ibm,secure-boot ]] &&
|
|
|
41d07d |
[[ $(lsprop /proc/device-tree/ibm,secure-boot | tail -1) -ge 2 ]]; then
|
|
|
41d07d |
return 0
|
|
|
41d07d |
fi
|
|
|
db7d74 |
|
|
|
4a6108 |
# Detect secure boot on x86 and arm64
|
|
|
4a6108 |
secure_boot_file=$(find /sys/firmware/efi/efivars -name "SecureBoot-*" 2> /dev/null)
|
|
|
4a6108 |
setup_mode_file=$(find /sys/firmware/efi/efivars -name "SetupMode-*" 2> /dev/null)
|
|
|
db7d74 |
|
|
|
4a6108 |
if [[ -f $secure_boot_file ]] && [[ -f $setup_mode_file ]]; then
|
|
|
4a6108 |
secure_boot_byte=$(hexdump -v -e '/1 "%d\ "' "$secure_boot_file" | cut -d' ' -f 5)
|
|
|
4a6108 |
setup_mode_byte=$(hexdump -v -e '/1 "%d\ "' "$setup_mode_file" | cut -d' ' -f 5)
|
|
|
db7d74 |
|
|
|
4a6108 |
if [[ $secure_boot_byte == "1" ]] && [[ $setup_mode_byte == "0" ]]; then
|
|
|
4a6108 |
return 0
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
fi
|
|
|
db7d74 |
|
|
|
4a6108 |
# Detect secure boot on s390x
|
|
|
4a6108 |
if [[ -e "/sys/firmware/ipl/secure" && "$(< /sys/firmware/ipl/secure)" == "1" ]]; then
|
|
|
4a6108 |
return 0
|
|
|
4a6108 |
fi
|
|
|
db7d74 |
|
|
|
4a6108 |
return 1
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
#
|
|
|
db7d74 |
# prepare_kexec_args <kexec args>
|
|
|
db7d74 |
# This function prepares kexec argument.
|
|
|
db7d74 |
#
|
|
|
db7d74 |
prepare_kexec_args()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local kexec_args=$1
|
|
|
4a6108 |
local found_elf_args
|
|
|
4a6108 |
|
|
|
4a6108 |
ARCH=$(uname -m)
|
|
|
4a6108 |
if [[ $ARCH == "i686" ]] || [[ $ARCH == "i386" ]]; then
|
|
|
4a6108 |
need_64bit_headers
|
|
|
4a6108 |
if [[ $? == 1 ]]; then
|
|
|
4a6108 |
found_elf_args=$(echo "$kexec_args" | grep elf32-core-headers)
|
|
|
4a6108 |
if [[ -n $found_elf_args ]]; then
|
|
|
4a6108 |
dwarn "Warning: elf32-core-headers overrides correct elf64 setting"
|
|
|
4a6108 |
else
|
|
|
4a6108 |
kexec_args="$kexec_args --elf64-core-headers"
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
else
|
|
|
4a6108 |
found_elf_args=$(echo "$kexec_args" | grep elf64-core-headers)
|
|
|
4a6108 |
if [[ -z $found_elf_args ]]; then
|
|
|
4a6108 |
kexec_args="$kexec_args --elf32-core-headers"
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
echo "$kexec_args"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
#
|
|
|
db7d74 |
# Detect initrd and kernel location, results are stored in global enviromental variables:
|
|
|
db7d74 |
# KDUMP_BOOTDIR, KDUMP_KERNELVER, KDUMP_KERNEL, DEFAULT_INITRD, and KDUMP_INITRD
|
|
|
db7d74 |
#
|
|
|
db7d74 |
# Expectes KDUMP_BOOTDIR, KDUMP_IMG, KDUMP_IMG_EXT, KDUMP_KERNELVER to be loaded from config already
|
|
|
db7d74 |
# and will prefer already set values so user can specify custom kernel/initramfs location
|
|
|
db7d74 |
#
|
|
|
db7d74 |
prepare_kdump_bootinfo()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local boot_img boot_imglist boot_dirlist boot_initrdlist
|
|
|
4a6108 |
local machine_id
|
|
|
4a6108 |
|
|
|
4a6108 |
if [[ -z $KDUMP_KERNELVER ]]; then
|
|
|
4a6108 |
KDUMP_KERNELVER="$(uname -r)"
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
|
|
|
4a6108 |
read -r machine_id < /etc/machine-id
|
|
|
4a6108 |
boot_dirlist=${KDUMP_BOOTDIR:-"/boot /boot/efi /efi /"}
|
|
|
4a6108 |
boot_imglist="$KDUMP_IMG-$KDUMP_KERNELVER$KDUMP_IMG_EXT $machine_id/$KDUMP_KERNELVER/$KDUMP_IMG"
|
|
|
4a6108 |
|
|
|
4a6108 |
# Use BOOT_IMAGE as reference if possible, strip the GRUB root device prefix in (hd0,gpt1) format
|
|
|
4a6108 |
boot_img="$(sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/" /proc/cmdline)"
|
|
|
4a6108 |
if [[ -n $boot_img ]]; then
|
|
|
4a6108 |
boot_imglist="$boot_img $boot_imglist"
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
|
|
|
4a6108 |
for dir in $boot_dirlist; do
|
|
|
4a6108 |
for img in $boot_imglist; do
|
|
|
4a6108 |
if [[ -f "$dir/$img" ]]; then
|
|
|
4a6108 |
KDUMP_KERNEL=$(echo "$dir/$img" | tr -s '/')
|
|
|
4a6108 |
break 2
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
done
|
|
|
4a6108 |
done
|
|
|
4a6108 |
|
|
|
4a6108 |
if ! [[ -e $KDUMP_KERNEL ]]; then
|
|
|
4a6108 |
derror "Failed to detect kdump kernel location"
|
|
|
4a6108 |
return 1
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
|
|
|
4a6108 |
# Set KDUMP_BOOTDIR to where kernel image is stored
|
|
|
4a6108 |
KDUMP_BOOTDIR=$(dirname "$KDUMP_KERNEL")
|
|
|
4a6108 |
|
|
|
4a6108 |
# Default initrd should just stay aside of kernel image, try to find it in KDUMP_BOOTDIR
|
|
|
4a6108 |
boot_initrdlist="initramfs-$KDUMP_KERNELVER.img initrd"
|
|
|
4a6108 |
for initrd in $boot_initrdlist; do
|
|
|
4a6108 |
if [[ -f "$KDUMP_BOOTDIR/$initrd" ]]; then
|
|
|
4a6108 |
defaut_initrd_base="$initrd"
|
|
|
4a6108 |
DEFAULT_INITRD="$KDUMP_BOOTDIR/$defaut_initrd_base"
|
|
|
4a6108 |
break
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
done
|
|
|
4a6108 |
|
|
|
4a6108 |
# Create kdump initrd basename from default initrd basename
|
|
|
4a6108 |
# initramfs-5.7.9-200.fc32.x86_64.img => initramfs-5.7.9-200.fc32.x86_64kdump.img
|
|
|
4a6108 |
# initrd => initrdkdump
|
|
|
4a6108 |
if [[ -z $defaut_initrd_base ]]; then
|
|
|
4a6108 |
kdump_initrd_base=initramfs-${KDUMP_KERNELVER}kdump.img
|
|
|
4a6108 |
elif [[ $defaut_initrd_base == *.* ]]; then
|
|
|
4a6108 |
kdump_initrd_base=${defaut_initrd_base%.*}kdump.${DEFAULT_INITRD##*.}
|
|
|
4a6108 |
else
|
|
|
4a6108 |
kdump_initrd_base=${defaut_initrd_base}kdump
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
|
|
|
4a6108 |
# Place kdump initrd in $(/var/lib/kdump) if $(KDUMP_BOOTDIR) not writable
|
|
|
4a6108 |
if [[ ! -w $KDUMP_BOOTDIR ]]; then
|
|
|
4a6108 |
var_target_initrd_dir="/var/lib/kdump"
|
|
|
4a6108 |
mkdir -p "$var_target_initrd_dir"
|
|
|
4a6108 |
KDUMP_INITRD="$var_target_initrd_dir/$kdump_initrd_base"
|
|
|
4a6108 |
else
|
|
|
4a6108 |
KDUMP_INITRD="$KDUMP_BOOTDIR/$kdump_initrd_base"
|
|
|
4a6108 |
fi
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
get_watchdog_drvs()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local _wdtdrvs _drv _dir
|
|
|
4a6108 |
|
|
|
4a6108 |
for _dir in /sys/class/watchdog/*; do
|
|
|
4a6108 |
# device/modalias will return driver of this device
|
|
|
4a6108 |
[[ -f "$_dir/device/modalias" ]] || continue
|
|
|
4a6108 |
_drv=$(< "$_dir/device/modalias")
|
|
|
4a6108 |
_drv=$(modprobe --set-version "$KDUMP_KERNELVER" -R "$_drv" 2> /dev/null)
|
|
|
4a6108 |
for i in $_drv; do
|
|
|
4a6108 |
if ! [[ " $_wdtdrvs " == *" $i "* ]]; then
|
|
|
4a6108 |
_wdtdrvs="$_wdtdrvs $i"
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
done
|
|
|
4a6108 |
done
|
|
|
4a6108 |
|
|
|
4a6108 |
echo "$_wdtdrvs"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
#
|
|
|
db7d74 |
# prepare_cmdline <commandline> <commandline remove> <commandline append>
|
|
|
db7d74 |
# This function performs a series of edits on the command line.
|
|
|
db7d74 |
# Store the final result in global $KDUMP_COMMANDLINE.
|
|
|
db7d74 |
prepare_cmdline()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local cmdline id arg
|
|
|
4a6108 |
|
|
|
4a6108 |
if [[ -z $1 ]]; then
|
|
|
4a6108 |
cmdline=$(< /proc/cmdline)
|
|
|
4a6108 |
else
|
|
|
4a6108 |
cmdline="$1"
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
|
|
|
4a6108 |
# These params should always be removed
|
|
|
4a6108 |
cmdline=$(remove_cmdline_param "$cmdline" crashkernel panic_on_warn)
|
|
|
4a6108 |
# These params can be removed configurably
|
|
|
4a6108 |
while read -r arg; do
|
|
|
4a6108 |
cmdline=$(remove_cmdline_param "$cmdline" "$arg")
|
|
|
4a6108 |
done <<< "$(echo "$2" | xargs -n 1 echo)"
|
|
|
4a6108 |
|
|
|
4a6108 |
# Always remove "root=X", as we now explicitly generate all kinds
|
|
|
4a6108 |
# of dump target mount information including root fs.
|
|
|
4a6108 |
#
|
|
|
4a6108 |
# We do this before KDUMP_COMMANDLINE_APPEND, if one really cares
|
|
|
4a6108 |
# about it(e.g. for debug purpose), then can pass "root=X" using
|
|
|
4a6108 |
# KDUMP_COMMANDLINE_APPEND.
|
|
|
4a6108 |
cmdline=$(remove_cmdline_param "$cmdline" root)
|
|
|
4a6108 |
|
|
|
4a6108 |
# With the help of "--hostonly-cmdline", we can avoid some interitage.
|
|
|
4a6108 |
cmdline=$(remove_cmdline_param "$cmdline" rd.lvm.lv rd.luks.uuid rd.dm.uuid rd.md.uuid fcoe)
|
|
|
4a6108 |
|
|
|
4a6108 |
# Remove netroot, rd.iscsi.initiator and iscsi_initiator since
|
|
|
4a6108 |
# we get duplicate entries for the same in case iscsi code adds
|
|
|
4a6108 |
# it as well.
|
|
|
4a6108 |
cmdline=$(remove_cmdline_param "$cmdline" netroot rd.iscsi.initiator iscsi_initiator)
|
|
|
4a6108 |
|
|
|
4a6108 |
cmdline="${cmdline} $3"
|
|
|
4a6108 |
|
|
|
4a6108 |
id=$(get_bootcpu_apicid)
|
|
|
4a6108 |
if [[ -n ${id} ]]; then
|
|
|
4a6108 |
cmdline=$(append_cmdline "$cmdline" disable_cpu_apicid "$id")
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
|
|
|
4a6108 |
# If any watchdog is used, set it's pretimeout to 0. pretimeout let
|
|
|
4a6108 |
# watchdog panic the kernel first, and reset the system after the
|
|
|
4a6108 |
# panic. If the system is already in kdump, panic is not helpful
|
|
|
4a6108 |
# and only increase the chance of watchdog failure.
|
|
|
4a6108 |
for i in $(get_watchdog_drvs); do
|
|
|
4a6108 |
cmdline+=" $i.pretimeout=0"
|
|
|
4a6108 |
|
|
|
4a6108 |
if [[ $i == hpwdt ]]; then
|
|
|
4a6108 |
# hpwdt have a special parameter kdumptimeout, is's only suppose
|
|
|
4a6108 |
# to be set to non-zero in first kernel. In kdump, non-zero
|
|
|
4a6108 |
# value could prevent the watchdog from resetting the system.
|
|
|
4a6108 |
cmdline+=" $i.kdumptimeout=0"
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
done
|
|
|
4a6108 |
|
|
|
4a6108 |
echo "$cmdline"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
#get system memory size in the unit of GB
|
|
|
db7d74 |
get_system_size()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
result=$(grep "System RAM" /proc/iomem | awk -F ":" '{ print $1 }' | tr "[:lower:]" "[:upper:]" | paste -sd+)
|
|
|
4a6108 |
result="+$result"
|
|
|
4a6108 |
# replace '-' with '+0x' and '+' with '-0x'
|
|
|
4a6108 |
sum=$(echo "$result" | sed -e 's/-/K0x/g' -e 's/+/-0x/g' -e 's/K/+/g')
|
|
|
4a6108 |
size=$(printf "%d\n" $((sum)))
|
|
|
4a6108 |
size=$((size / 1024 / 1024 / 1024))
|
|
|
4a6108 |
|
|
|
4a6108 |
echo "$size"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
get_recommend_size()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local mem_size=$1
|
|
|
4a6108 |
local _ck_cmdline=$2
|
|
|
4a6108 |
local OLDIFS="$IFS"
|
|
|
4a6108 |
|
|
|
4a6108 |
start=${_ck_cmdline::1}
|
|
|
4a6108 |
if [[ $mem_size -lt $start ]]; then
|
|
|
4a6108 |
echo "0M"
|
|
|
4a6108 |
return
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
IFS=','
|
|
|
4a6108 |
for i in $_ck_cmdline; do
|
|
|
4a6108 |
end=$(echo "$i" | awk -F "-" '{ print $2 }' | awk -F ":" '{ print $1 }')
|
|
|
4a6108 |
recommend=$(echo "$i" | awk -F "-" '{ print $2 }' | awk -F ":" '{ print $2 }')
|
|
|
4a6108 |
size=${end::-1}
|
|
|
4a6108 |
unit=${end: -1}
|
|
|
4a6108 |
if [[ $unit == 'T' ]]; then
|
|
|
4a6108 |
size=$((size * 1024))
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
if [[ $mem_size -lt $size ]]; then
|
|
|
4a6108 |
echo "$recommend"
|
|
|
4a6108 |
IFS="$OLDIFS"
|
|
|
4a6108 |
return
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
done
|
|
|
4a6108 |
IFS="$OLDIFS"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
455616 |
# get default crashkernel
|
|
|
455616 |
# $1 dump mode, if not specified, dump_mode will be judged by is_fadump_capable
|
|
|
455616 |
kdump_get_arch_recommend_crashkernel()
|
|
|
db7d74 |
{
|
|
|
455616 |
local _arch _ck_cmdline _dump_mode
|
|
|
4a6108 |
|
|
|
455616 |
if [[ -z "$1" ]]; then
|
|
|
455616 |
if is_fadump_capable; then
|
|
|
455616 |
_dump_mode=fadump
|
|
|
455616 |
else
|
|
|
455616 |
_dump_mode=kdump
|
|
|
455616 |
fi
|
|
|
455616 |
else
|
|
|
455616 |
_dump_mode=$1
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
|
|
|
455616 |
_arch=$(uname -m)
|
|
|
4a6108 |
|
|
|
455616 |
if [[ $_arch == "x86_64" ]] || [[ $_arch == "s390x" ]]; then
|
|
|
455616 |
_ck_cmdline="1G-4G:192M,4G-64G:256M,64G-:512M"
|
|
|
455616 |
elif [[ $_arch == "aarch64" ]]; then
|
|
|
455616 |
_ck_cmdline="2G-:448M"
|
|
|
455616 |
elif [[ $_arch == "ppc64le" ]]; then
|
|
|
455616 |
if [[ $_dump_mode == "fadump" ]]; then
|
|
|
455616 |
_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"
|
|
|
455616 |
else
|
|
|
455616 |
_ck_cmdline="2G-4G:384M,4G-16G:512M,16G-64G:1G,64G-128G:2G,128G-:4G"
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
|
|
|
455616 |
echo -n "$_ck_cmdline"
|
|
|
455616 |
}
|
|
|
4a6108 |
|
|
|
455616 |
# return recommended size based on current system RAM size
|
|
|
455616 |
# $1: kernel version, if not set, will defaults to $(uname -r)
|
|
|
455616 |
kdump_get_arch_recommend_size()
|
|
|
455616 |
{
|
|
|
455616 |
local _ck_cmdline _sys_mem
|
|
|
455616 |
|
|
|
455616 |
if ! [[ -r "/proc/iomem" ]]; then
|
|
|
455616 |
echo "Error, can not access /proc/iomem."
|
|
|
455616 |
return 1
|
|
|
455616 |
fi
|
|
|
455616 |
_sys_mem=$(get_system_size)
|
|
|
455616 |
_ck_cmdline=$(kdump_get_arch_recommend_crashkernel)
|
|
|
455616 |
_ck_cmdline=${_ck_cmdline//-:/-102400T:}
|
|
|
455616 |
get_recommend_size "$_sys_mem" "$_ck_cmdline"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# Print all underlying crypt devices of a block device
|
|
|
db7d74 |
# print nothing if device is not on top of a crypt device
|
|
|
db7d74 |
# $1: the block device to be checked in maj:min format
|
|
|
db7d74 |
get_luks_crypt_dev()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local _type
|
|
|
db7d74 |
|
|
|
4a6108 |
[[ -b /dev/block/$1 ]] || return 1
|
|
|
db7d74 |
|
|
|
4a6108 |
_type=$(eval "$(blkid -u filesystem,crypto -o export -- "/dev/block/$1"); echo \$TYPE")
|
|
|
4a6108 |
[[ $_type == "crypto_LUKS" ]] && echo "$1"
|
|
|
4a6108 |
|
|
|
4a6108 |
for _x in "/sys/dev/block/$1/slaves/"*; do
|
|
|
4a6108 |
[[ -f $_x/dev ]] || continue
|
|
|
4a6108 |
[[ $_x/subsystem -ef /sys/class/block ]] || continue
|
|
|
4a6108 |
get_luks_crypt_dev "$(< "$_x/dev")"
|
|
|
4a6108 |
done
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# kdump_get_maj_min <device>
|
|
|
db7d74 |
# Prints the major and minor of a device node.
|
|
|
db7d74 |
# Example:
|
|
|
db7d74 |
# $ get_maj_min /dev/sda2
|
|
|
db7d74 |
# 8:2
|
|
|
4a6108 |
kdump_get_maj_min()
|
|
|
4a6108 |
{
|
|
|
4a6108 |
local _majmin
|
|
|
4a6108 |
_majmin="$(stat -L -c '%t:%T' "$1" 2> /dev/null)"
|
|
|
4a6108 |
printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))"
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
get_all_kdump_crypt_dev()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local _dev
|
|
|
db7d74 |
|
|
|
4a6108 |
for _dev in $(get_block_dump_target); do
|
|
|
4a6108 |
get_luks_crypt_dev "$(kdump_get_maj_min "$_dev")"
|
|
|
4a6108 |
done
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
check_vmlinux()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
# Use readelf to check if it's a valid ELF
|
|
|
4a6108 |
readelf -h "$1" &> /dev/null || return 1
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
get_vmlinux_size()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
local size=0 _msize
|
|
|
db7d74 |
|
|
|
4a6108 |
while read -r _msize; do
|
|
|
4a6108 |
size=$((size + _msize))
|
|
|
4a6108 |
done <<< "$(readelf -l -W "$1" | awk '/^ LOAD/{print $6}' 2> /dev/stderr)"
|
|
|
db7d74 |
|
|
|
4a6108 |
echo $size
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
try_decompress()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
# The obscure use of the "tr" filter is to work around older versions of
|
|
|
4a6108 |
# "grep" that report the byte offset of the line instead of the pattern.
|
|
|
4a6108 |
|
|
|
4a6108 |
# Try to find the header ($1) and decompress from here
|
|
|
4a6108 |
for pos in $(tr "$1\n$2" "\n$2=" < "$4" | grep -abo "^$2"); do
|
|
|
4a6108 |
if ! type -P "$3" > /dev/null; then
|
|
|
4a6108 |
ddebug "Signiature detected but '$3' is missing, skip this decompressor"
|
|
|
4a6108 |
break
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
|
|
|
4a6108 |
pos=${pos%%:*}
|
|
|
4a6108 |
tail "-c+$pos" "$img" | $3 > "$5" 2> /dev/null
|
|
|
4a6108 |
if check_vmlinux "$5"; then
|
|
|
4a6108 |
ddebug "Kernel is extracted with '$3'"
|
|
|
4a6108 |
return 0
|
|
|
4a6108 |
fi
|
|
|
4a6108 |
done
|
|
|
4a6108 |
|
|
|
4a6108 |
return 1
|
|
|
db7d74 |
}
|
|
|
db7d74 |
|
|
|
db7d74 |
# Borrowed from linux/scripts/extract-vmlinux
|
|
|
db7d74 |
get_kernel_size()
|
|
|
db7d74 |
{
|
|
|
4a6108 |
# Prepare temp files:
|
|
|
4a6108 |
local tmp img=$1
|
|
|
4a6108 |
|
|
|
4a6108 |
tmp=$(mktemp /tmp/vmlinux-XXX)
|
|
|
4a6108 |
trap 'rm -f "$tmp"' 0
|
|
|
4a6108 |
|
|
|
4a6108 |
# Try to check if it's a vmlinux already
|
|
|
4a6108 |
check_vmlinux "$img" && get_vmlinux_size "$img" && return 0
|
|
|
4a6108 |
|
|
|
4a6108 |
# That didn't work, so retry after decompression.
|
|
|
4a6108 |
try_decompress '\037\213\010' xy gunzip "$img" "$tmp" ||
|
|
|
4a6108 |
try_decompress '\3757zXZ\000' abcde unxz "$img" "$tmp" ||
|
|
|
4a6108 |
try_decompress 'BZh' xy bunzip2 "$img" "$tmp" ||
|
|
|
4a6108 |
try_decompress '\135\0\0\0' xxx unlzma "$img" "$tmp" ||
|
|
|
4a6108 |
try_decompress '\211\114\132' xy 'lzop -d' "$img" "$tmp" ||
|
|
|
4a6108 |
try_decompress '\002!L\030' xxx 'lz4 -d' "$img" "$tmp" ||
|
|
|
4a6108 |
try_decompress '(\265/\375' xxx unzstd "$img" "$tmp"
|
|
|
4a6108 |
|
|
|
4a6108 |
# Finally check for uncompressed images or objects:
|
|
|
4a6108 |
[[ $? -eq 0 ]] && get_vmlinux_size "$tmp" && return 0
|
|
|
4a6108 |
|
|
|
4a6108 |
# Fallback to use iomem
|
|
|
4a6108 |
local _size=0 _seg
|
|
|
4a6108 |
while read -r _seg; do
|
|
|
4a6108 |
_size=$((_size + 0x${_seg#*-} - 0x${_seg%-*}))
|
|
|
4a6108 |
done <<< "$(grep -E "Kernel (code|rodata|data|bss)" /proc/iomem | cut -d ":" -f 1)"
|
|
|
4a6108 |
echo $_size
|
|
|
db7d74 |
}
|