|
|
de80c6 |
#!/bin/bash --norc
|
|
|
de80c6 |
# New mkdumprd
|
|
|
de80c6 |
#
|
|
|
de80c6 |
# Copyright 2011 Red Hat, Inc.
|
|
|
de80c6 |
#
|
|
|
de80c6 |
# Written by Cong Wang <amwang@redhat.com>
|
|
|
de80c6 |
#
|
|
|
de80c6 |
|
|
|
de80c6 |
. /lib/kdump/kdump-lib.sh
|
|
|
de80c6 |
export IN_KDUMP=1
|
|
|
de80c6 |
|
|
|
de80c6 |
conf_file="/etc/kdump.conf"
|
|
|
de80c6 |
SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
|
|
|
de80c6 |
SAVE_PATH=$(grep ^path $conf_file| cut -d' ' -f2)
|
|
|
de80c6 |
[ -z "$SAVE_PATH" ] && SAVE_PATH=$DEFAULT_PATH
|
|
|
de80c6 |
extra_modules=""
|
|
|
de80c6 |
dracut_args=("--hostonly" "--hostonly-cmdline" "-o" "plymouth dash resume")
|
|
|
de80c6 |
OVERRIDE_RESETTABLE=0
|
|
|
de80c6 |
|
|
|
de80c6 |
perror_exit() {
|
|
|
de80c6 |
echo $@ >&2
|
|
|
de80c6 |
exit 1
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
perror() {
|
|
|
de80c6 |
echo $@ >&2
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
get_persistent_dev() {
|
|
|
de80c6 |
local i _tmp _dev
|
|
|
de80c6 |
|
|
|
de80c6 |
_dev=$(udevadm info --query=name --name="$1" 2>/dev/null)
|
|
|
de80c6 |
[ -z "$_dev" ] && {
|
|
|
de80c6 |
perror_exit "Kernel dev name of $1 is not found."
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
for i in /dev/mapper/* /dev/disk/by-uuid/* /dev/disk/by-id/*; do
|
|
|
de80c6 |
_tmp=$(udevadm info --query=name --name="$i" 2>/dev/null)
|
|
|
de80c6 |
if [ "$_tmp" = "$_dev" ]; then
|
|
|
de80c6 |
echo $i
|
|
|
de80c6 |
return
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
done
|
|
|
de80c6 |
|
|
|
de80c6 |
perror "WARNING: Persistent device name of $1 not found. Using $1 as dump target name"
|
|
|
de80c6 |
echo $1
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
add_dracut_arg() {
|
|
|
de80c6 |
local arg qarg is_quoted=0
|
|
|
de80c6 |
while [ $# -gt 0 ];
|
|
|
de80c6 |
do
|
|
|
de80c6 |
arg="${1//\'/\"}"
|
|
|
de80c6 |
#Handle quoted substring properly for passing it to dracut_args array.
|
|
|
de80c6 |
if [ $is_quoted -eq 0 ]; then
|
|
|
de80c6 |
if [[ "$arg" == "\"" ]] || [[ $arg != ${arg#\"} ]]; then
|
|
|
de80c6 |
is_quoted=1
|
|
|
de80c6 |
arg=${arg#\"}
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
if [ $is_quoted -eq 1 ]; then
|
|
|
de80c6 |
qarg="$qarg $arg"
|
|
|
de80c6 |
if [[ "$arg" == "\"" ]] || [[ $arg != ${arg%\"} ]]; then
|
|
|
de80c6 |
is_quoted=0
|
|
|
de80c6 |
arg=${qarg%\"}
|
|
|
de80c6 |
qarg=""
|
|
|
de80c6 |
else
|
|
|
de80c6 |
shift
|
|
|
de80c6 |
continue
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
dracut_args+=("$arg")
|
|
|
de80c6 |
shift
|
|
|
de80c6 |
done
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
add_dracut_module() {
|
|
|
de80c6 |
add_dracut_arg "--add" "$1"
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
add_dracut_mount() {
|
|
|
de80c6 |
add_dracut_arg "--mount" "$1"
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
add_dracut_sshkey() {
|
|
|
de80c6 |
add_dracut_arg "--sshkey" "$1"
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
# Generic substring function. If $2 is in $1, return 0.
|
|
|
de80c6 |
strstr() { [[ $1 =~ $2 ]]; }
|
|
|
de80c6 |
|
|
|
de80c6 |
target_is_root() {
|
|
|
de80c6 |
local _t
|
|
|
de80c6 |
_t=$(findmnt -k -n -r -o TARGET $1|sort|head -1)
|
|
|
de80c6 |
[ "$_t" = "/" ]
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
# caller should ensure $1 is valid and mounted in 1st kernel
|
|
|
de80c6 |
to_mount() {
|
|
|
de80c6 |
local _dev=$1 _source _target _fstype _options _mntopts _pdev
|
|
|
de80c6 |
|
|
|
de80c6 |
_source=$(findmnt -k -f -n -r -o SOURCE $_dev)
|
|
|
de80c6 |
_target=$(findmnt -k -f -n -r -o TARGET $_dev)
|
|
|
de80c6 |
# mount under /sysroot if dump to root disk or mount under
|
|
|
de80c6 |
#/kdumproot/$_target in other cases in 2nd kernel. systemd
|
|
|
de80c6 |
#will be in charge to umount it.
|
|
|
de80c6 |
|
|
|
de80c6 |
if [ "$_target" = "/" ];then
|
|
|
de80c6 |
_target="/sysroot"
|
|
|
de80c6 |
else
|
|
|
de80c6 |
_target="/kdumproot/$_target"
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
_fstype=$(findmnt -k -f -n -r -o FSTYPE $_dev)
|
|
|
de80c6 |
_options=$(findmnt --fstab -f -n -r -o OPTIONS $_dev)
|
|
|
de80c6 |
[ -z "$_options" ] && _options=$(findmnt -k -f -n -r -o OPTIONS $_dev)
|
|
|
de80c6 |
_options=${_options/#ro/rw} #mount fs target as rw in 2nd kernel
|
|
|
de80c6 |
# "x-initrd.mount" mount failure will trigger isolate emergency service
|
|
|
de80c6 |
# W/o this, systemd won't isolate, thus we won't get to emergency.
|
|
|
de80c6 |
# This is not applicable to remote fs mount, because if we use
|
|
|
de80c6 |
# "x-initrd.mount", remote mount will become required by
|
|
|
de80c6 |
# "initrd-root-fs.target", instead of "remote-fs.target". That's how it is
|
|
|
de80c6 |
# handled within systemd internal. We need remote mount to be required
|
|
|
de80c6 |
# "remote-fs.target", because we need to bring up network before any remote
|
|
|
de80c6 |
# mount and "remote-fs.target" can be a checkpoint of that.
|
|
|
de80c6 |
# If remote mount fails, dracut-initqueue will still start and once
|
|
|
de80c6 |
# dracut-initqueue finishes, kdump service will start. Because remote mount
|
|
|
de80c6 |
# failed, kdump service will fail and it will lead to kdump error handler.
|
|
|
de80c6 |
if ! is_nfs_dump_target; then
|
|
|
de80c6 |
_options="$_options,x-initrd.mount"
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
_mntopts="$_target $_fstype $_options"
|
|
|
de80c6 |
#for non-nfs _dev converting to use udev persistent name
|
|
|
de80c6 |
if [ -b "$_source" ]; then
|
|
|
de80c6 |
_pdev="$(get_persistent_dev $_source)"
|
|
|
de80c6 |
if [ $? -ne 0 ]; then
|
|
|
de80c6 |
return 1
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
else
|
|
|
de80c6 |
_pdev=$_dev
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
echo "$_pdev $_mntopts"
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
to_mount_point() {
|
|
|
de80c6 |
echo $(findmnt -k -f -n -r -o TARGET $1)
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
is_readonly_mount() {
|
|
|
de80c6 |
local _mnt
|
|
|
de80c6 |
_mnt=$(findmnt -k -f -n -r -o OPTIONS $1)
|
|
|
de80c6 |
|
|
|
de80c6 |
#fs/proc_namespace.c: show_mountinfo():
|
|
|
de80c6 |
#seq_puts(m, mnt->mnt_flags & MNT_READONLY ? " ro" : " rw");
|
|
|
de80c6 |
[[ "$_mnt" =~ ^ro ]]
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
#Function: get_ssh_size
|
|
|
de80c6 |
#$1=dump target
|
|
|
de80c6 |
#called from while loop and shouldn't read from stdin, so we're using "ssh -n"
|
|
|
de80c6 |
get_ssh_size() {
|
|
|
de80c6 |
local _opt _out _size
|
|
|
de80c6 |
_opt="-i $SSH_KEY_LOCATION -o BatchMode=yes -o StrictHostKeyChecking=yes"
|
|
|
de80c6 |
_out=$(ssh -q -n $_opt $1 "df -P $SAVE_PATH")
|
|
|
de80c6 |
[ $? -ne 0 ] && {
|
|
|
de80c6 |
perror_exit "checking remote ssh server available size failed."
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
#ssh output removed the line break, so print field NF-2
|
|
|
de80c6 |
_size=$(echo -n $_out| awk '{avail=NF-2; print $avail}')
|
|
|
de80c6 |
echo -n $_size
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
#mkdir if save path does not exist on ssh dump target
|
|
|
de80c6 |
#$1=ssh dump target
|
|
|
de80c6 |
#caller should ensure write permission on $DUMP_TARGET:$SAVE_PATH
|
|
|
de80c6 |
#called from while loop and shouldn't read from stdin, so we're using "ssh -n"
|
|
|
de80c6 |
mkdir_save_path_ssh()
|
|
|
de80c6 |
{
|
|
|
de80c6 |
local _opt _dir
|
|
|
de80c6 |
_opt="-i $SSH_KEY_LOCATION -o BatchMode=yes -o StrictHostKeyChecking=yes"
|
|
|
de80c6 |
ssh -qn $_opt $1 mkdir -p $SAVE_PATH 2>&1 > /dev/null
|
|
|
de80c6 |
_ret=$?
|
|
|
de80c6 |
if [ $_ret -ne 0 ]; then
|
|
|
de80c6 |
perror_exit "mkdir failed on $DUMP_TARGET:$SAVE_PATH"
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
#check whether user has write permission on $SAVE_PATH/$DUMP_TARGET
|
|
|
de80c6 |
_dir=$(ssh -qn $_opt $1 mktemp -dqp $SAVE_PATH 2>/dev/null)
|
|
|
de80c6 |
_ret=$?
|
|
|
de80c6 |
if [ $_ret -ne 0 ]; then
|
|
|
de80c6 |
perror_exit "Could not create temporary directory on $DUMP_TARGET:$SAVE_PATH. Make sure user has write permission on destination"
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
ssh -qn $_opt $1 rmdir $_dir
|
|
|
de80c6 |
|
|
|
de80c6 |
return 0
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
#Function: get_fs_size
|
|
|
de80c6 |
#$1=dump target
|
|
|
de80c6 |
get_fs_size() {
|
|
|
de80c6 |
local _mnt=$(to_mount_point $1)
|
|
|
de80c6 |
echo -n $(df -P "${_mnt}/$SAVE_PATH"|tail -1|awk '{print $4}')
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
#Function: get_raw_size
|
|
|
de80c6 |
#$1=dump target
|
|
|
de80c6 |
get_raw_size() {
|
|
|
de80c6 |
echo -n $(fdisk -s "$1")
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
#Function: check_size
|
|
|
de80c6 |
#$1: dump type string ('raw', 'fs', 'ssh')
|
|
|
de80c6 |
#$2: dump target
|
|
|
de80c6 |
check_size() {
|
|
|
de80c6 |
local avail memtotal
|
|
|
de80c6 |
|
|
|
de80c6 |
memtotal=$(awk '/MemTotal/{print $2}' /proc/meminfo)
|
|
|
de80c6 |
case "$1" in
|
|
|
de80c6 |
raw)
|
|
|
de80c6 |
avail=$(get_raw_size "$2")
|
|
|
de80c6 |
;;
|
|
|
de80c6 |
ssh)
|
|
|
de80c6 |
avail=$(get_ssh_size "$2")
|
|
|
de80c6 |
;;
|
|
|
de80c6 |
fs)
|
|
|
de80c6 |
avail=$(get_fs_size "$2")
|
|
|
de80c6 |
;;
|
|
|
de80c6 |
*)
|
|
|
de80c6 |
return
|
|
|
de80c6 |
esac
|
|
|
de80c6 |
|
|
|
de80c6 |
if [ $? -ne 0 ]; then
|
|
|
de80c6 |
perror_exit "Check dump target size failed"
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
if [ $avail -lt $memtotal ]; then
|
|
|
de80c6 |
echo "Warning: There might not be enough space to save a vmcore."
|
|
|
de80c6 |
echo " The size of $2 should be greater than $memtotal kilo bytes."
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
# $1: core_collector config value
|
|
|
de80c6 |
verify_core_collector() {
|
|
|
de80c6 |
if grep -q "^raw" $conf_file && [ "${1%% *}" != "makedumpfile" ]; then
|
|
|
de80c6 |
echo "Warning: specifying a non-makedumpfile core collector, you will have to recover the vmcore manually."
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
if is_ssh_dump_target || is_raw_dump_target; then
|
|
|
de80c6 |
if [ "${1%% *}" = "makedumpfile" ]; then
|
|
|
de80c6 |
! strstr "$1" "-F" && {
|
|
|
de80c6 |
perror_exit "The specified dump target needs makedumpfile \"-F\" option."
|
|
|
de80c6 |
}
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
add_mount() {
|
|
|
de80c6 |
if ! target_is_root "$1"; then
|
|
|
de80c6 |
local _mnt=$(to_mount "$1")
|
|
|
de80c6 |
if [ $? -ne 0 ]; then
|
|
|
de80c6 |
exit 1
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
add_dracut_mount "$_mnt"
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
# get_maj_min <device>
|
|
|
de80c6 |
# Prints the major and minor of a device node.
|
|
|
de80c6 |
# Example:
|
|
|
de80c6 |
# $ get_maj_min /dev/sda2
|
|
|
de80c6 |
# 8:2
|
|
|
de80c6 |
get_maj_min() {
|
|
|
de80c6 |
local _dev
|
|
|
de80c6 |
_dev=$(stat -L -c '$((0x%t)):$((0x%T))' "$1" 2>/dev/null)
|
|
|
de80c6 |
_dev=$(eval "echo $_dev")
|
|
|
de80c6 |
echo $_dev
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
# ugly workaround for the lvm design
|
|
|
de80c6 |
# There is no volume group device,
|
|
|
de80c6 |
# so, there are no slave devices for volume groups.
|
|
|
de80c6 |
# Logical volumes only have the slave devices they really live on,
|
|
|
de80c6 |
# but you cannot create the logical volume without the volume group.
|
|
|
de80c6 |
# And the volume group might be bigger than the devices the LV needs.
|
|
|
de80c6 |
check_vol_slaves() {
|
|
|
de80c6 |
local _lv _vg _pv
|
|
|
de80c6 |
for i in /dev/mapper/*; do
|
|
|
de80c6 |
_lv=$(get_maj_min $i)
|
|
|
de80c6 |
if [[ $_lv = $2 ]]; then
|
|
|
de80c6 |
_vg=$(lvm lvs --noheadings -o vg_name $i 2>/dev/null)
|
|
|
de80c6 |
# strip space
|
|
|
de80c6 |
_vg=$(echo $_vg)
|
|
|
de80c6 |
if [[ $_vg ]]; then
|
|
|
de80c6 |
for _pv in $(lvm vgs --noheadings -o pv_name "$_vg" 2>/dev/null)
|
|
|
de80c6 |
do
|
|
|
de80c6 |
check_block_and_slaves $1 $(get_maj_min $_pv) && return 0
|
|
|
de80c6 |
done
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
done
|
|
|
de80c6 |
return 1
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
# Walk all the slave relationships for a given block device.
|
|
|
de80c6 |
# Stop when our helper function returns success
|
|
|
de80c6 |
# $1 = function to call on every found block device
|
|
|
de80c6 |
# $2 = block device in major:minor format
|
|
|
de80c6 |
check_block_and_slaves() {
|
|
|
de80c6 |
local _x
|
|
|
de80c6 |
[[ -b /dev/block/$2 ]] || return 1 # Not a block device? So sorry.
|
|
|
de80c6 |
"$1" $2 && return
|
|
|
de80c6 |
check_vol_slaves "$@" && return 0
|
|
|
de80c6 |
if [[ -f /sys/dev/block/$2/../dev ]]; then
|
|
|
de80c6 |
check_block_and_slaves $1 $(cat "/sys/dev/block/$2/../dev") && return 0
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
[[ -d /sys/dev/block/$2/slaves ]] || return 1
|
|
|
de80c6 |
for _x in /sys/dev/block/$2/slaves/*/dev; do
|
|
|
de80c6 |
[[ -f $_x ]] || continue
|
|
|
de80c6 |
check_block_and_slaves $1 $(cat "$_x") && return 0
|
|
|
de80c6 |
done
|
|
|
de80c6 |
return 1
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
to_dev_name() {
|
|
|
de80c6 |
local dev="${1//\"/}"
|
|
|
de80c6 |
|
|
|
de80c6 |
case "$dev" in
|
|
|
de80c6 |
UUID=*)
|
|
|
de80c6 |
dev=`blkid -U "${dev#UUID=}"`
|
|
|
de80c6 |
;;
|
|
|
de80c6 |
LABEL=*)
|
|
|
de80c6 |
dev=`blkid -L "${dev#LABEL=}"`
|
|
|
de80c6 |
;;
|
|
|
de80c6 |
esac
|
|
|
de80c6 |
echo $dev
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
get_block_dump_target()
|
|
|
de80c6 |
{
|
|
|
de80c6 |
local _target
|
|
|
de80c6 |
|
|
|
de80c6 |
|
|
|
de80c6 |
_target=$(get_user_configured_dump_disk)
|
|
|
de80c6 |
[ -n "$_target" ] && echo $(to_dev_name $_target) && return
|
|
|
de80c6 |
|
|
|
de80c6 |
#get rootfs device name
|
|
|
de80c6 |
_target=$(get_root_fs_device)
|
|
|
de80c6 |
[ -b "$_target" ] && echo $(to_dev_name $_target)
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
#handle the case user does not specify the dump target explicitly
|
|
|
de80c6 |
handle_default_dump_target()
|
|
|
de80c6 |
{
|
|
|
de80c6 |
local _target
|
|
|
de80c6 |
local _mntpoint
|
|
|
de80c6 |
local _fstype
|
|
|
de80c6 |
|
|
|
de80c6 |
is_user_configured_dump_target && return
|
|
|
de80c6 |
|
|
|
de80c6 |
check_save_path_fs $SAVE_PATH
|
|
|
de80c6 |
|
|
|
de80c6 |
_mntpoint=$(get_mntpoint_from_path $SAVE_PATH)
|
|
|
de80c6 |
_target=$(get_target_from_path $SAVE_PATH)
|
|
|
de80c6 |
if [ "$_mntpoint" != "/" ]; then
|
|
|
de80c6 |
SAVE_PATH=${SAVE_PATH##"$_mntpoint"}
|
|
|
de80c6 |
_fstype=$(get_fs_type_from_target $_target)
|
|
|
de80c6 |
|
|
|
de80c6 |
if $(is_fs_type_nfs $_fstype); then
|
|
|
de80c6 |
add_dracut_module "nfs"
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
add_mount "$_target"
|
|
|
de80c6 |
check_size fs $_target
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
get_default_action_target()
|
|
|
de80c6 |
{
|
|
|
de80c6 |
local _target
|
|
|
de80c6 |
local _action=$(grep "^default" /etc/kdump.conf 2>/dev/null | awk '{print $2}')
|
|
|
de80c6 |
if [ -n "$_action" ] && [ "$_action" = "dump_to_rootfs" ]; then
|
|
|
de80c6 |
#get rootfs device name
|
|
|
de80c6 |
_target=$(findmnt -k -f -n -o SOURCE /)
|
|
|
de80c6 |
[ -b "$_target" ] && echo $(to_dev_name $_target)
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
return
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
get_override_resettable()
|
|
|
de80c6 |
{
|
|
|
de80c6 |
local override_resettable
|
|
|
de80c6 |
|
|
|
de80c6 |
override_resettable=$(grep "^override_resettable" $conf_file)
|
|
|
de80c6 |
if [ -n "$override_resettable" ]; then
|
|
|
de80c6 |
OVERRIDE_RESETTABLE=$(echo $override_resettable | cut -d' ' -f2)
|
|
|
de80c6 |
if [ "$OVERRIDE_RESETTABLE" != "0" ] && [ "$OVERRIDE_RESETTABLE" != "1" ];then
|
|
|
de80c6 |
perror_exit "override_resettable value $OVERRIDE_RESETTABLE is invalid"
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
|
|
|
de80c6 |
# $1: function name
|
|
|
de80c6 |
for_each_block_target()
|
|
|
de80c6 |
{
|
|
|
de80c6 |
local dev majmin
|
|
|
de80c6 |
|
|
|
de80c6 |
#check dump target
|
|
|
de80c6 |
dev=$(get_block_dump_target)
|
|
|
de80c6 |
|
|
|
de80c6 |
if [ -n "$dev" ]; then
|
|
|
de80c6 |
majmin=$(get_maj_min $dev)
|
|
|
de80c6 |
check_block_and_slaves $1 $majmin && return 1
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
#check rootfs when default action dump_to_rootfs is set
|
|
|
de80c6 |
dev=$(get_default_action_target)
|
|
|
de80c6 |
if [ -n "$dev" ]; then
|
|
|
de80c6 |
majmin=$(get_maj_min $dev)
|
|
|
de80c6 |
check_block_and_slaves $1 $majmin && return 2
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
return 0
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
|
|
|
de80c6 |
|
|
|
de80c6 |
#judge if a specific device with $1 is unresettable
|
|
|
de80c6 |
#return false if unresettable.
|
|
|
de80c6 |
is_unresettable()
|
|
|
de80c6 |
{
|
|
|
de80c6 |
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"
|
|
|
de80c6 |
local resettable=1
|
|
|
de80c6 |
|
|
|
de80c6 |
if [ -f "$path" ]
|
|
|
de80c6 |
then
|
|
|
de80c6 |
resettable="$(cat $path)"
|
|
|
de80c6 |
[ $resettable -eq 0 -a "$OVERRIDE_RESETTABLE" -eq 0 ] && {
|
|
|
de80c6 |
local device=$(udevadm info --query=all --path=/sys/dev/block/$1 | awk -F= '/DEVNAME/{print $2}')
|
|
|
de80c6 |
echo "Device $device is unresettable"
|
|
|
de80c6 |
return 0
|
|
|
de80c6 |
}
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
return 1
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
#check if machine is resettable.
|
|
|
de80c6 |
#return true if resettable
|
|
|
de80c6 |
check_resettable()
|
|
|
de80c6 |
{
|
|
|
de80c6 |
local _ret _target
|
|
|
de80c6 |
|
|
|
de80c6 |
get_override_resettable
|
|
|
de80c6 |
|
|
|
de80c6 |
for_each_block_target is_unresettable
|
|
|
de80c6 |
_ret=$?
|
|
|
de80c6 |
|
|
|
de80c6 |
[ $_ret -eq 0 ] && return
|
|
|
de80c6 |
|
|
|
de80c6 |
if [ $_ret -eq 1 ]; then
|
|
|
de80c6 |
_target=$(get_block_dump_target)
|
|
|
de80c6 |
perror "Can not save vmcore to target device $_target . This device can not be initialized in kdump kernel as it is not resettable"
|
|
|
de80c6 |
elif [ $_ret -eq 2 ]; then
|
|
|
de80c6 |
_target=$(get_default_action_target)
|
|
|
de80c6 |
perror "Rootfs device $_target is not resettable, can not be used as the default target, please specify a default action"
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
return 1
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
# $1: maj:min
|
|
|
de80c6 |
is_crypt()
|
|
|
de80c6 |
{
|
|
|
de80c6 |
local majmin=$1 dev line ID_FS_TYPE=""
|
|
|
de80c6 |
|
|
|
de80c6 |
line=$(udevadm info --query=property --path=/sys/dev/block/$majmin \
|
|
|
de80c6 |
| grep "^ID_FS_TYPE")
|
|
|
de80c6 |
eval "$line"
|
|
|
de80c6 |
[[ "$ID_FS_TYPE" = "crypto_LUKS" ]] && {
|
|
|
de80c6 |
dev=$(udevadm info --query=all --path=/sys/dev/block/$majmin | awk -F= '/DEVNAME/{print $2}')
|
|
|
de80c6 |
echo "Device $dev is encrypted."
|
|
|
de80c6 |
return 0
|
|
|
de80c6 |
}
|
|
|
de80c6 |
return 1
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
check_crypt()
|
|
|
de80c6 |
{
|
|
|
de80c6 |
local _ret _target
|
|
|
de80c6 |
|
|
|
de80c6 |
for_each_block_target is_crypt
|
|
|
de80c6 |
_ret=$?
|
|
|
de80c6 |
|
|
|
de80c6 |
[ $_ret -eq 0 ] && return
|
|
|
de80c6 |
|
|
|
de80c6 |
return 1
|
|
|
de80c6 |
}
|
|
|
de80c6 |
|
|
|
de80c6 |
if ! check_resettable; then
|
|
|
de80c6 |
exit 1
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
if ! check_crypt; then
|
|
|
de80c6 |
echo "Warning: Encrypted device is in dump path. User will prompted for password during second kernel boot."
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
# firstly get right SSH_KEY_LOCATION
|
|
|
de80c6 |
keyfile=$(awk '/^sshkey/ {print $2}' $conf_file)
|
|
|
de80c6 |
if [ -f "$keyfile" ]; then
|
|
|
de80c6 |
# canonicalize the path
|
|
|
de80c6 |
SSH_KEY_LOCATION=$(/usr/bin/readlink -m $keyfile)
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
if [ "$(uname -m)" = "s390x" ]; then
|
|
|
de80c6 |
add_dracut_module "znet"
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
while read config_opt config_val;
|
|
|
de80c6 |
do
|
|
|
de80c6 |
# remove inline comments after the end of a directive.
|
|
|
de80c6 |
config_val=$(strip_comments $config_val)
|
|
|
de80c6 |
case "$config_opt" in
|
|
|
de80c6 |
extra_modules)
|
|
|
de80c6 |
extra_modules="$extra_modules $config_val"
|
|
|
de80c6 |
;;
|
|
|
de80c6 |
ext[234]|xfs|btrfs|minix|nfs)
|
|
|
de80c6 |
if ! findmnt $config_val >/dev/null; then
|
|
|
de80c6 |
perror_exit "Dump target $config_val is probably not mounted."
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
if [ "$config_opt" = "nfs" ]; then
|
|
|
de80c6 |
add_dracut_module "nfs"
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
add_mount "$config_val"
|
|
|
de80c6 |
check_save_path_fs $(make_absolute_save_path $config_val)
|
|
|
de80c6 |
check_size fs $config_val
|
|
|
de80c6 |
;;
|
|
|
de80c6 |
raw)
|
|
|
de80c6 |
#checking raw disk writable
|
|
|
de80c6 |
dd if=$config_val count=1 of=/dev/null > /dev/null 2>&1 || {
|
|
|
de80c6 |
perror_exit "Bad raw disk $config_val"
|
|
|
de80c6 |
}
|
|
|
de80c6 |
_praw=$(get_persistent_dev $config_val)
|
|
|
de80c6 |
if [ $? -ne 0 ]; then
|
|
|
de80c6 |
exit 1
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
add_dracut_arg "--device" "$_praw"
|
|
|
de80c6 |
check_size raw $config_val
|
|
|
de80c6 |
;;
|
|
|
de80c6 |
ssh)
|
|
|
de80c6 |
if strstr "$config_val" "@";
|
|
|
de80c6 |
then
|
|
|
de80c6 |
check_size ssh $config_val
|
|
|
de80c6 |
mkdir_save_path_ssh $config_val
|
|
|
de80c6 |
add_dracut_module "ssh-client"
|
|
|
de80c6 |
add_dracut_sshkey "$SSH_KEY_LOCATION"
|
|
|
de80c6 |
else
|
|
|
de80c6 |
perror_exit "Bad ssh dump target $config_val"
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
;;
|
|
|
de80c6 |
core_collector)
|
|
|
de80c6 |
verify_core_collector "$config_val"
|
|
|
de80c6 |
;;
|
|
|
de80c6 |
dracut_args)
|
|
|
de80c6 |
add_dracut_arg $config_val
|
|
|
de80c6 |
;;
|
|
|
de80c6 |
*)
|
|
|
de80c6 |
if [ -n $(echo $config_opt | grep "^#.*$") ]
|
|
|
de80c6 |
then
|
|
|
de80c6 |
continue
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
;;
|
|
|
de80c6 |
esac
|
|
|
de80c6 |
done < $conf_file
|
|
|
de80c6 |
|
|
|
de80c6 |
handle_default_dump_target
|
|
|
de80c6 |
|
|
|
de80c6 |
if [ -n "$extra_modules" ]
|
|
|
de80c6 |
then
|
|
|
de80c6 |
add_dracut_arg "--add-drivers" "$extra_modules"
|
|
|
de80c6 |
fi
|
|
|
de80c6 |
|
|
|
de80c6 |
dracut "${dracut_args[@]}" "$@"
|
|
|
de80c6 |
_rc=$?
|
|
|
de80c6 |
sync
|
|
|
de80c6 |
exit $_rc
|