24eaa7da8f
Resolves: bz805783 kdumpctl: save_raw if found vmcore mkdumprd: checking available size of raw disk dracut module: do the dumping Note, add a dir /kdumpscripts for monitor_dd_progress and future kdump scripts [v1->v2]: monitor_dd_process become a script instead of a function add missed utils use pipe with dc [v2->v3]: Don: fix dd_progress_file typo Vivek: move [ -f $conf_file ] earlier don't split keyfile= and [ -f keyfile ] move default core_collector earlier move non-makedumpfile warnings to mkdumprd make check available size a common function Amerigo: use less pipe for grep then awk print use shell (( )) instead of dc use cut instead of awk no need install dc and awk make DD_BLKSIZE a variable don't add 0755 file in git, chmod in module-setup.sh [v3->v4]: vivek: kdumpctl multi raw target handling monitor_dd_progress- fix wrong size calculation: the tail -1 of dd pregress file is in bytes instead of blocks only print the whole dd src file size for non-filtered case check [ -b raw target device ] before dump [v4->v5]: vivek: move check [ -b $1 ] before monitor_dd_progress remove multi target function [v5->v6]: vivek: only warning for raw dump of non-makedumpfile core_collector [v6->v7]: kdumpctl should return 0 when there's no raw target Signed-off-by: Dave Young <dyoung@redhat.com> Acked-by: Vivek Goyal <vgoyal@redhat.com>
200 lines
4.1 KiB
Bash
200 lines
4.1 KiB
Bash
#!/bin/bash --norc
|
|
# New mkdumprd
|
|
#
|
|
# Copyright 2011 Red Hat, Inc.
|
|
#
|
|
# Written by Cong Wang <amwang@redhat.com>
|
|
#
|
|
|
|
export IN_KDUMP=1
|
|
|
|
conf_file="/etc/kdump.conf"
|
|
SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
|
|
extra_modules=""
|
|
dracut_args=("-m" "kdumpbase" "--add" "dash" "--add" "fstab-sys" "--add" "kernel-modules" "-c" "/dev/null" "-I" "/sbin/makedumpfile")
|
|
|
|
add_dracut_arg() {
|
|
while [ $# -gt 0 ];
|
|
do
|
|
dracut_args+=("$1")
|
|
shift
|
|
done
|
|
}
|
|
|
|
add_dracut_module() {
|
|
add_dracut_arg "--add" "$1"
|
|
}
|
|
|
|
add_dracut_mount() {
|
|
add_dracut_arg "--mount" "$1"
|
|
}
|
|
|
|
add_dracut_sshkey() {
|
|
add_dracut_arg "--sshkey" "$1"
|
|
}
|
|
|
|
#Function: get_raw_size
|
|
#$1=dump target
|
|
get_raw_size() {
|
|
echo -n $(fdisk -s "$1")
|
|
}
|
|
|
|
#Function: check_size
|
|
#$1: dump type string ('raw', 'local', 'ssh', 'nfs')
|
|
#$2: dump target
|
|
check_size() {
|
|
local avail memtotal
|
|
|
|
memtotal=$(awk '/MemTotal/{print $2}' /proc/meminfo)
|
|
case "$1" in
|
|
raw)
|
|
avail=$(get_raw_size "$2")
|
|
;;
|
|
*)
|
|
return
|
|
esac
|
|
|
|
if [ $avail -lt $memtotal ]; then
|
|
echo "Warning: There is not enough space to save a vmcore."
|
|
echo " The size of $2 should be much greater than $memtotal kilo bytes."
|
|
fi
|
|
}
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case $1 in
|
|
-d)
|
|
shift
|
|
;;
|
|
--noconf)
|
|
conf_file=""
|
|
shift
|
|
;;
|
|
--debug)
|
|
add_dracut_arg "-v"
|
|
set -x
|
|
shift
|
|
;;
|
|
*)
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Generic substring function. If $2 is in $1, return 0.
|
|
strstr() { [[ $1 =~ $2 ]]; }
|
|
|
|
to_dev_name() {
|
|
local dev="$1"
|
|
|
|
case "$dev" in
|
|
UUID=*)
|
|
dev=`blkid -U "${dev#UUID=}"`
|
|
;;
|
|
LABEL=*)
|
|
dev=`blkid -L "${dev#LABEL=}"`
|
|
;;
|
|
esac
|
|
echo $dev
|
|
}
|
|
|
|
get_rootdev() {
|
|
mount | grep 'on / ' | grep -v rootfs | awk '{print $1}'
|
|
}
|
|
|
|
to_mount() {
|
|
local _dev=$(to_dev_name $1)
|
|
echo "$(grep "$_dev" /proc/mounts | cut -d' ' -f1-4)"
|
|
}
|
|
|
|
# $1 remote target
|
|
check_remote() {
|
|
return
|
|
}
|
|
|
|
add_mount() {
|
|
local _dev=$(to_dev_name "$1")
|
|
local _mnt=$(to_mount "$1")
|
|
if [ "$_dev" = "$(get_rootdev)" ]; then
|
|
:
|
|
elif [ -n "$_mnt" ]; then
|
|
add_dracut_mount "$_mnt"
|
|
else
|
|
return 1
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
add_dracut_mount "$(to_mount "$(get_rootdev)")"
|
|
|
|
# firstly get right SSH_KEY_LOCATION
|
|
keyfile=$(awk '/sshkey/ {print $2}' $conf_file)
|
|
if [ -f "$keyfile" ]; then
|
|
# canonicalize the path
|
|
SSH_KEY_LOCATION=$(/usr/bin/readlink -m $keyfile)
|
|
fi
|
|
|
|
while read config_opt config_val;
|
|
do
|
|
case "$config_opt" in
|
|
extra_modules)
|
|
extra_modules="$extra_modules $config_val"
|
|
;;
|
|
ext[234]|xfs|btrfs|minix)
|
|
add_mount "$config_val"
|
|
if [ $? -ne 0 ]; then
|
|
echo "Dump target $config_val is probably not mounted."
|
|
exit 1
|
|
fi
|
|
;;
|
|
raw)
|
|
#checking raw disk writable
|
|
dd if=$config_val count=1 of=/dev/null > /dev/null 2>&1 || {
|
|
echo "Bad raw disk $config_val"
|
|
exit 1
|
|
}
|
|
check_size raw $config_val
|
|
;;
|
|
net)
|
|
check_remote "$config_val"
|
|
if strstr "$config_val" "@";
|
|
then
|
|
add_dracut_module "ssh-client"
|
|
add_dracut_sshkey "$SSH_KEY_LOCATION"
|
|
else
|
|
add_dracut_module "nfs"
|
|
add_mount "$config_val"
|
|
if [ $? -ne 0 ]; then
|
|
echo "Dump target $config_val is probably not mounted."
|
|
exit 1
|
|
fi
|
|
fi
|
|
;;
|
|
core_collector)
|
|
if grep -q "^raw" $conf_file && [ "${config_val%% *}" != "makedumpfile" ]; then
|
|
echo "Warning: specifying a non-makedumpfile core collector, you will have to recover the vmcore manually."
|
|
fi
|
|
add_dracut_arg "-I" "${config_val%% *}"
|
|
;;
|
|
extra_bins)
|
|
add_dracut_arg "-I" "$config_val"
|
|
;;
|
|
*)
|
|
if [ -n $(echo $config_opt | grep "^#.*$") ]
|
|
then
|
|
continue
|
|
fi
|
|
;;
|
|
esac
|
|
done < $conf_file
|
|
|
|
if [ -n "$extra_modules" ]
|
|
then
|
|
add_dracut_arg "--add-drivers" "$extra_modules"
|
|
fi
|
|
|
|
dracut "${dracut_args[@]}" -M "$@"
|
|
_rc=$?
|
|
sync
|
|
exit $_rc
|
|
|