|
|
35519c |
#!/bin/sh
|
|
|
35519c |
#
|
|
|
050f80 |
# The code in this file will be used in initramfs environment, bash may
|
|
|
050f80 |
# not be the default shell. Any code added must be POSIX compliant.
|
|
Petr Šabata |
f5bf49 |
|
|
|
35519c |
DEFAULT_PATH="/var/crash/"
|
|
|
35519c |
KDUMP_CONFIG_FILE="/etc/kdump.conf"
|
|
Petr Šabata |
f5bf49 |
|
|
|
35519c |
# Read kdump config in well formated style
|
|
|
35519c |
kdump_read_conf()
|
|
|
35519c |
{
|
|
|
57daeb |
# Following steps are applied in order: strip trailing comment, strip trailing space,
|
|
|
57daeb |
# strip heading space, match non-empty line, remove duplicated spaces between conf name and value
|
|
|
57daeb |
[ -f "$KDUMP_CONFIG_FILE" ] && sed -n -e "s/#.*//;s/\s*$//;s/^\s*//;s/\(\S\+\)\s*\(.*\)/\1 \2/p" $KDUMP_CONFIG_FILE
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
35519c |
# Retrieves config value defined in kdump.conf
|
|
|
35519c |
# $1: config name, sed regexp compatible
|
|
|
57daeb |
kdump_get_conf_val()
|
|
|
57daeb |
{
|
|
|
57daeb |
# For lines matching "^\s*$1\s+", remove matched part (config name including space),
|
|
|
57daeb |
# remove tailing comment, space, then store in hold space. Print out the hold buffer on last line.
|
|
|
57daeb |
[ -f "$KDUMP_CONFIG_FILE" ] &&
|
|
|
57daeb |
sed -n -e "/^\s*\($1\)\s\+/{s/^\s*\($1\)\s\+//;s/#.*//;s/\s*$//;h};\${x;p}" $KDUMP_CONFIG_FILE
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
35519c |
is_mounted()
|
|
|
35519c |
{
|
|
|
57daeb |
findmnt -k -n "$1" > /dev/null 2>&1
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
57daeb |
# $1: info type
|
|
|
57daeb |
# $2: mount source type
|
|
|
57daeb |
# $3: mount source
|
|
|
57daeb |
# $4: extra args
|
|
|
35519c |
get_mount_info()
|
|
|
35519c |
{
|
|
|
57daeb |
__kdump_mnt=$(findmnt -k -n -r -o "$1" "--$2" "$3" $4)
|
|
|
35519c |
|
|
|
57daeb |
[ -z "$__kdump_mnt" ] && [ -e "/etc/fstab" ] && __kdump_mnt=$(findmnt -s -n -r -o "$1" "--$2" "$3" $4)
|
|
|
35519c |
|
|
|
57daeb |
echo "$__kdump_mnt"
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
35519c |
is_ipv6_address()
|
|
|
35519c |
{
|
|
|
57daeb |
echo "$1" | grep -q ":"
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
35519c |
is_fs_type_nfs()
|
|
|
35519c |
{
|
|
|
57daeb |
[ "$1" = "nfs" ] || [ "$1" = "nfs4" ]
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
35519c |
# If $1 contains dracut_args "--mount", return <filesystem type>
|
|
|
35519c |
get_dracut_args_fstype()
|
|
|
35519c |
{
|
|
|
57daeb |
echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f3
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
35519c |
# If $1 contains dracut_args "--mount", return <device>
|
|
|
35519c |
get_dracut_args_target()
|
|
|
35519c |
{
|
|
|
57daeb |
echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f1
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
35519c |
get_save_path()
|
|
|
35519c |
{
|
|
|
57daeb |
__kdump_path=$(kdump_get_conf_val path)
|
|
|
57daeb |
[ -z "$__kdump_path" ] && __kdump_path=$DEFAULT_PATH
|
|
|
35519c |
|
|
|
57daeb |
# strip the duplicated "/"
|
|
|
57daeb |
echo "$__kdump_path" | tr -s /
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
35519c |
get_root_fs_device()
|
|
|
35519c |
{
|
|
|
57daeb |
findmnt -k -f -n -o SOURCE /
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
35519c |
# Return the current underlying device of a path, ignore bind mounts
|
|
|
35519c |
get_target_from_path()
|
|
|
35519c |
{
|
|
|
57daeb |
__kdump_target=$(df "$1" 2> /dev/null | tail -1 | awk '{print $1}')
|
|
|
57daeb |
[ "$__kdump_target" = "/dev/root" ] && [ ! -e /dev/root ] && __kdump_target=$(get_root_fs_device)
|
|
|
57daeb |
echo "$__kdump_target"
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
35519c |
get_fs_type_from_target()
|
|
|
35519c |
{
|
|
|
57daeb |
get_mount_info FSTYPE source "$1" -f
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
35519c |
get_mntpoint_from_target()
|
|
|
35519c |
{
|
|
|
57daeb |
# --source is applied to ensure non-bind mount is returned
|
|
|
57daeb |
get_mount_info TARGET source "$1" -f
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
35519c |
is_ssh_dump_target()
|
|
|
35519c |
{
|
|
|
57daeb |
kdump_get_conf_val ssh | grep -q @
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
35519c |
is_raw_dump_target()
|
|
|
35519c |
{
|
|
|
57daeb |
[ -n "$(kdump_get_conf_val raw)" ]
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
35519c |
is_nfs_dump_target()
|
|
|
35519c |
{
|
|
|
57daeb |
if [ -n "$(kdump_get_conf_val nfs)" ]; then
|
|
|
57daeb |
return 0
|
|
|
57daeb |
fi
|
|
|
35519c |
|
|
|
57daeb |
if is_fs_type_nfs "$(get_dracut_args_fstype "$(kdump_get_conf_val dracut_args)")"; then
|
|
|
57daeb |
return 0
|
|
|
57daeb |
fi
|
|
|
35519c |
|
|
|
57daeb |
if is_fs_type_nfs "$(get_fs_type_from_target "$(get_target_from_path "$(get_save_path)")")"; then
|
|
|
57daeb |
return 0
|
|
|
57daeb |
fi
|
|
|
35519c |
|
|
|
57daeb |
return 1
|
|
|
35519c |
}
|
|
|
35519c |
|
|
|
35519c |
is_fs_dump_target()
|
|
|
35519c |
{
|
|
|
57daeb |
[ -n "$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix")" ]
|
|
|
35519c |
}
|