2006-07-20 03:36:18 +00:00
|
|
|
#!/bin/bash --norc
|
2011-07-21 10:51:33 +00:00
|
|
|
# New mkdumprd
|
2006-07-20 03:36:18 +00:00
|
|
|
#
|
2011-07-21 10:51:33 +00:00
|
|
|
# Copyright 2011 Red Hat, Inc.
|
2006-07-20 03:36:18 +00:00
|
|
|
#
|
2011-07-21 10:51:33 +00:00
|
|
|
# Written by Cong Wang <amwang@redhat.com>
|
2006-07-20 03:36:18 +00:00
|
|
|
#
|
|
|
|
|
2011-07-21 10:51:33 +00:00
|
|
|
export IN_KDUMP=1
|
2006-07-20 03:36:18 +00:00
|
|
|
|
2011-07-21 10:51:33 +00:00
|
|
|
conf_file="/etc/kdump.conf"
|
|
|
|
extra_modules=""
|
2012-01-10 14:34:47 +00:00
|
|
|
dracut_args=("-m" "kdumpbase" "--add" "dash" "--add" "fstab-sys" "-c" "/dev/null" "-I" "/sbin/makedumpfile")
|
2006-07-20 03:36:18 +00:00
|
|
|
|
2011-07-21 10:51:33 +00:00
|
|
|
add_dracut_arg() {
|
2011-12-16 10:06:45 +00:00
|
|
|
while [ $# -gt 0 ];
|
|
|
|
do
|
|
|
|
dracut_args+=("$1")
|
|
|
|
shift
|
|
|
|
done
|
2006-07-20 03:36:18 +00:00
|
|
|
}
|
|
|
|
|
2011-08-01 09:19:24 +00:00
|
|
|
add_dracut_module() {
|
2011-12-16 10:06:45 +00:00
|
|
|
add_dracut_arg "--add" "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
add_dracut_mount() {
|
|
|
|
add_dracut_arg "--mount" "$1"
|
2011-08-01 09:19:24 +00:00
|
|
|
}
|
|
|
|
|
2006-07-20 03:36:18 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case $1 in
|
2011-07-21 13:04:09 +00:00
|
|
|
-d)
|
|
|
|
shift
|
|
|
|
;;
|
2011-07-21 10:51:33 +00:00
|
|
|
--noconf)
|
|
|
|
conf_file=""
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--debug)
|
|
|
|
add_dracut_arg "-v"
|
|
|
|
set -x
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
2006-07-20 03:36:18 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2011-12-16 06:21:02 +00:00
|
|
|
# Generic substring function. If $2 is in $1, return 0.
|
|
|
|
strstr() { [[ $1 =~ $2 ]]; }
|
|
|
|
|
2011-12-16 10:06:45 +00:00
|
|
|
to_dev_name() {
|
2011-12-16 06:21:02 +00:00
|
|
|
local dev="$1"
|
|
|
|
|
|
|
|
case "$dev" in
|
|
|
|
UUID=*)
|
|
|
|
dev=`blkid -U "${dev#UUID=}"`
|
|
|
|
;;
|
|
|
|
LABEL=*)
|
|
|
|
dev=`blkid -L "${dev#LABEL=}"`
|
|
|
|
;;
|
|
|
|
esac
|
2011-12-16 10:06:45 +00:00
|
|
|
echo $dev
|
|
|
|
}
|
|
|
|
|
2012-01-25 04:18:51 +00:00
|
|
|
get_rootdev() {
|
|
|
|
mount | grep 'on / ' | grep -v rootfs | awk '{print $1}'
|
|
|
|
}
|
|
|
|
|
2011-12-16 10:06:45 +00:00
|
|
|
to_mount() {
|
|
|
|
local _dev=$(to_dev_name $1)
|
|
|
|
echo "$(grep "$_dev" /proc/mounts | cut -d' ' -f1-4)"
|
2006-07-20 03:36:18 +00:00
|
|
|
}
|
|
|
|
|
2011-07-21 10:51:33 +00:00
|
|
|
# $1 remote target
|
2011-07-28 14:50:43 +00:00
|
|
|
check_remote() {
|
2011-07-21 10:51:33 +00:00
|
|
|
return
|
2006-07-20 03:36:18 +00:00
|
|
|
}
|
|
|
|
|
2012-01-25 04:18:51 +00:00
|
|
|
add_dracut_mount "$(to_mount "$(get_rootdev)")"
|
2011-07-21 10:51:33 +00:00
|
|
|
if [ -n "$conf_file" ]; then
|
|
|
|
while read config_opt config_val;
|
|
|
|
do
|
2008-02-22 12:40:20 +00:00
|
|
|
case "$config_opt" in
|
|
|
|
extra_modules)
|
2011-07-21 10:51:33 +00:00
|
|
|
extra_modules="$extra_modules $config_val"
|
2006-12-15 21:05:01 +00:00
|
|
|
;;
|
2011-07-21 10:51:33 +00:00
|
|
|
ext[234]|xfs|btrfs|minix)
|
2012-01-25 04:18:51 +00:00
|
|
|
_dev=$(to_dev_name "$config_val")
|
|
|
|
_mnt=$(to_mount "$config_val")
|
|
|
|
if [ "$_dev" = "$(get_rootdev)" ]; then
|
|
|
|
:
|
|
|
|
elif [ -n "$_mnt" ]; then
|
|
|
|
add_dracut_mount "$_mnt"
|
|
|
|
else
|
|
|
|
echo "Dump target $config_val is probably not mounted."
|
|
|
|
exit 1
|
|
|
|
fi
|
2010-06-13 19:20:48 +00:00
|
|
|
;;
|
2011-07-21 10:51:33 +00:00
|
|
|
raw)
|
2011-12-16 06:21:02 +00:00
|
|
|
#TODO
|
2006-12-15 21:05:01 +00:00
|
|
|
;;
|
2011-07-21 10:51:33 +00:00
|
|
|
net)
|
2011-07-28 14:50:43 +00:00
|
|
|
check_remote "$config_val"
|
2011-12-16 06:21:02 +00:00
|
|
|
if strstr "$config_val" "@";
|
|
|
|
then
|
2012-01-10 05:28:27 +00:00
|
|
|
add_dracut_module "ssh-client"
|
2011-12-16 06:21:02 +00:00
|
|
|
else
|
|
|
|
add_dracut_module "nfs"
|
2011-12-16 10:06:45 +00:00
|
|
|
add_dracut_mount "$(to_mount $config_val)"
|
2011-12-16 06:21:02 +00:00
|
|
|
fi
|
2010-02-17 16:49:26 +00:00
|
|
|
;;
|
2011-07-25 10:02:37 +00:00
|
|
|
core_collector)
|
2012-01-10 14:34:47 +00:00
|
|
|
add_dracut_arg "-I" "${config_val% *}"
|
2011-07-25 10:02:37 +00:00
|
|
|
;;
|
|
|
|
extra_bins)
|
2012-01-10 14:34:47 +00:00
|
|
|
add_dracut_arg "-I" "$config_val"
|
2011-07-25 10:02:37 +00:00
|
|
|
;;
|
2006-07-20 03:36:18 +00:00
|
|
|
*)
|
2011-07-21 10:51:33 +00:00
|
|
|
if [ -n $(echo $config_opt | grep "^#.*$") ]
|
2006-12-15 21:05:01 +00:00
|
|
|
then
|
2011-07-21 10:51:33 +00:00
|
|
|
continue
|
2006-12-15 21:05:01 +00:00
|
|
|
fi
|
2006-07-20 03:36:18 +00:00
|
|
|
;;
|
|
|
|
esac
|
2011-07-21 10:51:33 +00:00
|
|
|
done < $conf_file
|
2006-07-20 03:36:18 +00:00
|
|
|
fi
|
|
|
|
|
2011-07-21 10:51:33 +00:00
|
|
|
if [ -n "$extra_modules" ]
|
|
|
|
then
|
2012-01-10 14:34:47 +00:00
|
|
|
add_dracut_arg "--add-drivers" "$extra_modules"
|
2010-06-13 19:20:48 +00:00
|
|
|
fi
|
|
|
|
|
2011-12-16 10:06:45 +00:00
|
|
|
dracut "${dracut_args[@]}" -M "$@"
|
2012-01-25 04:18:51 +00:00
|
|
|
_rc=$?
|
2012-01-10 05:28:27 +00:00
|
|
|
sync
|
2012-01-25 04:18:51 +00:00
|
|
|
exit $_rc
|
2008-02-22 12:40:20 +00:00
|
|
|
|