|
Petr Šabata |
f5bf49 |
#!/bin/bash --norc
|
|
Petr Šabata |
f5bf49 |
# New mkdumprd
|
|
Petr Šabata |
f5bf49 |
#
|
|
Petr Šabata |
f5bf49 |
# Copyright 2011 Red Hat, Inc.
|
|
Petr Šabata |
f5bf49 |
#
|
|
Petr Šabata |
f5bf49 |
# Written by Cong Wang <amwang@redhat.com>
|
|
Petr Šabata |
f5bf49 |
#
|
|
Petr Šabata |
f5bf49 |
|
|
DistroBaker |
5cac7c |
if [ -f /etc/sysconfig/kdump ]; then
|
|
DistroBaker |
5cac7c |
. /etc/sysconfig/kdump
|
|
DistroBaker |
5cac7c |
fi
|
|
DistroBaker |
5cac7c |
|
|
Petr Šabata |
f5bf49 |
[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
|
|
Petr Šabata |
f5bf49 |
. $dracutbasedir/dracut-functions.sh
|
|
Petr Šabata |
f5bf49 |
. /lib/kdump/kdump-lib.sh
|
|
DistroBaker |
624a64 |
. /lib/kdump/kdump-logger.sh
|
|
Petr Šabata |
f5bf49 |
export IN_KDUMP=1
|
|
Petr Šabata |
f5bf49 |
|
|
DistroBaker |
5cac7c |
#initiate the kdump logger
|
|
DistroBaker |
5cac7c |
dlog_init
|
|
DistroBaker |
5cac7c |
if [ $? -ne 0 ]; then
|
|
DistroBaker |
5cac7c |
echo "failed to initiate the kdump logger."
|
|
DistroBaker |
5cac7c |
exit 1
|
|
DistroBaker |
5cac7c |
fi
|
|
DistroBaker |
5cac7c |
|
|
Petr Šabata |
f5bf49 |
conf_file="/etc/kdump.conf"
|
|
Petr Šabata |
f5bf49 |
SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
|
|
Petr Šabata |
f5bf49 |
SAVE_PATH=$(get_save_path)
|
|
Petr Šabata |
f5bf49 |
OVERRIDE_RESETTABLE=0
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
extra_modules=""
|
|
DistroBaker |
5cac7c |
dracut_args="--add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o \"plymouth dash resume ifcfg earlykdump\""
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
readonly MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)"
|
|
Petr Šabata |
f5bf49 |
[ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t dracut.XXXXXX failed."
|
|
Petr Šabata |
f5bf49 |
readonly MKDUMPRD_TMPMNT="$MKDUMPRD_TMPDIR/target"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
trap '
|
|
Petr Šabata |
f5bf49 |
ret=$?;
|
|
Petr Šabata |
f5bf49 |
is_mounted $MKDUMPRD_TMPMNT && umount -f $MKDUMPRD_TMPMNT;
|
|
Petr Šabata |
f5bf49 |
[[ -d $MKDUMPRD_TMPDIR ]] && rm --one-file-system -rf -- "$MKDUMPRD_TMPDIR";
|
|
Petr Šabata |
f5bf49 |
exit $ret;
|
|
Petr Šabata |
f5bf49 |
' EXIT
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# clean up after ourselves no matter how we die.
|
|
Petr Šabata |
f5bf49 |
trap 'exit 1;' SIGINT
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
add_dracut_arg() {
|
|
Petr Šabata |
f5bf49 |
dracut_args="$dracut_args $@"
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
add_dracut_mount() {
|
|
Petr Šabata |
f5bf49 |
add_dracut_arg "--mount" "\"$1\""
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
add_dracut_sshkey() {
|
|
Petr Šabata |
f5bf49 |
add_dracut_arg "--sshkey" "\"$1\""
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# caller should ensure $1 is valid and mounted in 1st kernel
|
|
Petr Šabata |
f5bf49 |
to_mount() {
|
|
Petr Šabata |
f5bf49 |
local _target=$1 _fstype=$2 _options=$3 _new_mntpoint _pdev
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
_new_mntpoint=$(get_kdump_mntpoint_from_target $_target)
|
|
Petr Šabata |
f5bf49 |
_fstype="${_fstype:-$(get_fs_type_from_target $_target)}"
|
|
Petr Šabata |
f5bf49 |
_options="${_options:-$(get_mntopt_from_target $_target)}"
|
|
Petr Šabata |
f5bf49 |
_options="${_options:-defaults}"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [[ "$_fstype" == "nfs"* ]]; then
|
|
Petr Šabata |
f5bf49 |
_pdev=$_target
|
|
Petr Šabata |
f5bf49 |
_options=$(echo $_options | sed 's/,addr=[^,]*//')
|
|
Petr Šabata |
f5bf49 |
_options=$(echo $_options | sed 's/,proto=[^,]*//')
|
|
Petr Šabata |
f5bf49 |
_options=$(echo $_options | sed 's/,clientaddr=[^,]*//')
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
# for non-nfs _target converting to use udev persistent name
|
|
Petr Šabata |
f5bf49 |
_pdev="$(kdump_get_persistent_dev $_target)"
|
|
Petr Šabata |
f5bf49 |
if [ -z "$_pdev" ]; then
|
|
Petr Šabata |
f5bf49 |
return 1
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# mount fs target as rw in 2nd kernel
|
|
Petr Šabata |
f5bf49 |
_options=$(echo $_options | sed 's/\(^\|,\)ro\($\|,\)/\1rw\2/g')
|
|
Petr Šabata |
f5bf49 |
# with 'noauto' in fstab nfs and non-root disk mount will fail in 2nd
|
|
Petr Šabata |
f5bf49 |
# kernel, filter it out here.
|
|
Petr Šabata |
f5bf49 |
_options=$(echo $_options | sed 's/\(^\|,\)noauto\($\|,\)/\1/g')
|
|
Petr Šabata |
f5bf49 |
# drop nofail or nobootwait
|
|
Petr Šabata |
f5bf49 |
_options=$(echo $_options | sed 's/\(^\|,\)nofail\($\|,\)/\1/g')
|
|
Petr Šabata |
f5bf49 |
_options=$(echo $_options | sed 's/\(^\|,\)nobootwait\($\|,\)/\1/g')
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
echo "$_pdev $_new_mntpoint $_fstype $_options"
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
#Function: get_ssh_size
|
|
Petr Šabata |
f5bf49 |
#$1=dump target
|
|
Petr Šabata |
f5bf49 |
#called from while loop and shouldn't read from stdin, so we're using "ssh -n"
|
|
Petr Šabata |
f5bf49 |
get_ssh_size() {
|
|
Petr Šabata |
f5bf49 |
local _opt _out _size
|
|
Petr Šabata |
f5bf49 |
_opt="-i $SSH_KEY_LOCATION -o BatchMode=yes -o StrictHostKeyChecking=yes"
|
|
Petr Šabata |
f5bf49 |
_out=$(ssh -q -n $_opt $1 "df -P $SAVE_PATH")
|
|
Petr Šabata |
f5bf49 |
[ $? -ne 0 ] && {
|
|
Petr Šabata |
f5bf49 |
perror_exit "checking remote ssh server available size failed."
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
#ssh output removed the line break, so print field NF-2
|
|
Petr Šabata |
f5bf49 |
_size=$(echo -n $_out| awk '{avail=NF-2; print $avail}')
|
|
Petr Šabata |
f5bf49 |
echo -n $_size
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
#mkdir if save path does not exist on ssh dump target
|
|
Petr Šabata |
f5bf49 |
#$1=ssh dump target
|
|
Petr Šabata |
f5bf49 |
#caller should ensure write permission on $1:$SAVE_PATH
|
|
Petr Šabata |
f5bf49 |
#called from while loop and shouldn't read from stdin, so we're using "ssh -n"
|
|
Petr Šabata |
f5bf49 |
mkdir_save_path_ssh()
|
|
Petr Šabata |
f5bf49 |
{
|
|
Petr Šabata |
f5bf49 |
local _opt _dir
|
|
Petr Šabata |
f5bf49 |
_opt="-i $SSH_KEY_LOCATION -o BatchMode=yes -o StrictHostKeyChecking=yes"
|
|
Petr Šabata |
f5bf49 |
ssh -qn $_opt $1 mkdir -p $SAVE_PATH 2>&1 > /dev/null
|
|
Petr Šabata |
f5bf49 |
_ret=$?
|
|
Petr Šabata |
f5bf49 |
if [ $_ret -ne 0 ]; then
|
|
Petr Šabata |
f5bf49 |
perror_exit "mkdir failed on $1:$SAVE_PATH"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
#check whether user has write permission on $1:$SAVE_PATH
|
|
Petr Šabata |
f5bf49 |
_dir=$(ssh -qn $_opt $1 mktemp -dqp $SAVE_PATH 2>/dev/null)
|
|
Petr Šabata |
f5bf49 |
_ret=$?
|
|
Petr Šabata |
f5bf49 |
if [ $_ret -ne 0 ]; then
|
|
Petr Šabata |
f5bf49 |
perror_exit "Could not create temporary directory on $1:$SAVE_PATH. Make sure user has write permission on destination"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
ssh -qn $_opt $1 rmdir $_dir
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
return 0
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
#Function: get_fs_size
|
|
Petr Šabata |
f5bf49 |
#$1=dump target
|
|
Petr Šabata |
f5bf49 |
get_fs_size() {
|
|
Petr Šabata |
f5bf49 |
local _mnt=$(get_mntpoint_from_target $1)
|
|
Petr Šabata |
f5bf49 |
echo -n $(df -P "${_mnt}/$SAVE_PATH"|tail -1|awk '{print $4}')
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
#Function: get_raw_size
|
|
Petr Šabata |
f5bf49 |
#$1=dump target
|
|
Petr Šabata |
f5bf49 |
get_raw_size() {
|
|
Petr Šabata |
f5bf49 |
echo -n $(fdisk -s "$1")
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
#Function: check_size
|
|
Petr Šabata |
f5bf49 |
#$1: dump type string ('raw', 'fs', 'ssh')
|
|
Petr Šabata |
f5bf49 |
#$2: dump target
|
|
Petr Šabata |
f5bf49 |
check_size() {
|
|
Petr Šabata |
f5bf49 |
local avail memtotal
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
memtotal=$(awk '/MemTotal/{print $2}' /proc/meminfo)
|
|
Petr Šabata |
f5bf49 |
case "$1" in
|
|
Petr Šabata |
f5bf49 |
raw)
|
|
Petr Šabata |
f5bf49 |
avail=$(get_raw_size "$2")
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
ssh)
|
|
Petr Šabata |
f5bf49 |
avail=$(get_ssh_size "$2")
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
fs)
|
|
Petr Šabata |
f5bf49 |
avail=$(get_fs_size "$2")
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
*)
|
|
Petr Šabata |
f5bf49 |
return
|
|
Petr Šabata |
f5bf49 |
esac
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ $? -ne 0 ]; then
|
|
Petr Šabata |
f5bf49 |
perror_exit "Check dump target size failed"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ $avail -lt $memtotal ]; then
|
|
DistroBaker |
5cac7c |
dwarn "Warning: There might not be enough space to save a vmcore."
|
|
DistroBaker |
5cac7c |
dwarn " The size of $2 should be greater than $memtotal kilo bytes."
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
check_save_path_fs()
|
|
Petr Šabata |
f5bf49 |
{
|
|
Petr Šabata |
f5bf49 |
local _path=$1
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ ! -d $_path ]; then
|
|
Petr Šabata |
f5bf49 |
perror_exit "Dump path $_path does not exist."
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
check_user_configured_target()
|
|
Petr Šabata |
f5bf49 |
{
|
|
Petr Šabata |
f5bf49 |
local _target=$1 _cfg_fs_type=$2 _mounted
|
|
Petr Šabata |
f5bf49 |
local _mnt=$(get_mntpoint_from_target $_target)
|
|
Petr Šabata |
f5bf49 |
local _opt=$(get_mntopt_from_target $_target)
|
|
Petr Šabata |
f5bf49 |
local _fstype=$(get_fs_type_from_target $_target)
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ -n "$_fstype" ]; then
|
|
Petr Šabata |
f5bf49 |
# In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf
|
|
Petr Šabata |
f5bf49 |
[[ $_fstype = "nfs"* ]] && _fstype=nfs
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ -n "$_cfg_fs_type" ] && [ "$_fstype" != "$_cfg_fs_type" ]; then
|
|
Petr Šabata |
f5bf49 |
perror_exit "\"$_target\" have a wrong type config \"$_cfg_fs_type\", expected \"$_fstype\""
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
_fstype="$_cfg_fs_type"
|
|
Petr Šabata |
f5bf49 |
_fstype="$_cfg_fs_type"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# For noauto mount, mount it inplace with default value.
|
|
Petr Šabata |
f5bf49 |
# Else use the temporary target directory
|
|
Petr Šabata |
f5bf49 |
if [ -n "$_mnt" ]; then
|
|
Petr Šabata |
f5bf49 |
if ! is_mounted "$_mnt"; then
|
|
Petr Šabata |
f5bf49 |
if [[ $_opt = *",noauto"* ]]; then
|
|
Petr Šabata |
f5bf49 |
mount $_mnt
|
|
Petr Šabata |
f5bf49 |
[ $? -ne 0 ] && perror_exit "Failed to mount $_target on $_mnt for kdump preflight check."
|
|
Petr Šabata |
f5bf49 |
_mounted=$_mnt
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
perror_exit "Dump target \"$_target\" is neither mounted nor configured as \"noauto\""
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
_mnt=$MKDUMPRD_TMPMNT
|
|
Petr Šabata |
f5bf49 |
mkdir -p $_mnt
|
|
Petr Šabata |
f5bf49 |
mount $_target $_mnt -t $_fstype -o defaults
|
|
Petr Šabata |
f5bf49 |
[ $? -ne 0 ] && perror_exit "Failed to mount $_target for kdump preflight check."
|
|
Petr Šabata |
f5bf49 |
_mounted=$_mnt
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# For user configured target, use $SAVE_PATH as the dump path within the target
|
|
Petr Šabata |
f5bf49 |
if [ ! -d "$_mnt/$SAVE_PATH" ]; then
|
|
Petr Šabata |
f5bf49 |
perror_exit "Dump path \"$SAVE_PATH\" does not exist in dump target \"$_target\""
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
check_size fs "$_target"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Unmount it early, if function is interrupted and didn't reach here, the shell trap will clear it up anyway
|
|
Petr Šabata |
f5bf49 |
if [ -n "$_mounted" ]; then
|
|
Petr Šabata |
f5bf49 |
umount -f -- $_mounted
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# $1: core_collector config value
|
|
Petr Šabata |
f5bf49 |
verify_core_collector() {
|
|
Petr Šabata |
f5bf49 |
local _cmd="${1%% *}"
|
|
Petr Šabata |
f5bf49 |
local _params="${1#* }"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ "$_cmd" != "makedumpfile" ]; then
|
|
Petr Šabata |
f5bf49 |
if is_raw_dump_target; then
|
|
DistroBaker |
5cac7c |
dwarn "Warning: specifying a non-makedumpfile core collector, you will have to recover the vmcore manually."
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
return
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if is_ssh_dump_target || is_raw_dump_target; then
|
|
Petr Šabata |
f5bf49 |
if ! strstr "$_params" "-F"; then
|
|
Petr Šabata |
f5bf49 |
perror_exit "The specified dump target needs makedumpfile \"-F\" option."
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
_params="$_params vmcore"
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
_params="$_params vmcore dumpfile"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if ! $_cmd --check-params $_params; then
|
|
Petr Šabata |
f5bf49 |
perror_exit "makedumpfile parameter check failed."
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
add_mount() {
|
|
Petr Šabata |
f5bf49 |
local _mnt=$(to_mount $@)
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ $? -ne 0 ]; then
|
|
Petr Šabata |
f5bf49 |
exit 1
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
add_dracut_mount "$_mnt"
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
#handle the case user does not specify the dump target explicitly
|
|
Petr Šabata |
f5bf49 |
handle_default_dump_target()
|
|
Petr Šabata |
f5bf49 |
{
|
|
Petr Šabata |
f5bf49 |
local _target
|
|
Petr Šabata |
f5bf49 |
local _mntpoint
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
is_user_configured_dump_target && return
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
check_save_path_fs $SAVE_PATH
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
_save_path=$(get_bind_mount_source $SAVE_PATH)
|
|
Petr Šabata |
f5bf49 |
_target=$(get_target_from_path $_save_path)
|
|
Petr Šabata |
f5bf49 |
_mntpoint=$(get_mntpoint_from_target $_target)
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
SAVE_PATH=${_save_path##"$_mntpoint"}
|
|
Petr Šabata |
f5bf49 |
add_mount "$_target"
|
|
Petr Šabata |
f5bf49 |
check_size fs $_target
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
get_override_resettable()
|
|
Petr Šabata |
f5bf49 |
{
|
|
Petr Šabata |
f5bf49 |
local override_resettable
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
override_resettable=$(grep "^override_resettable" $conf_file)
|
|
Petr Šabata |
f5bf49 |
if [ -n "$override_resettable" ]; then
|
|
Petr Šabata |
f5bf49 |
OVERRIDE_RESETTABLE=$(echo $override_resettable | cut -d' ' -f2)
|
|
Petr Šabata |
f5bf49 |
if [ "$OVERRIDE_RESETTABLE" != "0" ] && [ "$OVERRIDE_RESETTABLE" != "1" ];then
|
|
Petr Šabata |
f5bf49 |
perror_exit "override_resettable value $OVERRIDE_RESETTABLE is invalid"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# $1: function name
|
|
Petr Šabata |
f5bf49 |
for_each_block_target()
|
|
Petr Šabata |
f5bf49 |
{
|
|
Petr Šabata |
f5bf49 |
local dev majmin
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
for dev in $(get_kdump_targets); do
|
|
Petr Šabata |
f5bf49 |
[ -b "$dev" ] || continue
|
|
Petr Šabata |
f5bf49 |
majmin=$(get_maj_min $dev)
|
|
Petr Šabata |
f5bf49 |
check_block_and_slaves $1 $majmin && return 1
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
return 0
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
#judge if a specific device with $1 is unresettable
|
|
Petr Šabata |
f5bf49 |
#return false if unresettable.
|
|
Petr Šabata |
f5bf49 |
is_unresettable()
|
|
Petr Šabata |
f5bf49 |
{
|
|
Petr Šabata |
f5bf49 |
local path="/sys/$(udevadm info --query=all --path=/sys/dev/block/$1 | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable"
|
|
Petr Šabata |
f5bf49 |
local resettable=1
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ -f "$path" ]
|
|
Petr Šabata |
f5bf49 |
then
|
|
Petr Šabata |
f5bf49 |
resettable="$(cat $path)"
|
|
Petr Šabata |
f5bf49 |
[ $resettable -eq 0 -a "$OVERRIDE_RESETTABLE" -eq 0 ] && {
|
|
Petr Šabata |
f5bf49 |
local device=$(udevadm info --query=all --path=/sys/dev/block/$1 | awk -F= '/DEVNAME/{print $2}')
|
|
DistroBaker |
5cac7c |
derror "Error: Can not save vmcore because device $device is unresettable"
|
|
Petr Šabata |
f5bf49 |
return 0
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
return 1
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
#check if machine is resettable.
|
|
Petr Šabata |
f5bf49 |
#return true if resettable
|
|
Petr Šabata |
f5bf49 |
check_resettable()
|
|
Petr Šabata |
f5bf49 |
{
|
|
Petr Šabata |
f5bf49 |
local _ret _target
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
get_override_resettable
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
for_each_block_target is_unresettable
|
|
Petr Šabata |
f5bf49 |
_ret=$?
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
[ $_ret -eq 0 ] && return
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
return 1
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
check_crypt()
|
|
Petr Šabata |
f5bf49 |
{
|
|
Kairui Song |
de1c56 |
local _dev
|
|
Petr Šabata |
f5bf49 |
|
|
Kairui Song |
de1c56 |
for _dev in $(get_kdump_targets); do
|
|
Kairui Song |
de1c56 |
if [[ -n $(get_luks_crypt_dev "$(get_maj_min "$_dev")") ]]; then
|
|
Kairui Song |
de1c56 |
derror "Device $_dev is encrypted." && return 1
|
|
Kairui Song |
de1c56 |
fi
|
|
Kairui Song |
de1c56 |
done
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if ! check_resettable; then
|
|
Petr Šabata |
f5bf49 |
exit 1
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if ! check_crypt; then
|
|
DistroBaker |
5cac7c |
dwarn "Warning: Encrypted device is in dump path, which is not recommended, see kexec-kdump-howto.txt for more details."
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# firstly get right SSH_KEY_LOCATION
|
|
Petr Šabata |
f5bf49 |
keyfile=$(awk '/^sshkey/ {print $2}' $conf_file)
|
|
Petr Šabata |
f5bf49 |
if [ -f "$keyfile" ]; then
|
|
Petr Šabata |
f5bf49 |
# canonicalize the path
|
|
Petr Šabata |
f5bf49 |
SSH_KEY_LOCATION=$(/usr/bin/readlink -m $keyfile)
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
while read config_opt config_val;
|
|
Petr Šabata |
f5bf49 |
do
|
|
Petr Šabata |
f5bf49 |
# remove inline comments after the end of a directive.
|
|
Petr Šabata |
f5bf49 |
case "$config_opt" in
|
|
Petr Šabata |
f5bf49 |
extra_modules)
|
|
Petr Šabata |
f5bf49 |
extra_modules="$extra_modules $config_val"
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
ext[234]|xfs|btrfs|minix|nfs)
|
|
Petr Šabata |
f5bf49 |
check_user_configured_target "$config_val" "$config_opt"
|
|
Petr Šabata |
f5bf49 |
add_mount "$config_val" "$config_opt"
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
raw)
|
|
Petr Šabata |
f5bf49 |
# checking raw disk writable
|
|
Petr Šabata |
f5bf49 |
dd if=$config_val count=1 of=/dev/null > /dev/null 2>&1 || {
|
|
Petr Šabata |
f5bf49 |
perror_exit "Bad raw disk $config_val"
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
_praw=$(persistent_policy="by-id" kdump_get_persistent_dev $config_val)
|
|
Petr Šabata |
f5bf49 |
if [ -z "$_praw" ]; then
|
|
Petr Šabata |
f5bf49 |
exit 1
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
add_dracut_arg "--device" "$_praw"
|
|
Petr Šabata |
f5bf49 |
check_size raw $config_val
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
ssh)
|
|
Petr Šabata |
f5bf49 |
if strstr "$config_val" "@";
|
|
Petr Šabata |
f5bf49 |
then
|
|
Petr Šabata |
f5bf49 |
mkdir_save_path_ssh $config_val
|
|
Petr Šabata |
f5bf49 |
check_size ssh $config_val
|
|
Petr Šabata |
f5bf49 |
add_dracut_sshkey "$SSH_KEY_LOCATION"
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
perror_exit "Bad ssh dump target $config_val"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
core_collector)
|
|
Petr Šabata |
f5bf49 |
verify_core_collector "$config_val"
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
dracut_args)
|
|
Petr Šabata |
f5bf49 |
add_dracut_arg $config_val
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
*)
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
esac
|
|
Petr Šabata |
f5bf49 |
done <<< "$(read_strip_comments $conf_file)"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
handle_default_dump_target
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ -n "$extra_modules" ]
|
|
Petr Šabata |
f5bf49 |
then
|
|
Petr Šabata |
f5bf49 |
add_dracut_arg "--add-drivers" \"$extra_modules\"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if ! is_fadump_capable; then
|
|
Petr Šabata |
f5bf49 |
# The 2nd rootfs mount stays behind the normal dump target mount,
|
|
Petr Šabata |
f5bf49 |
# so it doesn't affect the logic of check_dump_fs_modified().
|
|
Petr Šabata |
f5bf49 |
is_dump_to_rootfs && add_mount "$(to_dev_name $(get_root_fs_device))"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
add_dracut_arg "--no-hostonly-default-device"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
echo "$dracut_args $@" | xargs dracut
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
_rc=$?
|
|
Petr Šabata |
f5bf49 |
sync
|
|
Petr Šabata |
f5bf49 |
exit $_rc
|