|
|
b9e861 |
#!/bin/sh
|
|
|
b9e861 |
#
|
|
|
b9e861 |
# Kdump common variables and functions
|
|
|
b9e861 |
#
|
|
|
b9e861 |
|
|
|
b9e861 |
DEFAULT_PATH="/var/crash/"
|
|
|
b9e861 |
FENCE_KDUMP_CONFIG_FILE="/etc/sysconfig/fence_kdump"
|
|
|
b9e861 |
FENCE_KDUMP_SEND="/usr/libexec/fence_kdump_send"
|
|
|
b9e861 |
FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled"
|
|
|
b9e861 |
|
|
|
b9e861 |
is_fadump_capable()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
# Check if firmware-assisted dump is enabled
|
|
|
b9e861 |
# if no, fallback to kdump check
|
|
|
b9e861 |
if [ -f $FADUMP_ENABLED_SYS_NODE ]; then
|
|
|
b9e861 |
rc=`cat $FADUMP_ENABLED_SYS_NODE`
|
|
|
b9e861 |
[ $rc -eq 1 ] && return 0
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
return 1
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
perror_exit() {
|
|
|
b9e861 |
echo $@ >&2
|
|
|
b9e861 |
exit 1
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
perror() {
|
|
|
b9e861 |
echo $@ >&2
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
is_ssh_dump_target()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
grep -q "^ssh[[:blank:]].*@" /etc/kdump.conf
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
is_nfs_dump_target()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
grep -q "^nfs" /etc/kdump.conf || \
|
|
|
b9e861 |
[[ $(get_dracut_args_fstype "$(grep "^dracut_args .*\-\-mount" /etc/kdump.conf)") = nfs* ]]
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
is_raw_dump_target()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
grep -q "^raw" /etc/kdump.conf
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
is_fs_type_nfs()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local _fstype=$1
|
|
|
b9e861 |
[ $_fstype = "nfs" ] || [ $_fstype = "nfs4" ] && return 0
|
|
|
b9e861 |
return 1
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
is_fs_dump_target()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
egrep -q "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
strip_comments()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
echo $@ | sed -e 's/\(.*\)#.*/\1/'
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# Read from kdump config file stripping all comments
|
|
|
b9e861 |
read_strip_comments()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
# strip heading spaces, and print any content starting with
|
|
|
b9e861 |
# neither space or #, and strip everything after #
|
|
|
b9e861 |
sed -n -e "s/^\s*\([^# \t][^#]\+\).*/\1/gp" $1
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# Check if fence kdump is configured in Pacemaker cluster
|
|
|
b9e861 |
is_pcs_fence_kdump()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
# no pcs or fence_kdump_send executables installed?
|
|
|
b9e861 |
type -P pcs > /dev/null || return 1
|
|
|
b9e861 |
[ -x $FENCE_KDUMP_SEND ] || return 1
|
|
|
b9e861 |
|
|
|
b9e861 |
# fence kdump not configured?
|
|
|
b9e861 |
(pcs cluster cib | grep 'type="fence_kdump"') &> /dev/null || return 1
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# Check if fence_kdump is configured using kdump options
|
|
|
b9e861 |
is_generic_fence_kdump()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
[ -x $FENCE_KDUMP_SEND ] || return 1
|
|
|
b9e861 |
|
|
|
b9e861 |
grep -q "^fence_kdump_nodes" /etc/kdump.conf
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
to_dev_name() {
|
|
|
b9e861 |
local dev="${1//\"/}"
|
|
|
b9e861 |
|
|
|
b9e861 |
case "$dev" in
|
|
|
b9e861 |
UUID=*)
|
|
|
b9e861 |
dev=`blkid -U "${dev#UUID=}"`
|
|
|
b9e861 |
;;
|
|
|
b9e861 |
LABEL=*)
|
|
|
b9e861 |
dev=`blkid -L "${dev#LABEL=}"`
|
|
|
b9e861 |
;;
|
|
|
b9e861 |
esac
|
|
|
b9e861 |
echo $dev
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
is_user_configured_dump_target()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
return $(is_mount_in_dracut_args || is_ssh_dump_target || is_nfs_dump_target || \
|
|
|
b9e861 |
is_raw_dump_target || is_fs_dump_target)
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
get_user_configured_dump_disk()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local _target
|
|
|
b9e861 |
|
|
|
b9e861 |
_target=$(egrep "^ext[234]|^xfs|^btrfs|^minix|^raw" /etc/kdump.conf 2>/dev/null |awk '{print $2}')
|
|
|
b9e861 |
[ -n "$_target" ] && echo $_target && return
|
|
|
b9e861 |
|
|
|
b9e861 |
_target=$(get_dracut_args_target "$(grep "^dracut_args .*\-\-mount" /etc/kdump.conf)")
|
|
|
b9e861 |
[ -b "$_target" ] && echo $_target
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
get_root_fs_device()
|
|
|
b9e861 |
{
|
|
|
399b37 |
findmnt -k -f -n -o SOURCE /
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
get_save_path()
|
|
|
b9e861 |
{
|
|
|
399b37 |
local _save_path=$(awk '$1 == "path" {print $2}' /etc/kdump.conf)
|
|
|
399b37 |
[ -z "$_save_path" ] && _save_path=$DEFAULT_PATH
|
|
|
b9e861 |
|
|
|
399b37 |
# strip the duplicated "/"
|
|
|
399b37 |
echo $_save_path | tr -s /
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
get_block_dump_target()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local _target _path
|
|
|
b9e861 |
|
|
|
b9e861 |
if is_ssh_dump_target || is_nfs_dump_target; then
|
|
|
b9e861 |
return
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
|
|
|
b9e861 |
_target=$(get_user_configured_dump_disk)
|
|
|
b9e861 |
[ -n "$_target" ] && echo $(to_dev_name $_target) && return
|
|
|
b9e861 |
|
|
|
b9e861 |
# Get block device name from local save path
|
|
|
b9e861 |
_path=$(get_save_path)
|
|
|
b9e861 |
_target=$(get_target_from_path $_path)
|
|
|
b9e861 |
[ -b "$_target" ] && echo $(to_dev_name $_target)
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
is_dump_to_rootfs()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
grep -E "^(failure_action|default)[[:space:]]dump_to_rootfs" /etc/kdump.conf >/dev/null
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
get_failure_action_target()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local _target
|
|
|
b9e861 |
|
|
|
b9e861 |
if is_dump_to_rootfs; then
|
|
|
b9e861 |
# Get rootfs device name
|
|
|
b9e861 |
_target=$(get_root_fs_device)
|
|
|
b9e861 |
[ -b "$_target" ] && echo $(to_dev_name $_target) && return
|
|
|
b9e861 |
# Then, must be nfs root
|
|
|
b9e861 |
echo "nfs"
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# Get kdump targets(including root in case of dump_to_rootfs).
|
|
|
b9e861 |
get_kdump_targets()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local _target _root
|
|
|
b9e861 |
local kdump_targets
|
|
|
b9e861 |
|
|
|
b9e861 |
_target=$(get_block_dump_target)
|
|
|
b9e861 |
if [ -n "$_target" ]; then
|
|
|
b9e861 |
kdump_targets=$_target
|
|
|
b9e861 |
elif is_ssh_dump_target; then
|
|
|
b9e861 |
kdump_targets="ssh"
|
|
|
b9e861 |
else
|
|
|
b9e861 |
kdump_targets="nfs"
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
|
|
|
b9e861 |
# Add the root device if dump_to_rootfs is specified.
|
|
|
b9e861 |
_root=$(get_failure_action_target)
|
|
|
b9e861 |
if [ -n "$_root" -a "$kdump_targets" != "$_root" ]; then
|
|
|
b9e861 |
kdump_targets="$kdump_targets $_root"
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
|
|
|
b9e861 |
echo "$kdump_targets"
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
399b37 |
# Return the bind mount source path, return the path itself if it's not bind mounted
|
|
|
399b37 |
# Eg. if /path/to/src is bind mounted to /mnt/bind, then:
|
|
|
399b37 |
# /mnt/bind -> /path/to/src, /mnt/bind/dump -> /path/to/src/dump
|
|
|
399b37 |
#
|
|
|
b9e861 |
# findmnt uses the option "-v, --nofsroot" to exclusive the [/dir]
|
|
|
b9e861 |
# in the SOURCE column for bind-mounts, then if $_mntpoint equals to
|
|
|
b9e861 |
# $_mntpoint_nofsroot, the mountpoint is not bind mounted directory.
|
|
|
399b37 |
#
|
|
|
b9e861 |
# Below is just an example for mount info
|
|
|
b9e861 |
# /dev/mapper/atomicos-root[/ostree/deploy/rhel-atomic-host/var], if the
|
|
|
b9e861 |
# directory is bind mounted. The former part represents the device path, rest
|
|
|
b9e861 |
# part is the bind mounted directory which quotes by bracket "[]".
|
|
|
399b37 |
get_bind_mount_source()
|
|
|
b9e861 |
{
|
|
|
399b37 |
local _path=$1
|
|
|
399b37 |
# In case it's a sub path in a mount point, get the mount point first
|
|
|
399b37 |
local _mnt_top=$(df $_path | tail -1 | awk '{print $NF}')
|
|
|
399b37 |
local _mntpoint=$(findmnt $_mnt_top | tail -n 1 | awk '{print $2}')
|
|
|
399b37 |
local _mntpoint_nofsroot=$(findmnt -v $_mnt_top | tail -n 1 | awk '{print $2}')
|
|
|
b9e861 |
|
|
|
399b37 |
if [[ "$_mntpoint" = $_mntpoint_nofsroot ]]; then
|
|
|
399b37 |
echo $_path && return
|
|
|
399b37 |
fi
|
|
|
b9e861 |
|
|
|
399b37 |
_mntpoint=${_mntpoint#*$_mntpoint_nofsroot}
|
|
|
b9e861 |
_mntpoint=${_mntpoint#[}
|
|
|
b9e861 |
_mntpoint=${_mntpoint%]}
|
|
|
399b37 |
_path=${_path#$_mnt_top}
|
|
|
b9e861 |
|
|
|
399b37 |
echo $_mntpoint$_path
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
399b37 |
# Return the current underlaying device of a path, ignore bind mounts
|
|
|
b9e861 |
get_target_from_path()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local _target
|
|
|
b9e861 |
|
|
|
b9e861 |
_target=$(df $1 2>/dev/null | tail -1 | awk '{print $1}')
|
|
|
b9e861 |
[[ "$_target" == "/dev/root" ]] && [[ ! -e /dev/root ]] && _target=$(get_root_fs_device)
|
|
|
b9e861 |
echo $_target
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
399b37 |
is_mounted()
|
|
|
b9e861 |
{
|
|
|
399b37 |
findmnt -k -n $1 &>/dev/null
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
399b37 |
get_mount_info()
|
|
|
b9e861 |
{
|
|
|
399b37 |
local _info_type=$1 _src_type=$2 _src=$3; shift 3
|
|
|
399b37 |
local _info=$(findmnt -k -n -r -o $_info_type --$_src_type $_src $@)
|
|
|
b9e861 |
|
|
|
399b37 |
[ -z "$_info" ] && [ -e "/etc/fstab" ] && _info=$(findmnt -s -n -r -o $_info_type --$_src_type $_src $@)
|
|
|
399b37 |
|
|
|
399b37 |
echo $_info
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
399b37 |
get_fs_type_from_target()
|
|
|
b9e861 |
{
|
|
|
399b37 |
get_mount_info FSTYPE source $1 -f
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
399b37 |
get_mntopt_from_target()
|
|
|
b9e861 |
{
|
|
|
399b37 |
get_mount_info OPTIONS source $1 -f
|
|
|
399b37 |
}
|
|
|
399b37 |
# Find the general mount point of a dump target, not the bind mount point
|
|
|
399b37 |
get_mntpoint_from_target()
|
|
|
399b37 |
{
|
|
|
399b37 |
# Expcilitly specify --source to findmnt could ensure non-bind mount is returned
|
|
|
399b37 |
get_mount_info TARGET source $1 -f
|
|
|
399b37 |
}
|
|
|
b9e861 |
|
|
|
399b37 |
# Get the path where the target will be mounted in kdump kernel
|
|
|
399b37 |
# $1: kdump target device
|
|
|
399b37 |
get_kdump_mntpoint_from_target()
|
|
|
399b37 |
{
|
|
|
399b37 |
local _mntpoint=$(get_mntpoint_from_target $1)
|
|
|
399b37 |
|
|
|
399b37 |
# mount under /sysroot if dump to root disk or mount under
|
|
|
399b37 |
# mount under /kdumproot if dump target is not mounted in first kernel
|
|
|
399b37 |
# mount under /kdumproot/$_mntpoint in other cases in 2nd kernel.
|
|
|
399b37 |
# systemd will be in charge to umount it.
|
|
|
399b37 |
if [ -z "$_mntpoint" ];then
|
|
|
399b37 |
_mntpoint="/kdumproot"
|
|
|
399b37 |
else
|
|
|
399b37 |
if [ "$_mntpoint" = "/" ];then
|
|
|
399b37 |
_mntpoint="/sysroot"
|
|
|
399b37 |
else
|
|
|
399b37 |
_mntpoint="/kdumproot/$_mntpoint"
|
|
|
399b37 |
fi
|
|
|
b9e861 |
fi
|
|
|
399b37 |
|
|
|
399b37 |
# strip duplicated "/"
|
|
|
399b37 |
echo $_mntpoint | tr -s "/"
|
|
|
399b37 |
}
|
|
|
399b37 |
|
|
|
399b37 |
# get_option_value <option_name>
|
|
|
399b37 |
# retrieves value of option defined in kdump.conf
|
|
|
399b37 |
get_option_value() {
|
|
|
399b37 |
strip_comments `grep "^$1[[:space:]]\+" /etc/kdump.conf | tail -1 | cut -d\ -f2-`
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
a6b1d2 |
kdump_get_persistent_dev() {
|
|
|
a6b1d2 |
local dev="${1//\"/}"
|
|
|
a6b1d2 |
|
|
|
a6b1d2 |
case "$dev" in
|
|
|
a6b1d2 |
UUID=*)
|
|
|
a6b1d2 |
dev=`blkid -U "${dev#UUID=}"`
|
|
|
a6b1d2 |
;;
|
|
|
a6b1d2 |
LABEL=*)
|
|
|
a6b1d2 |
dev=`blkid -L "${dev#LABEL=}"`
|
|
|
a6b1d2 |
;;
|
|
|
a6b1d2 |
esac
|
|
|
a6b1d2 |
echo $(get_persistent_dev "$dev")
|
|
|
a6b1d2 |
}
|
|
|
a6b1d2 |
|
|
|
b9e861 |
is_atomic()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
grep -q "ostree" /proc/cmdline
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# fixme, try the best to decide whether the ipv6 addr is allocated by slaac or dhcp6
|
|
|
b9e861 |
is_ipv6_auto()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local _netdev=$1
|
|
|
b9e861 |
local _auto=$(cat /proc/sys/net/ipv6/conf/$_netdev/autoconf)
|
|
|
b9e861 |
if [ $_auto -eq 1 ]; then
|
|
|
b9e861 |
return 0
|
|
|
b9e861 |
else
|
|
|
b9e861 |
return 1
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
is_ipv6_address()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
echo $1 | grep -q ":"
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# get ip address or hostname from nfs/ssh config value
|
|
|
b9e861 |
get_remote_host()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local _config_val=$1
|
|
|
b9e861 |
|
|
|
b9e861 |
# ipv6 address in kdump.conf is around with "[]",
|
|
|
b9e861 |
# factor out the ipv6 address
|
|
|
b9e861 |
_config_val=${_config_val#*@}
|
|
|
b9e861 |
_config_val=${_config_val%:/*}
|
|
|
b9e861 |
_config_val=${_config_val#[}
|
|
|
b9e861 |
_config_val=${_config_val%]}
|
|
|
b9e861 |
echo $_config_val
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
is_hostname()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local _hostname=`echo $1 | grep ":"`
|
|
|
b9e861 |
|
|
|
b9e861 |
if [ -n "$_hostname" ]; then
|
|
|
b9e861 |
return 1
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
echo $1 | grep -q "[a-zA-Z]"
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# Copied from "/etc/sysconfig/network-scripts/network-functions"
|
|
|
b9e861 |
get_hwaddr()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
if [ -f "/sys/class/net/${1}/address" ]; then
|
|
|
b9e861 |
awk '{ print toupper($0) }' < /sys/class/net/${1}/address
|
|
|
b9e861 |
elif [ -d "/sys/class/net/${1}" ]; then
|
|
|
b9e861 |
LC_ALL= LANG= ip -o link show ${1} 2>/dev/null | \
|
|
|
b9e861 |
awk '{ print toupper(gensub(/.*link\/[^ ]* ([[:alnum:]:]*).*/,
|
|
|
b9e861 |
"\\1", 1)); }'
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
get_ifcfg_by_device()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
grep -E -i -l "^[[:space:]]*DEVICE=\"*${1}\"*[[:space:]]*$" \
|
|
|
b9e861 |
/etc/sysconfig/network-scripts/ifcfg-* 2>/dev/null | head -1
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
get_ifcfg_by_hwaddr()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
grep -E -i -l "^[[:space:]]*HWADDR=\"*${1}\"*[[:space:]]*$" \
|
|
|
b9e861 |
/etc/sysconfig/network-scripts/ifcfg-* 2>/dev/null | head -1
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
get_ifcfg_by_uuid()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
grep -E -i -l "^[[:space:]]*UUID=\"*${1}\"*[[:space:]]*$" \
|
|
|
b9e861 |
/etc/sysconfig/network-scripts/ifcfg-* 2>/dev/null | head -1
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
get_ifcfg_by_name()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
grep -E -i -l "^[[:space:]]*NAME=\"*${1}\"*[[:space:]]*$" \
|
|
|
b9e861 |
/etc/sysconfig/network-scripts/ifcfg-* 2>/dev/null | head -1
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
is_nm_running()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
[ "$(LANG=C nmcli -t --fields running general status 2>/dev/null)" = "running" ]
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
is_nm_handling()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
LANG=C nmcli -t --fields device,state dev status 2>/dev/null \
|
|
|
b9e861 |
| grep -q "^\(${1}:connected\)\|\(${1}:connecting.*\)$"
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# $1: netdev name
|
|
|
b9e861 |
get_ifcfg_nmcli()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local nm_uuid nm_name
|
|
|
b9e861 |
local ifcfg_file
|
|
|
b9e861 |
|
|
|
b9e861 |
# Get the active nmcli config name of $1
|
|
|
b9e861 |
if is_nm_running && is_nm_handling "${1}" ; then
|
|
|
b9e861 |
# The configuration "uuid" and "name" generated by nm is wrote to
|
|
|
b9e861 |
# the ifcfg file as "UUID=<nm_uuid>" and "NAME=<nm_name>".
|
|
|
b9e861 |
nm_uuid=$(LANG=C nmcli -t --fields uuid,device c show --active 2>/dev/null \
|
|
|
b9e861 |
| grep "${1}" | head -1 | cut -d':' -f1)
|
|
|
b9e861 |
nm_name=$(LANG=C nmcli -t --fields name,device c show --active 2>/dev/null \
|
|
|
b9e861 |
| grep "${1}" | head -1 | cut -d':' -f1)
|
|
|
b9e861 |
ifcfg_file=$(get_ifcfg_by_uuid "${nm_uuid}")
|
|
|
b9e861 |
[ -z "${ifcfg_file}" ] && ifcfg_file=$(get_ifcfg_by_name "${nm_name}")
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
|
|
|
b9e861 |
echo -n "${ifcfg_file}"
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# $1: netdev name
|
|
|
b9e861 |
get_ifcfg_legacy()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local ifcfg_file
|
|
|
b9e861 |
|
|
|
b9e861 |
ifcfg_file="/etc/sysconfig/network-scripts/ifcfg-${1}"
|
|
|
b9e861 |
[ -f "${ifcfg_file}" ] && echo -n "${ifcfg_file}" && return
|
|
|
b9e861 |
|
|
|
b9e861 |
ifcfg_file=$(get_ifcfg_by_name "${1}")
|
|
|
b9e861 |
[ -f "${ifcfg_file}" ] && echo -n "${ifcfg_file}" && return
|
|
|
b9e861 |
|
|
|
b9e861 |
local hwaddr=$(get_hwaddr "${1}")
|
|
|
b9e861 |
if [ -n "$hwaddr" ]; then
|
|
|
b9e861 |
ifcfg_file=$(get_ifcfg_by_hwaddr "${hwaddr}")
|
|
|
b9e861 |
[ -f "${ifcfg_file}" ] && echo -n "${ifcfg_file}" && return
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
|
|
|
b9e861 |
ifcfg_file=$(get_ifcfg_by_device "${1}")
|
|
|
b9e861 |
|
|
|
b9e861 |
echo -n "${ifcfg_file}"
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# $1: netdev name
|
|
|
b9e861 |
# Return the ifcfg file whole name(including the path) of $1 if any.
|
|
|
b9e861 |
get_ifcfg_filename() {
|
|
|
b9e861 |
local ifcfg_file
|
|
|
b9e861 |
|
|
|
b9e861 |
ifcfg_file=$(get_ifcfg_nmcli "${1}")
|
|
|
b9e861 |
if [ -z "${ifcfg_file}" ]; then
|
|
|
b9e861 |
ifcfg_file=$(get_ifcfg_legacy "${1}")
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
|
|
|
b9e861 |
echo -n "${ifcfg_file}"
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# returns 0 when omission of watchdog module is desired in dracut_args
|
|
|
b9e861 |
# returns 1 otherwise
|
|
|
b9e861 |
is_wdt_mod_omitted() {
|
|
|
b9e861 |
local dracut_args
|
|
|
b9e861 |
local ret=1
|
|
|
b9e861 |
|
|
|
b9e861 |
dracut_args=$(grep "^dracut_args" /etc/kdump.conf)
|
|
|
b9e861 |
[[ -z $dracut_args ]] && return $ret
|
|
|
b9e861 |
|
|
|
b9e861 |
eval set -- $dracut_args
|
|
|
b9e861 |
while :; do
|
|
|
b9e861 |
[[ -z $1 ]] && break
|
|
|
b9e861 |
case $1 in
|
|
|
b9e861 |
-o|--omit)
|
|
|
b9e861 |
echo $2 | grep -qw "watchdog"
|
|
|
b9e861 |
[[ $? == 0 ]] && ret=0
|
|
|
b9e861 |
break
|
|
|
b9e861 |
esac
|
|
|
b9e861 |
shift
|
|
|
b9e861 |
done
|
|
|
b9e861 |
|
|
|
b9e861 |
return $ret
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# If "dracut_args" contains "--mount" information, use it
|
|
|
b9e861 |
# directly without any check(users are expected to ensure
|
|
|
b9e861 |
# its correctness).
|
|
|
b9e861 |
is_mount_in_dracut_args()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
grep -q "^dracut_args .*\-\-mount" /etc/kdump.conf
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# If $1 contains dracut_args "--mount", return <filesystem type>
|
|
|
b9e861 |
get_dracut_args_fstype()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f3
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# If $1 contains dracut_args "--mount", return <device>
|
|
|
b9e861 |
get_dracut_args_target()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f1
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
check_crash_mem_reserved()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local mem_reserved
|
|
|
b9e861 |
|
|
|
b9e861 |
mem_reserved=$(cat /sys/kernel/kexec_crash_size)
|
|
|
b9e861 |
if [ $mem_reserved -eq 0 ]; then
|
|
|
b9e861 |
echo "No memory reserved for crash kernel"
|
|
|
b9e861 |
return 1
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
|
|
|
b9e861 |
return 0
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
check_kdump_feasibility()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
if [ ! -e /sys/kernel/kexec_crash_loaded ]; then
|
|
|
b9e861 |
echo "Kdump is not supported on this kernel"
|
|
|
b9e861 |
return 1
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
check_crash_mem_reserved
|
|
|
b9e861 |
return $?
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
check_current_kdump_status()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
if [ ! -f /sys/kernel/kexec_crash_loaded ];then
|
|
|
b9e861 |
echo "Perhaps CONFIG_CRASH_DUMP is not enabled in kernel"
|
|
|
b9e861 |
return 1
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
|
|
|
b9e861 |
rc=`cat /sys/kernel/kexec_crash_loaded`
|
|
|
b9e861 |
if [ $rc == 1 ]; then
|
|
|
b9e861 |
return 0
|
|
|
b9e861 |
else
|
|
|
b9e861 |
return 1
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# remove_cmdline_param <kernel cmdline> <param1> [<param2>] ... [<paramN>]
|
|
|
b9e861 |
# Remove a list of kernel parameters from a given kernel cmdline and print the result.
|
|
|
b9e861 |
# For each "arg" in the removing params list, "arg" and "arg=xxx" will be removed if exists.
|
|
|
b9e861 |
remove_cmdline_param()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local cmdline=$1
|
|
|
b9e861 |
shift
|
|
|
b9e861 |
|
|
|
b9e861 |
for arg in $@; do
|
|
|
b9e861 |
cmdline=`echo $cmdline | \
|
|
|
b9e861 |
sed -e "s/\b$arg=[^ ]*//g" \
|
|
|
b9e861 |
-e "s/^$arg\b//g" \
|
|
|
b9e861 |
-e "s/[[:space:]]$arg\b//g" \
|
|
|
b9e861 |
-e "s/\s\+/ /g"`
|
|
|
b9e861 |
done
|
|
|
b9e861 |
echo $cmdline
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
#
|
|
|
b9e861 |
# This function returns the "apicid" of the boot
|
|
|
b9e861 |
# cpu (cpu 0) if present.
|
|
|
b9e861 |
#
|
|
|
b9e861 |
get_bootcpu_apicid()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
awk ' \
|
|
|
b9e861 |
BEGIN { CPU = "-1"; } \
|
|
|
b9e861 |
$1=="processor" && $2==":" { CPU = $NF; } \
|
|
|
b9e861 |
CPU=="0" && /^apicid/ { print $NF; } \
|
|
|
b9e861 |
' \
|
|
|
b9e861 |
/proc/cpuinfo
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
#
|
|
|
b9e861 |
# append_cmdline <kernel cmdline> <parameter name> <parameter value>
|
|
|
b9e861 |
# This function appends argument "$2=$3" to string ($1) if not already present.
|
|
|
b9e861 |
#
|
|
|
b9e861 |
append_cmdline()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local cmdline=$1
|
|
|
b9e861 |
local newstr=${cmdline/$2/""}
|
|
|
b9e861 |
|
|
|
b9e861 |
# unchanged str implies argument wasn't there
|
|
|
b9e861 |
if [ "$cmdline" == "$newstr" ]; then
|
|
|
b9e861 |
cmdline="${cmdline} ${2}=${3}"
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
|
|
|
b9e861 |
echo $cmdline
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
# This function check iomem and determines if we have more than
|
|
|
b9e861 |
# 4GB of ram available. Returns 1 if we do, 0 if we dont
|
|
|
b9e861 |
need_64bit_headers()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
return `tail -n 1 /proc/iomem | awk '{ split ($1, r, "-"); \
|
|
|
b9e861 |
print (strtonum("0x" r[2]) > strtonum("0xffffffff")); }'`
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
e7b8b8 |
# Check if secure boot is being enforced.
|
|
|
e7b8b8 |
#
|
|
|
e7b8b8 |
# Per Peter Jones, we need check efivar SecureBoot-$(the UUID) and
|
|
|
e7b8b8 |
# SetupMode-$(the UUID), they are both 5 bytes binary data. The first four
|
|
|
e7b8b8 |
# bytes are the attributes associated with the variable and can safely be
|
|
|
e7b8b8 |
# ignored, the last bytes are one-byte true-or-false variables. If SecureBoot
|
|
|
e7b8b8 |
# is 1 and SetupMode is 0, then secure boot is being enforced.
|
|
|
e7b8b8 |
#
|
|
|
e7b8b8 |
# Assume efivars is mounted at /sys/firmware/efi/efivars.
|
|
|
e7b8b8 |
is_secure_boot_enforced()
|
|
|
e7b8b8 |
{
|
|
|
e7b8b8 |
local secure_boot_file setup_mode_file
|
|
|
e7b8b8 |
local secure_boot_byte setup_mode_byte
|
|
|
e7b8b8 |
|
|
|
e7b8b8 |
# On powerpc, os-secureboot-enforcing DT property indicates whether secureboot
|
|
|
e7b8b8 |
# is enforced. Return success, if it is found.
|
|
|
e7b8b8 |
if [ -f /proc/device-tree/ibm,secureboot/os-secureboot-enforcing ]; then
|
|
|
e7b8b8 |
return 0
|
|
|
e7b8b8 |
fi
|
|
|
e7b8b8 |
|
|
|
e7b8b8 |
secure_boot_file=$(find /sys/firmware/efi/efivars -name SecureBoot-* 2>/dev/null)
|
|
|
e7b8b8 |
setup_mode_file=$(find /sys/firmware/efi/efivars -name SetupMode-* 2>/dev/null)
|
|
|
e7b8b8 |
|
|
|
e7b8b8 |
if [ -f "$secure_boot_file" ] && [ -f "$setup_mode_file" ]; then
|
|
|
e7b8b8 |
secure_boot_byte=$(hexdump -v -e '/1 "%d\ "' $secure_boot_file|cut -d' ' -f 5)
|
|
|
e7b8b8 |
setup_mode_byte=$(hexdump -v -e '/1 "%d\ "' $setup_mode_file|cut -d' ' -f 5)
|
|
|
e7b8b8 |
|
|
|
e7b8b8 |
if [ "$secure_boot_byte" = "1" ] && [ "$setup_mode_byte" = "0" ]; then
|
|
|
e7b8b8 |
return 0
|
|
|
e7b8b8 |
fi
|
|
|
e7b8b8 |
fi
|
|
|
e7b8b8 |
|
|
|
e7b8b8 |
return 1
|
|
|
e7b8b8 |
}
|
|
|
e7b8b8 |
|
|
|
b9e861 |
#
|
|
|
b9e861 |
# prepare_kexec_args <kexec args>
|
|
|
b9e861 |
# This function prepares kexec argument.
|
|
|
b9e861 |
#
|
|
|
b9e861 |
prepare_kexec_args()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local kexec_args=$1
|
|
|
b9e861 |
local found_elf_args
|
|
|
b9e861 |
|
|
|
b9e861 |
ARCH=`uname -m`
|
|
|
b9e861 |
if [ "$ARCH" == "i686" -o "$ARCH" == "i386" ]
|
|
|
b9e861 |
then
|
|
|
b9e861 |
need_64bit_headers
|
|
|
b9e861 |
if [ $? == 1 ]
|
|
|
b9e861 |
then
|
|
|
b9e861 |
found_elf_args=`echo $kexec_args | grep elf32-core-headers`
|
|
|
b9e861 |
if [ -n "$found_elf_args" ]
|
|
|
b9e861 |
then
|
|
|
b9e861 |
echo -n "Warning: elf32-core-headers overrides correct elf64 setting"
|
|
|
b9e861 |
echo
|
|
|
b9e861 |
else
|
|
|
b9e861 |
kexec_args="$kexec_args --elf64-core-headers"
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
else
|
|
|
b9e861 |
found_elf_args=`echo $kexec_args | grep elf64-core-headers`
|
|
|
b9e861 |
if [ -z "$found_elf_args" ]
|
|
|
b9e861 |
then
|
|
|
b9e861 |
kexec_args="$kexec_args --elf32-core-headers"
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
echo $kexec_args
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
check_boot_dir()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local kdump_bootdir=$1
|
|
|
b9e861 |
#If user specify a boot dir for kdump kernel, let's use it. Otherwise
|
|
|
b9e861 |
#check whether it's a atomic host. If yes parse the subdirectory under
|
|
|
b9e861 |
#/boot; If not just find it under /boot.
|
|
|
b9e861 |
if [ -n "$kdump_bootdir" ]; then
|
|
|
b9e861 |
echo "$kdump_bootdir"
|
|
|
b9e861 |
return
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
|
|
|
b9e861 |
if ! is_atomic || [ "$(uname -m)" = "s390x" ]; then
|
|
|
b9e861 |
kdump_bootdir="/boot"
|
|
|
b9e861 |
else
|
|
|
b9e861 |
eval $(cat /proc/cmdline| grep "BOOT_IMAGE" | cut -d' ' -f1)
|
|
|
b9e861 |
kdump_bootdir="/boot"$(dirname $BOOT_IMAGE)
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
echo $kdump_bootdir
|
|
|
b9e861 |
}
|
|
|
b9e861 |
|
|
|
b9e861 |
#
|
|
|
b9e861 |
# prepare_cmdline <commandline> <commandline remove> <commandline append>
|
|
|
b9e861 |
# This function performs a series of edits on the command line.
|
|
|
b9e861 |
# Store the final result in global $KDUMP_COMMANDLINE.
|
|
|
b9e861 |
prepare_cmdline()
|
|
|
b9e861 |
{
|
|
|
b9e861 |
local cmdline id
|
|
|
b9e861 |
|
|
|
b9e861 |
if [ -z "$1" ]; then
|
|
|
b9e861 |
cmdline=$(cat /proc/cmdline)
|
|
|
b9e861 |
else
|
|
|
b9e861 |
cmdline="$1"
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
|
|
|
b9e861 |
# These params should always be removed
|
|
|
b9e861 |
cmdline=$(remove_cmdline_param "$cmdline" crashkernel panic_on_warn)
|
|
|
b9e861 |
# These params can be removed configurably
|
|
|
b9e861 |
cmdline=$(remove_cmdline_param "$cmdline" "$2")
|
|
|
b9e861 |
|
|
|
b9e861 |
# Always remove "root=X", as we now explicitly generate all kinds
|
|
|
b9e861 |
# of dump target mount information including root fs.
|
|
|
b9e861 |
#
|
|
|
b9e861 |
# We do this before KDUMP_COMMANDLINE_APPEND, if one really cares
|
|
|
b9e861 |
# about it(e.g. for debug purpose), then can pass "root=X" using
|
|
|
b9e861 |
# KDUMP_COMMANDLINE_APPEND.
|
|
|
b9e861 |
cmdline=$(remove_cmdline_param "$cmdline" root)
|
|
|
b9e861 |
|
|
|
b9e861 |
# With the help of "--hostonly-cmdline", we can avoid some interitage.
|
|
|
b9e861 |
cmdline=$(remove_cmdline_param "$cmdline" rd.lvm.lv rd.luks.uuid rd.dm.uuid rd.md.uuid fcoe)
|
|
|
b9e861 |
|
|
|
b9e861 |
# Remove netroot, rd.iscsi.initiator and iscsi_initiator since
|
|
|
b9e861 |
# we get duplicate entries for the same in case iscsi code adds
|
|
|
b9e861 |
# it as well.
|
|
|
b9e861 |
cmdline=$(remove_cmdline_param "$cmdline" netroot rd.iscsi.initiator iscsi_initiator)
|
|
|
b9e861 |
|
|
|
b9e861 |
cmdline="${cmdline} $3"
|
|
|
b9e861 |
|
|
|
b9e861 |
id=$(get_bootcpu_apicid)
|
|
|
b9e861 |
if [ ! -z ${id} ] ; then
|
|
|
b9e861 |
cmdline=$(append_cmdline "${cmdline}" disable_cpu_apicid ${id})
|
|
|
b9e861 |
fi
|
|
|
b9e861 |
echo ${cmdline}
|
|
|
b9e861 |
}
|