|
Petr Šabata |
f5bf49 |
#!/bin/bash
|
|
Petr Šabata |
f5bf49 |
|
|
DistroBaker |
624a64 |
kdump_module_init() {
|
|
DistroBaker |
624a64 |
if ! [[ -d "${initdir}/tmp" ]]; then
|
|
DistroBaker |
624a64 |
mkdir -p "${initdir}/tmp"
|
|
DistroBaker |
624a64 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
DistroBaker |
624a64 |
. /lib/kdump/kdump-lib.sh
|
|
DistroBaker |
624a64 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
check() {
|
|
Petr Šabata |
f5bf49 |
[[ $debug ]] && set -x
|
|
Petr Šabata |
f5bf49 |
#kdumpctl sets this explicitly
|
|
Petr Šabata |
f5bf49 |
if [ -z "$IN_KDUMP" ] || [ ! -f /etc/kdump.conf ]
|
|
Petr Šabata |
f5bf49 |
then
|
|
Petr Šabata |
f5bf49 |
return 1
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
return 0
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
depends() {
|
|
Petr Šabata |
f5bf49 |
local _dep="base shutdown"
|
|
Petr Šabata |
f5bf49 |
|
|
DistroBaker |
624a64 |
kdump_module_init
|
|
DistroBaker |
624a64 |
|
|
DistroBaker |
17a515 |
add_opt_module() {
|
|
DistroBaker |
17a515 |
[[ " $omit_dracutmodules " != *\ $1\ * ]] && _dep="$_dep $1"
|
|
DistroBaker |
17a515 |
}
|
|
DistroBaker |
17a515 |
|
|
Petr Šabata |
f5bf49 |
is_squash_available() {
|
|
Petr Šabata |
f5bf49 |
for kmodule in squashfs overlay loop; do
|
|
Petr Šabata |
f5bf49 |
if [ -z "$KDUMP_KERNELVER" ]; then
|
|
Petr Šabata |
f5bf49 |
modprobe --dry-run $kmodule &>/dev/null || return 1
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
modprobe -S $KDUMP_KERNELVER --dry-run $kmodule &>/dev/null || return 1
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if is_squash_available && ! is_fadump_capable; then
|
|
DistroBaker |
17a515 |
add_opt_module squash
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
dwarning "Required modules to build a squashed kdump image is missing!"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
DistroBaker |
17a515 |
if is_wdt_active; then
|
|
DistroBaker |
17a515 |
add_opt_module watchdog
|
|
DistroBaker |
17a515 |
fi
|
|
DistroBaker |
17a515 |
|
|
DistroBaker |
17a515 |
if is_ssh_dump_target; then
|
|
DistroBaker |
17a515 |
_dep="$_dep ssh-client"
|
|
DistroBaker |
17a515 |
fi
|
|
DistroBaker |
17a515 |
|
|
DistroBaker |
17a515 |
if [ "$(uname -m)" = "s390x" ]; then
|
|
DistroBaker |
17a515 |
_dep="$_dep znet"
|
|
DistroBaker |
17a515 |
fi
|
|
DistroBaker |
17a515 |
|
|
Petr Šabata |
f5bf49 |
if [ -n "$( find /sys/devices -name drm )" ] || [ -d /sys/module/hyperv_fb ]; then
|
|
DistroBaker |
17a515 |
add_opt_module drm
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if is_generic_fence_kdump || is_pcs_fence_kdump; then
|
|
Petr Šabata |
f5bf49 |
_dep="$_dep network"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
echo $_dep
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_is_bridge() {
|
|
Petr Šabata |
f5bf49 |
[ -d /sys/class/net/"$1"/bridge ]
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_is_bond() {
|
|
Petr Šabata |
f5bf49 |
[ -d /sys/class/net/"$1"/bonding ]
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_is_team() {
|
|
Petr Šabata |
f5bf49 |
[ -f /usr/bin/teamnl ] && teamnl $1 ports &> /dev/null
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_is_vlan() {
|
|
Petr Šabata |
f5bf49 |
[ -f /proc/net/vlan/"$1" ]
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# $1: netdev name
|
|
Petr Šabata |
f5bf49 |
source_ifcfg_file() {
|
|
Petr Šabata |
f5bf49 |
local ifcfg_file
|
|
Petr Šabata |
f5bf49 |
|
|
Coiby Xu |
b5c915 |
dwarning "Network Scripts are deprecated. You are encouraged to set up network by NetworkManager."
|
|
Petr Šabata |
f5bf49 |
ifcfg_file=$(get_ifcfg_filename $1)
|
|
Petr Šabata |
f5bf49 |
if [ -f "${ifcfg_file}" ]; then
|
|
Petr Šabata |
f5bf49 |
. ${ifcfg_file}
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
dwarning "The ifcfg file of $1 is not found!"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Coiby Xu |
f06949 |
# $1: nmcli connection show output
|
|
Petr Šabata |
f5bf49 |
kdump_setup_dns() {
|
|
Coiby Xu |
f06949 |
local _netdev="$1"
|
|
Coiby Xu |
f06949 |
local _nm_show_cmd="$2"
|
|
Coiby Xu |
f06949 |
local _nameserver _dns _tmp array
|
|
Petr Šabata |
f5bf49 |
local _dnsfile=${initdir}/etc/cmdline.d/42dns.conf
|
|
Petr Šabata |
f5bf49 |
|
|
Coiby Xu |
f06949 |
_tmp=$(get_nmcli_value_by_field "$_nm_show_cmd" "IP4.DNS")
|
|
Coiby Xu |
f06949 |
array=(${_tmp//|/ })
|
|
Coiby Xu |
f06949 |
if [[ ${array[@]} ]]; then
|
|
Coiby Xu |
f06949 |
for _dns in "${array[@]}"
|
|
Coiby Xu |
f06949 |
do
|
|
Coiby Xu |
f06949 |
echo "nameserver=$_dns" >> "$_dnsfile"
|
|
Coiby Xu |
f06949 |
done
|
|
Coiby Xu |
f06949 |
else
|
|
Coiby Xu |
f06949 |
dwarning "Failed to get DNS info via nmcli output. Now try sourcing ifcfg script"
|
|
Coiby Xu |
f06949 |
source_ifcfg_file "$_netdev"
|
|
Coiby Xu |
f06949 |
[ -n "$DNS1" ] && echo "nameserver=$DNS1" > "$_dnsfile"
|
|
Coiby Xu |
f06949 |
[ -n "$DNS2" ] && echo "nameserver=$DNS2" >> "$_dnsfile"
|
|
Coiby Xu |
f06949 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
while read content;
|
|
Petr Šabata |
f5bf49 |
do
|
|
Petr Šabata |
f5bf49 |
_nameserver=$(echo $content | grep ^nameserver)
|
|
Petr Šabata |
f5bf49 |
[ -z "$_nameserver" ] && continue
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
_dns=$(echo $_nameserver | cut -d' ' -f2)
|
|
Petr Šabata |
f5bf49 |
[ -z "$_dns" ] && continue
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ ! -f $_dnsfile ] || [ ! $(cat $_dnsfile | grep -q $_dns) ]; then
|
|
Petr Šabata |
f5bf49 |
echo "nameserver=$_dns" >> "$_dnsfile"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
done < "/etc/resolv.conf"
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Coiby Xu |
54611c |
# $1: repeat times
|
|
Coiby Xu |
54611c |
# $2: string to be repeated
|
|
Coiby Xu |
54611c |
# $3: separator
|
|
Coiby Xu |
54611c |
repeatedly_join_str() {
|
|
Coiby Xu |
54611c |
local _count="$1"
|
|
Coiby Xu |
54611c |
local _str="$2"
|
|
Coiby Xu |
54611c |
local _separator="$3"
|
|
Coiby Xu |
54611c |
local i _res
|
|
Coiby Xu |
54611c |
|
|
Coiby Xu |
54611c |
if [[ "$_count" -le 0 ]]; then
|
|
Coiby Xu |
54611c |
echo -n ""
|
|
Coiby Xu |
54611c |
return
|
|
Coiby Xu |
54611c |
fi
|
|
Coiby Xu |
54611c |
|
|
Coiby Xu |
54611c |
i=0
|
|
Coiby Xu |
54611c |
_res="$_str"
|
|
Coiby Xu |
54611c |
((_count--))
|
|
Coiby Xu |
54611c |
|
|
Coiby Xu |
54611c |
while [[ "$i" -lt "$_count" ]]; do
|
|
Coiby Xu |
54611c |
((i++))
|
|
Coiby Xu |
54611c |
_res="${_res}${_separator}${_str}"
|
|
Coiby Xu |
54611c |
done
|
|
Coiby Xu |
54611c |
echo -n "$_res"
|
|
Coiby Xu |
54611c |
}
|
|
Coiby Xu |
54611c |
|
|
Coiby Xu |
54611c |
# $1: prefix
|
|
Coiby Xu |
54611c |
# $2: ipv6_flag="-6" indicates it's IPv6
|
|
Coiby Xu |
54611c |
# Given a prefix, calculate the netmask (equivalent of "ipcalc -m")
|
|
Coiby Xu |
54611c |
# by concatenating three parts,
|
|
Coiby Xu |
54611c |
# 1) the groups with all bits set 1
|
|
Coiby Xu |
54611c |
# 2) a group with partial bits set to 0
|
|
Coiby Xu |
54611c |
# 3) the groups with all bits set to 0
|
|
Coiby Xu |
54611c |
cal_netmask_by_prefix() {
|
|
Coiby Xu |
54611c |
local _prefix="$1"
|
|
Coiby Xu |
54611c |
local _ipv6_flag="$2" _ipv6
|
|
Coiby Xu |
54611c |
local _bits_per_octet=8
|
|
Coiby Xu |
54611c |
local _count _res _octets_per_group _octets_total _seperator _total_groups
|
|
Coiby Xu |
54611c |
local _max_group_value _max_group_value_repr _bits_per_group _tmp _zero_bits
|
|
Coiby Xu |
54611c |
|
|
Coiby Xu |
54611c |
if [[ "$_ipv6_flag" == "-6" ]]; then
|
|
Coiby Xu |
54611c |
_ipv6=1
|
|
Coiby Xu |
54611c |
else
|
|
Coiby Xu |
54611c |
_ipv6=0
|
|
Coiby Xu |
54611c |
fi
|
|
Coiby Xu |
54611c |
|
|
Coiby Xu |
54611c |
if [[ "$_prefix" -lt 0 || "$_prefix" -gt 128 ]] || \
|
|
Coiby Xu |
54611c |
( ((!_ipv6)) && [[ "$_prefix" -gt 32 ]] ); then
|
|
Coiby Xu |
54611c |
derror "Bad prefix:$_prefix for calculating netmask"
|
|
Coiby Xu |
54611c |
exit 1
|
|
Coiby Xu |
54611c |
fi
|
|
Coiby Xu |
54611c |
|
|
Coiby Xu |
54611c |
if ((_ipv6)); then
|
|
Coiby Xu |
54611c |
_octets_per_group=2
|
|
Coiby Xu |
54611c |
_octets_total=16
|
|
Coiby Xu |
54611c |
_seperator=":"
|
|
Coiby Xu |
54611c |
else
|
|
Coiby Xu |
54611c |
_octets_per_group=1
|
|
Coiby Xu |
54611c |
_octets_total=4
|
|
Coiby Xu |
54611c |
_seperator="."
|
|
Coiby Xu |
54611c |
fi
|
|
Coiby Xu |
54611c |
|
|
Coiby Xu |
54611c |
_total_groups=$((_octets_total/_octets_per_group))
|
|
Coiby Xu |
54611c |
_bits_per_group=$((_octets_per_group * _bits_per_octet))
|
|
Coiby Xu |
54611c |
_max_group_value=$(((1 << _bits_per_group) - 1))
|
|
Coiby Xu |
54611c |
|
|
Coiby Xu |
54611c |
if ((_ipv6)); then
|
|
Coiby Xu |
54611c |
_max_group_value_repr=$(printf "%x" $_max_group_value)
|
|
Coiby Xu |
54611c |
else
|
|
Coiby Xu |
54611c |
_max_group_value_repr="$_max_group_value"
|
|
Coiby Xu |
54611c |
fi
|
|
Coiby Xu |
54611c |
|
|
Coiby Xu |
54611c |
_count=$((_prefix/_octets_per_group/_bits_per_octet))
|
|
Coiby Xu |
54611c |
_first_part=$(repeatedly_join_str "$_count" "$_max_group_value_repr" "$_seperator")
|
|
Coiby Xu |
54611c |
_res="$_first_part"
|
|
Coiby Xu |
54611c |
|
|
Coiby Xu |
54611c |
_tmp=$((_octets_total*_bits_per_octet-_prefix))
|
|
Coiby Xu |
54611c |
_zero_bits=$(expr $_tmp % $_bits_per_group)
|
|
Coiby Xu |
54611c |
if [[ "$_zero_bits" -ne 0 ]]; then
|
|
Coiby Xu |
54611c |
_second_part=$((_max_group_value >> _zero_bits << _zero_bits))
|
|
Coiby Xu |
54611c |
if ((_ipv6)); then
|
|
Coiby Xu |
54611c |
_second_part=$(printf "%x" $_second_part)
|
|
Coiby Xu |
54611c |
fi
|
|
Coiby Xu |
54611c |
((_count++))
|
|
Coiby Xu |
54611c |
if [[ -z "$_first_part" ]]; then
|
|
Coiby Xu |
54611c |
_res="$_second_part"
|
|
Coiby Xu |
54611c |
else
|
|
Coiby Xu |
54611c |
_res="${_first_part}${_seperator}${_second_part}"
|
|
Coiby Xu |
54611c |
fi
|
|
Coiby Xu |
54611c |
fi
|
|
Coiby Xu |
54611c |
|
|
Coiby Xu |
54611c |
_count=$((_total_groups-_count))
|
|
Coiby Xu |
54611c |
if [[ "$_count" -eq 0 ]]; then
|
|
Coiby Xu |
54611c |
echo -n "$_res"
|
|
Coiby Xu |
54611c |
return
|
|
Coiby Xu |
54611c |
fi
|
|
Coiby Xu |
54611c |
|
|
Coiby Xu |
54611c |
if ((_ipv6)) && [[ "$_count" -gt 1 ]] ; then
|
|
Coiby Xu |
54611c |
# use condensed notion for IPv6
|
|
Coiby Xu |
54611c |
_third_part=":"
|
|
Coiby Xu |
54611c |
else
|
|
Coiby Xu |
54611c |
_third_part=$(repeatedly_join_str "$_count" "0" "$_seperator")
|
|
Coiby Xu |
54611c |
fi
|
|
Coiby Xu |
54611c |
|
|
Coiby Xu |
54611c |
if [[ -z "$_res" ]] && ((!_ipv6)) ; then
|
|
Coiby Xu |
54611c |
echo -n "${_third_part}"
|
|
Coiby Xu |
54611c |
else
|
|
Coiby Xu |
54611c |
echo -n "${_res}${_seperator}${_third_part}"
|
|
Coiby Xu |
54611c |
fi
|
|
Coiby Xu |
54611c |
}
|
|
Coiby Xu |
54611c |
|
|
Petr Šabata |
f5bf49 |
#$1: netdev name
|
|
Petr Šabata |
f5bf49 |
#$2: srcaddr
|
|
Petr Šabata |
f5bf49 |
#if it use static ip echo it, or echo null
|
|
Petr Šabata |
f5bf49 |
kdump_static_ip() {
|
|
Coiby Xu |
69c605 |
local _netdev="$1" _srcaddr="$2" kdumpnic="$3" _ipv6_flag
|
|
Coiby Xu |
54611c |
local _netmask _gateway _ipaddr _target _nexthop _prefix
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
_ipaddr=$(ip addr show dev $_netdev permanent | awk "/ $_srcaddr\/.* /{print \$2}")
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if is_ipv6_address $_srcaddr; then
|
|
Petr Šabata |
f5bf49 |
_ipv6_flag="-6"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ -n "$_ipaddr" ]; then
|
|
Petr Šabata |
f5bf49 |
_gateway=$(ip $_ipv6_flag route list dev $_netdev | \
|
|
Petr Šabata |
f5bf49 |
awk '/^default /{print $3}' | head -n 1)
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ "x" != "x"$_ipv6_flag ]; then
|
|
Petr Šabata |
f5bf49 |
# _ipaddr="2002::56ff:feb6:56d5/64", _netmask is the number after "/"
|
|
Petr Šabata |
f5bf49 |
_netmask=${_ipaddr#*\/}
|
|
Petr Šabata |
f5bf49 |
_srcaddr="[$_srcaddr]"
|
|
Petr Šabata |
f5bf49 |
_gateway="[$_gateway]"
|
|
Petr Šabata |
f5bf49 |
else
|
|
Coiby Xu |
54611c |
_prefix=$(cut -d'/' -f2 <<< "$_ipaddr")
|
|
Coiby Xu |
54611c |
_netmask=$(cal_netmask_by_prefix "$_prefix" "$_ipv6_flag")
|
|
Coiby Xu |
54611c |
if [[ "$?" -ne 0 ]]; then
|
|
Coiby Xu |
54611c |
derror "Failed to calculate netmask for $_ipaddr"
|
|
Coiby Xu |
54611c |
exit 1
|
|
Coiby Xu |
54611c |
fi
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
echo -n "${_srcaddr}::${_gateway}:${_netmask}::"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
/sbin/ip $_ipv6_flag route show | grep -v default |\
|
|
Petr Šabata |
f5bf49 |
grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" |\
|
|
Petr Šabata |
f5bf49 |
while read _route; do
|
|
Petr Šabata |
f5bf49 |
_target=`echo $_route | cut -d ' ' -f1`
|
|
Petr Šabata |
f5bf49 |
_nexthop=`echo $_route | cut -d ' ' -f3`
|
|
Petr Šabata |
f5bf49 |
if [ "x" != "x"$_ipv6_flag ]; then
|
|
Petr Šabata |
f5bf49 |
_target="[$_target]"
|
|
Petr Šabata |
f5bf49 |
_nexthop="[$_nexthop]"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Coiby Xu |
69c605 |
echo "rd.route=$_target:$_nexthop:$kdumpnic"
|
|
Petr Šabata |
f5bf49 |
done >> ${initdir}/etc/cmdline.d/45route-static.conf
|
|
Petr Šabata |
f5bf49 |
|
|
Coiby Xu |
69c605 |
kdump_handle_mulitpath_route $_netdev $_srcaddr $kdumpnic
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_handle_mulitpath_route() {
|
|
Coiby Xu |
69c605 |
local _netdev="$1" _srcaddr="$2" kdumpnic="$3" _ipv6_flag
|
|
Petr Šabata |
f5bf49 |
local _target _nexthop _route _weight _max_weight _rule
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if is_ipv6_address $_srcaddr; then
|
|
Petr Šabata |
f5bf49 |
_ipv6_flag="-6"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
while IFS="" read _route; do
|
|
Petr Šabata |
f5bf49 |
if [[ "$_route" =~ [[:space:]]+nexthop ]]; then
|
|
Petr Šabata |
f5bf49 |
_route=$(echo "$_route" | sed -e 's/^[[:space:]]*//')
|
|
Petr Šabata |
f5bf49 |
# Parse multipath route, using previous _target
|
|
Petr Šabata |
f5bf49 |
[[ "$_target" == 'default' ]] && continue
|
|
Petr Šabata |
f5bf49 |
[[ "$_route" =~ .*via.*\ $_netdev ]] || continue
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
_weight=`echo "$_route" | cut -d ' ' -f7`
|
|
Petr Šabata |
f5bf49 |
if [[ "$_weight" -gt "$_max_weight" ]]; then
|
|
Petr Šabata |
f5bf49 |
_nexthop=`echo "$_route" | cut -d ' ' -f3`
|
|
Petr Šabata |
f5bf49 |
_max_weight=$_weight
|
|
Petr Šabata |
f5bf49 |
if [ "x" != "x"$_ipv6_flag ]; then
|
|
Coiby Xu |
69c605 |
_rule="rd.route=[$_target]:[$_nexthop]:$kdumpnic"
|
|
Petr Šabata |
f5bf49 |
else
|
|
Coiby Xu |
69c605 |
_rule="rd.route=$_target:$_nexthop:$kdumpnic"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
[[ -n "$_rule" ]] && echo "$_rule"
|
|
Petr Šabata |
f5bf49 |
_target=`echo "$_route" | cut -d ' ' -f1`
|
|
Petr Šabata |
f5bf49 |
_rule="" _max_weight=0 _weight=0
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
done >> ${initdir}/etc/cmdline.d/45route-static.conf\
|
|
Petr Šabata |
f5bf49 |
<<< "$(/sbin/ip $_ipv6_flag route show)"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
[[ -n $_rule ]] && echo $_rule >> ${initdir}/etc/cmdline.d/45route-static.conf
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_get_mac_addr() {
|
|
Petr Šabata |
f5bf49 |
cat /sys/class/net/$1/address
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
#Bonding or team master modifies the mac address
|
|
Petr Šabata |
f5bf49 |
#of its slaves, we should use perm address
|
|
Petr Šabata |
f5bf49 |
kdump_get_perm_addr() {
|
|
Petr Šabata |
f5bf49 |
local addr=$(ethtool -P $1 | sed -e 's/Permanent address: //')
|
|
Petr Šabata |
f5bf49 |
if [ -z "$addr" ] || [ "$addr" = "00:00:00:00:00:00" ]
|
|
Petr Šabata |
f5bf49 |
then
|
|
Petr Šabata |
f5bf49 |
derror "Can't get the permanent address of $1"
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
echo "$addr"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Prefix kernel assigned names with "kdump-". EX: eth0 -> kdump-eth0
|
|
Petr Šabata |
f5bf49 |
# Because kernel assigned names are not persistent between 1st and 2nd
|
|
Petr Šabata |
f5bf49 |
# kernel. We could probably end up with eth0 being eth1, eth0 being
|
|
Petr Šabata |
f5bf49 |
# eth1, and naming conflict happens.
|
|
Petr Šabata |
f5bf49 |
kdump_setup_ifname() {
|
|
Petr Šabata |
f5bf49 |
local _ifname
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# If ifname already has 'kdump-' prefix, we must be switching from
|
|
Petr Šabata |
f5bf49 |
# fadump to kdump. Skip prefixing 'kdump-' in this case as adding
|
|
Petr Šabata |
f5bf49 |
# another prefix may truncate the ifname. Since an ifname with
|
|
Petr Šabata |
f5bf49 |
# 'kdump-' is already persistent, this should be fine.
|
|
Petr Šabata |
f5bf49 |
if [[ $1 =~ eth* ]] && [[ ! $1 =~ ^kdump-* ]]; then
|
|
Petr Šabata |
f5bf49 |
_ifname="kdump-$1"
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
_ifname="$1"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
echo "$_ifname"
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_setup_bridge() {
|
|
Petr Šabata |
f5bf49 |
local _netdev=$1
|
|
Petr Šabata |
f5bf49 |
local _brif _dev _mac _kdumpdev
|
|
Petr Šabata |
f5bf49 |
for _dev in `ls /sys/class/net/$_netdev/brif/`; do
|
|
Petr Šabata |
f5bf49 |
_kdumpdev=$_dev
|
|
Petr Šabata |
f5bf49 |
if kdump_is_bond "$_dev"; then
|
|
Coiby Xu |
c23189 |
$(kdump_setup_bond "$_dev" "$(get_nmcli_connection_show_cmd_by_ifname "$_dev")")
|
|
Coiby Xu |
c23189 |
if [[ $? != 0 ]]; then
|
|
Coiby Xu |
c23189 |
exit 1
|
|
Coiby Xu |
c23189 |
fi
|
|
Petr Šabata |
f5bf49 |
elif kdump_is_team "$_dev"; then
|
|
Petr Šabata |
f5bf49 |
kdump_setup_team "$_dev"
|
|
Petr Šabata |
f5bf49 |
elif kdump_is_vlan "$_dev"; then
|
|
Petr Šabata |
f5bf49 |
kdump_setup_vlan "$_dev"
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
_mac=$(kdump_get_mac_addr $_dev)
|
|
Petr Šabata |
f5bf49 |
_kdumpdev=$(kdump_setup_ifname $_dev)
|
|
Petr Šabata |
f5bf49 |
echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/41bridge.conf
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
_brif+="$_kdumpdev,"
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
echo " bridge=$_netdev:$(echo $_brif | sed -e 's/,$//')" >> ${initdir}/etc/cmdline.d/41bridge.conf
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Coiby Xu |
c23189 |
# drauct takes bond=<bondname>[:<bondslaves>:[:<options>]] syntax to parse
|
|
Coiby Xu |
c23189 |
# bond. For example:
|
|
Coiby Xu |
c23189 |
# bond=bond0:eth0,eth1:mode=balance-rr
|
|
Petr Šabata |
f5bf49 |
kdump_setup_bond() {
|
|
Coiby Xu |
c23189 |
local _netdev="$1"
|
|
Coiby Xu |
c23189 |
local _nm_show_cmd="$2"
|
|
Coiby Xu |
c23189 |
local _dev _mac _slaves _kdumpdev _bondoptions
|
|
Petr Šabata |
f5bf49 |
for _dev in `cat /sys/class/net/$_netdev/bonding/slaves`; do
|
|
Petr Šabata |
f5bf49 |
_mac=$(kdump_get_perm_addr $_dev)
|
|
Petr Šabata |
f5bf49 |
_kdumpdev=$(kdump_setup_ifname $_dev)
|
|
Petr Šabata |
f5bf49 |
echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf
|
|
Petr Šabata |
f5bf49 |
_slaves+="$_kdumpdev,"
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
echo -n " bond=$_netdev:$(echo $_slaves | sed 's/,$//')" >> ${initdir}/etc/cmdline.d/42bond.conf
|
|
Petr Šabata |
f5bf49 |
|
|
Coiby Xu |
c23189 |
_bondoptions=$(get_nmcli_value_by_field "$_nm_show_cmd" "bond.options")
|
|
Coiby Xu |
c23189 |
|
|
Coiby Xu |
c23189 |
if [[ -z "_bondoptions" ]]; then
|
|
Coiby Xu |
c23189 |
dwarning "Failed to get bond configuration via nmlci output. Now try sourcing ifcfg script."
|
|
Coiby Xu |
c23189 |
source_ifcfg_file $_netdev
|
|
Coiby Xu |
c23189 |
_bondoptions="$(echo $BONDING_OPTS | xargs echo | tr " " ",")"
|
|
Coiby Xu |
c23189 |
fi
|
|
Coiby Xu |
c23189 |
|
|
Coiby Xu |
c23189 |
if [[ -z "_bondoptions" ]]; then
|
|
Coiby Xu |
c23189 |
derror "Get empty bond options"
|
|
Coiby Xu |
c23189 |
exit 1
|
|
Coiby Xu |
c23189 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Coiby Xu |
c23189 |
echo ":$_bondoptions" >> ${initdir}/etc/cmdline.d/42bond.conf
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_setup_team() {
|
|
Petr Šabata |
f5bf49 |
local _netdev=$1
|
|
Petr Šabata |
f5bf49 |
local _dev _mac _slaves _kdumpdev
|
|
Petr Šabata |
f5bf49 |
for _dev in `teamnl $_netdev ports | awk -F':' '{print $2}'`; do
|
|
Petr Šabata |
f5bf49 |
_mac=$(kdump_get_perm_addr $_dev)
|
|
Petr Šabata |
f5bf49 |
_kdumpdev=$(kdump_setup_ifname $_dev)
|
|
Petr Šabata |
f5bf49 |
echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf
|
|
Petr Šabata |
f5bf49 |
_slaves+="$_kdumpdev,"
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
echo " team=$_netdev:$(echo $_slaves | sed -e 's/,$//')" >> ${initdir}/etc/cmdline.d/44team.conf
|
|
Petr Šabata |
f5bf49 |
#Buggy version teamdctl outputs to stderr!
|
|
Petr Šabata |
f5bf49 |
#Try to use the latest version of teamd.
|
|
Petr Šabata |
f5bf49 |
teamdctl "$_netdev" config dump > ${initdir}/tmp/$$-$_netdev.conf
|
|
Petr Šabata |
f5bf49 |
if [ $? -ne 0 ]
|
|
Petr Šabata |
f5bf49 |
then
|
|
Petr Šabata |
f5bf49 |
derror "teamdctl failed."
|
|
Petr Šabata |
f5bf49 |
exit 1
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
inst_dir /etc/teamd
|
|
Petr Šabata |
f5bf49 |
inst_simple ${initdir}/tmp/$$-$_netdev.conf "/etc/teamd/$_netdev.conf"
|
|
Petr Šabata |
f5bf49 |
rm -f ${initdir}/tmp/$$-$_netdev.conf
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_setup_vlan() {
|
|
Petr Šabata |
f5bf49 |
local _netdev=$1
|
|
Petr Šabata |
f5bf49 |
local _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")"
|
|
Petr Šabata |
f5bf49 |
local _netmac="$(kdump_get_mac_addr $_phydev)"
|
|
Petr Šabata |
f5bf49 |
local _kdumpdev
|
|
Petr Šabata |
f5bf49 |
|
|
DistroBaker |
a10140 |
#Just support vlan over bond and team
|
|
Petr Šabata |
f5bf49 |
if kdump_is_bridge "$_phydev"; then
|
|
Petr Šabata |
f5bf49 |
derror "Vlan over bridge is not supported!"
|
|
Petr Šabata |
f5bf49 |
exit 1
|
|
Petr Šabata |
f5bf49 |
elif kdump_is_bond "$_phydev"; then
|
|
Coiby Xu |
c23189 |
$(kdump_setup_bond "$_phydev" "$(get_nmcli_connection_show_cmd_by_ifname "$_phydev")")
|
|
Coiby Xu |
c23189 |
if [[ $? != 0 ]]; then
|
|
Coiby Xu |
c23189 |
exit 1
|
|
Coiby Xu |
c23189 |
fi
|
|
Petr Šabata |
f5bf49 |
echo " vlan=$(kdump_setup_ifname $_netdev):$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
_kdumpdev="$(kdump_setup_ifname $_phydev)"
|
|
Petr Šabata |
f5bf49 |
echo " vlan=$(kdump_setup_ifname $_netdev):$_kdumpdev ifname=$_kdumpdev:$_netmac" > ${initdir}/etc/cmdline.d/43vlan.conf
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# setup s390 znet cmdline
|
|
Coiby Xu |
d408ec |
# $1: netdev (ifname)
|
|
Coiby Xu |
d408ec |
# $2: nmcli connection show output
|
|
Petr Šabata |
f5bf49 |
kdump_setup_znet() {
|
|
Coiby Xu |
d408ec |
local _netdev="$1"
|
|
Coiby Xu |
d408ec |
local _nmcli_cmd="$2"
|
|
Coiby Xu |
d408ec |
local s390_prefix="802-3-ethernet.s390-"
|
|
Petr Šabata |
f5bf49 |
local _options=""
|
|
Coiby Xu |
d408ec |
local NETTYPE
|
|
Coiby Xu |
d408ec |
local SUBCHANNELS
|
|
Coiby Xu |
d408ec |
|
|
Coiby Xu |
d408ec |
NETTYPE=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}nettype")
|
|
Coiby Xu |
d408ec |
SUBCHANNELS=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}subchannels")
|
|
Coiby Xu |
d408ec |
_options=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}options")
|
|
Coiby Xu |
d408ec |
|
|
Coiby Xu |
d408ec |
if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then
|
|
Coiby Xu |
d408ec |
dwarning "Failed to get znet configuration via nmlci output. Now try sourcing ifcfg script."
|
|
Coiby Xu |
d408ec |
source_ifcfg_file $_netdev
|
|
Coiby Xu |
d408ec |
for i in $OPTIONS; do
|
|
Coiby Xu |
d408ec |
_options=${_options},$i
|
|
Coiby Xu |
d408ec |
done
|
|
Coiby Xu |
d408ec |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Coiby Xu |
d408ec |
if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then
|
|
Coiby Xu |
d408ec |
exit 1
|
|
Coiby Xu |
d408ec |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Coiby Xu |
d408ec |
echo rd.znet=${NETTYPE},${SUBCHANNELS},${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS} > ${initdir}/etc/cmdline.d/30znet.conf
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_get_ip_route()
|
|
Petr Šabata |
f5bf49 |
{
|
|
Petr Šabata |
f5bf49 |
local _route=$(/sbin/ip -o route get to $1 2>&1)
|
|
Petr Šabata |
f5bf49 |
[ $? != 0 ] && die "Bad kdump network destination: $1"
|
|
Petr Šabata |
f5bf49 |
echo $_route
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_get_ip_route_field()
|
|
Petr Šabata |
f5bf49 |
{
|
|
Petr Šabata |
f5bf49 |
if `echo $1 | grep -q $2`; then
|
|
Petr Šabata |
f5bf49 |
echo ${1##*$2} | cut -d ' ' -f1
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_get_remote_ip()
|
|
Petr Šabata |
f5bf49 |
{
|
|
Petr Šabata |
f5bf49 |
local _remote=$(get_remote_host $1) _remote_temp
|
|
Petr Šabata |
f5bf49 |
if is_hostname $_remote; then
|
|
Petr Šabata |
f5bf49 |
_remote_temp=`getent ahosts $_remote | grep -v : | head -n 1`
|
|
Petr Šabata |
f5bf49 |
if [ -z "$_remote_temp" ]; then
|
|
Petr Šabata |
f5bf49 |
_remote_temp=`getent ahosts $_remote | head -n 1`
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
_remote=`echo $_remote_temp | cut -d' ' -f1`
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
echo $_remote
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Setup dracut to bring up network interface that enable
|
|
Petr Šabata |
f5bf49 |
# initramfs accessing giving destination
|
|
Petr Šabata |
f5bf49 |
# $1: destination host
|
|
Petr Šabata |
f5bf49 |
kdump_install_net() {
|
|
Coiby Xu |
d408ec |
local _destaddr _srcaddr _route _netdev _nm_show_cmd kdumpnic
|
|
Petr Šabata |
f5bf49 |
local _static _proto _ip_conf _ip_opts _ifname_opts
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
_destaddr=$(kdump_get_remote_ip $1)
|
|
Petr Šabata |
f5bf49 |
_route=$(kdump_get_ip_route $_destaddr)
|
|
Petr Šabata |
f5bf49 |
_srcaddr=$(kdump_get_ip_route_field "$_route" "src")
|
|
Petr Šabata |
f5bf49 |
_netdev=$(kdump_get_ip_route_field "$_route" "dev")
|
|
Coiby Xu |
d408ec |
_nm_show_cmd=$(get_nmcli_connection_show_cmd_by_ifname "$_netdev")
|
|
Petr Šabata |
f5bf49 |
_netmac=$(kdump_get_mac_addr $_netdev)
|
|
Coiby Xu |
6a8e08 |
kdumpnic=$(kdump_setup_ifname $_netdev)
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ "$(uname -m)" = "s390x" ]; then
|
|
Coiby Xu |
d408ec |
$(kdump_setup_znet "$_netdev" "$_nm_show_cmd")
|
|
Coiby Xu |
d408ec |
if [[ $? != 0 ]]; then
|
|
Coiby Xu |
d408ec |
derror "Failed to set up znet"
|
|
Coiby Xu |
d408ec |
exit 1
|
|
Coiby Xu |
d408ec |
fi
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Coiby Xu |
69c605 |
_static=$(kdump_static_ip $_netdev $_srcaddr $kdumpnic)
|
|
Petr Šabata |
f5bf49 |
if [ -n "$_static" ]; then
|
|
Petr Šabata |
f5bf49 |
_proto=none
|
|
Petr Šabata |
f5bf49 |
elif is_ipv6_address $_srcaddr; then
|
|
DistroBaker |
7d0122 |
_proto=auto6
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
_proto=dhcp
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
_ip_conf="${initdir}/etc/cmdline.d/40ip.conf"
|
|
Coiby Xu |
6a8e08 |
_ip_opts=" ip=${_static}$kdumpnic:${_proto}"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# dracut doesn't allow duplicated configuration for same NIC, even they're exactly the same.
|
|
Petr Šabata |
f5bf49 |
# so we have to avoid adding duplicates
|
|
Petr Šabata |
f5bf49 |
# We should also check /proc/cmdline for existing ip=xx arg.
|
|
Petr Šabata |
f5bf49 |
# For example, iscsi boot will specify ip=xxx arg in cmdline.
|
|
Petr Šabata |
f5bf49 |
if [ ! -f $_ip_conf ] || ! grep -q $_ip_opts $_ip_conf &&\
|
|
Petr Šabata |
f5bf49 |
! grep -q "ip=[^[:space:]]*$_netdev" /proc/cmdline; then
|
|
Petr Šabata |
f5bf49 |
echo "$_ip_opts" >> $_ip_conf
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if kdump_is_bridge "$_netdev"; then
|
|
Petr Šabata |
f5bf49 |
kdump_setup_bridge "$_netdev"
|
|
Petr Šabata |
f5bf49 |
elif kdump_is_bond "$_netdev"; then
|
|
Coiby Xu |
c23189 |
$(kdump_setup_bond "$_netdev" "$_nm_show_cmd")
|
|
Coiby Xu |
c23189 |
if [[ $? != 0 ]]; then
|
|
Coiby Xu |
c23189 |
exit 1
|
|
Coiby Xu |
c23189 |
fi
|
|
Petr Šabata |
f5bf49 |
elif kdump_is_team "$_netdev"; then
|
|
Petr Šabata |
f5bf49 |
kdump_setup_team "$_netdev"
|
|
Petr Šabata |
f5bf49 |
elif kdump_is_vlan "$_netdev"; then
|
|
Petr Šabata |
f5bf49 |
kdump_setup_vlan "$_netdev"
|
|
Petr Šabata |
f5bf49 |
else
|
|
Coiby Xu |
6a8e08 |
_ifname_opts=" ifname=$kdumpnic:$_netmac"
|
|
Petr Šabata |
f5bf49 |
echo "$_ifname_opts" >> $_ip_conf
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Coiby Xu |
f06949 |
kdump_setup_dns "$_netdev" "$_nm_show_cmd"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ ! -f ${initdir}/etc/cmdline.d/50neednet.conf ]; then
|
|
Petr Šabata |
f5bf49 |
# network-manager module needs this parameter
|
|
Petr Šabata |
f5bf49 |
echo "rd.neednet" >> ${initdir}/etc/cmdline.d/50neednet.conf
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Save netdev used for kdump as cmdline
|
|
Petr Šabata |
f5bf49 |
# Whoever calling kdump_install_net() is setting up the default gateway,
|
|
Petr Šabata |
f5bf49 |
# ie. bootdev/kdumpnic. So don't override the setting if calling
|
|
Petr Šabata |
f5bf49 |
# kdump_install_net() for another time. For example, after setting eth0 as
|
|
Petr Šabata |
f5bf49 |
# the default gate way for network dump, eth1 in the fence kdump path will
|
|
Petr Šabata |
f5bf49 |
# call kdump_install_net again and we don't want eth1 to be the default
|
|
Petr Šabata |
f5bf49 |
# gateway.
|
|
Petr Šabata |
f5bf49 |
if [ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ] &&
|
|
Petr Šabata |
f5bf49 |
[ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]; then
|
|
Coiby Xu |
6a8e08 |
echo "kdumpnic=$kdumpnic" > ${initdir}/etc/cmdline.d/60kdumpnic.conf
|
|
Coiby Xu |
6a8e08 |
echo "bootdev=$kdumpnic" > ${initdir}/etc/cmdline.d/70bootdev.conf
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# install etc/kdump/pre.d and /etc/kdump/post.d
|
|
Petr Šabata |
f5bf49 |
kdump_install_pre_post_conf() {
|
|
Petr Šabata |
f5bf49 |
if [ -d /etc/kdump/pre.d ]; then
|
|
Petr Šabata |
f5bf49 |
for file in /etc/kdump/pre.d/*; do
|
|
Petr Šabata |
f5bf49 |
if [ -x "$file" ]; then
|
|
Petr Šabata |
f5bf49 |
dracut_install $file
|
|
Petr Šabata |
f5bf49 |
elif [ $file != "/etc/kdump/pre.d/*" ]; then
|
|
Petr Šabata |
f5bf49 |
echo "$file is not executable"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ -d /etc/kdump/post.d ]; then
|
|
Petr Šabata |
f5bf49 |
for file in /etc/kdump/post.d/*; do
|
|
Petr Šabata |
f5bf49 |
if [ -x "$file" ]; then
|
|
Petr Šabata |
f5bf49 |
dracut_install $file
|
|
Petr Šabata |
f5bf49 |
elif [ $file != "/etc/kdump/post.d/*" ]; then
|
|
Petr Šabata |
f5bf49 |
echo "$file is not executable"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
default_dump_target_install_conf()
|
|
Petr Šabata |
f5bf49 |
{
|
|
Petr Šabata |
f5bf49 |
local _target _fstype
|
|
Petr Šabata |
f5bf49 |
local _mntpoint _save_path
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
is_user_configured_dump_target && return
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
_save_path=$(get_bind_mount_source $(get_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 |
_fstype=$(get_fs_type_from_target $_target)
|
|
Petr Šabata |
f5bf49 |
if is_fs_type_nfs $_fstype; then
|
|
Petr Šabata |
f5bf49 |
kdump_install_net "$_target"
|
|
Petr Šabata |
f5bf49 |
_fstype="nfs"
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
_target=$(kdump_get_persistent_dev $_target)
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
echo "$_fstype $_target" >> ${initdir}/tmp/$$-kdump.conf
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# don't touch the path under root mount
|
|
Petr Šabata |
f5bf49 |
if [ "$_mntpoint" != "/" ]; then
|
|
Petr Šabata |
f5bf49 |
_save_path=${_save_path##"$_mntpoint"}
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
#erase the old path line, then insert the parsed path
|
|
Petr Šabata |
f5bf49 |
sed -i "/^path/d" ${initdir}/tmp/$$-kdump.conf
|
|
Petr Šabata |
f5bf49 |
echo "path $_save_path" >> ${initdir}/tmp/$$-kdump.conf
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
#install kdump.conf and what user specifies in kdump.conf
|
|
Petr Šabata |
f5bf49 |
kdump_install_conf() {
|
|
Petr Šabata |
f5bf49 |
local _opt _val _pdev
|
|
Petr Šabata |
f5bf49 |
(read_strip_comments /etc/kdump.conf) > ${initdir}/tmp/$$-kdump.conf
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
while read _opt _val;
|
|
Petr Šabata |
f5bf49 |
do
|
|
Petr Šabata |
f5bf49 |
# remove inline comments after the end of a directive.
|
|
Petr Šabata |
f5bf49 |
case "$_opt" in
|
|
Petr Šabata |
f5bf49 |
raw)
|
|
Petr Šabata |
f5bf49 |
_pdev=$(persistent_policy="by-id" kdump_get_persistent_dev $_val)
|
|
Petr Šabata |
f5bf49 |
sed -i -e "s#^$_opt[[:space:]]\+$_val#$_opt $_pdev#" ${initdir}/tmp/$$-kdump.conf
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
ext[234]|xfs|btrfs|minix)
|
|
Petr Šabata |
f5bf49 |
_pdev=$(kdump_get_persistent_dev $_val)
|
|
Petr Šabata |
f5bf49 |
sed -i -e "s#^$_opt[[:space:]]\+$_val#$_opt $_pdev#" ${initdir}/tmp/$$-kdump.conf
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
ssh|nfs)
|
|
Petr Šabata |
f5bf49 |
kdump_install_net "$_val"
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
dracut_args)
|
|
Petr Šabata |
f5bf49 |
if [[ $(get_dracut_args_fstype "$_val") = nfs* ]] ; then
|
|
Petr Šabata |
f5bf49 |
kdump_install_net "$(get_dracut_args_target "$_val")"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
kdump_pre|kdump_post|extra_bins)
|
|
Petr Šabata |
f5bf49 |
dracut_install $_val
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
core_collector)
|
|
Petr Šabata |
f5bf49 |
dracut_install "${_val%%[[:blank:]]*}"
|
|
Petr Šabata |
f5bf49 |
;;
|
|
Petr Šabata |
f5bf49 |
esac
|
|
Petr Šabata |
f5bf49 |
done <<< "$(read_strip_comments /etc/kdump.conf)"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_install_pre_post_conf
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
default_dump_target_install_conf
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_configure_fence_kdump "${initdir}/tmp/$$-kdump.conf"
|
|
Petr Šabata |
f5bf49 |
inst "${initdir}/tmp/$$-kdump.conf" "/etc/kdump.conf"
|
|
Petr Šabata |
f5bf49 |
rm -f ${initdir}/tmp/$$-kdump.conf
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Remove user custom configurations sysctl.conf & sysctl.d/*
|
|
Petr Šabata |
f5bf49 |
# and apply some optimization for kdump
|
|
Petr Šabata |
f5bf49 |
overwrite_sysctl_conf() {
|
|
Petr Šabata |
f5bf49 |
# As custom configurations like vm.min_free_kbytes can lead
|
|
Petr Šabata |
f5bf49 |
# to OOM issues in kdump kernel, avoid them
|
|
Petr Šabata |
f5bf49 |
rm -f "${initdir}/etc/sysctl.conf"
|
|
Petr Šabata |
f5bf49 |
rm -rf "${initdir}/etc/sysctl.d"
|
|
Petr Šabata |
f5bf49 |
rm -rf "${initdir}/run/sysctl.d"
|
|
Petr Šabata |
f5bf49 |
rm -rf "${initdir}/usr/lib/sysctl.d"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
mkdir -p "${initdir}/etc/sysctl.d"
|
|
Petr Šabata |
f5bf49 |
echo "vm.zone_reclaim_mode = 3" > "${initdir}/etc/sysctl.d/99-zone-reclaim.conf"
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_iscsi_get_rec_val() {
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
local result
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# The open-iscsi 742 release changed to using flat files in
|
|
Petr Šabata |
f5bf49 |
# /var/lib/iscsi.
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
result=$(/sbin/iscsiadm --show -m session -r ${1} | grep "^${2} = ")
|
|
Petr Šabata |
f5bf49 |
result=${result##* = }
|
|
Petr Šabata |
f5bf49 |
echo $result
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_get_iscsi_initiator() {
|
|
Petr Šabata |
f5bf49 |
local _initiator
|
|
Petr Šabata |
f5bf49 |
local initiator_conf="/etc/iscsi/initiatorname.iscsi"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
[ -f "$initiator_conf" ] || return 1
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
while read _initiator; do
|
|
Petr Šabata |
f5bf49 |
[ -z "${_initiator%%#*}" ] && continue # Skip comment lines
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
case $_initiator in
|
|
Petr Šabata |
f5bf49 |
InitiatorName=*)
|
|
Petr Šabata |
f5bf49 |
initiator=${_initiator#InitiatorName=}
|
|
Petr Šabata |
f5bf49 |
echo "rd.iscsi.initiator=${initiator}"
|
|
Petr Šabata |
f5bf49 |
return 0;;
|
|
Petr Šabata |
f5bf49 |
*) ;;
|
|
Petr Šabata |
f5bf49 |
esac
|
|
Petr Šabata |
f5bf49 |
done < ${initiator_conf}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
return 1
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Figure out iBFT session according to session type
|
|
Petr Šabata |
f5bf49 |
is_ibft() {
|
|
Petr Šabata |
f5bf49 |
[ "$(kdump_iscsi_get_rec_val $1 "node.discovery_type")" = fw ]
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_setup_iscsi_device() {
|
|
Petr Šabata |
f5bf49 |
local path=$1
|
|
Petr Šabata |
f5bf49 |
local tgt_name; local tgt_ipaddr;
|
|
Petr Šabata |
f5bf49 |
local username; local password; local userpwd_str;
|
|
Petr Šabata |
f5bf49 |
local username_in; local password_in; local userpwd_in_str;
|
|
Petr Šabata |
f5bf49 |
local netroot_str ; local initiator_str;
|
|
Petr Šabata |
f5bf49 |
local netroot_conf="${initdir}/etc/cmdline.d/50iscsi.conf"
|
|
Petr Šabata |
f5bf49 |
local initiator_conf="/etc/iscsi/initiatorname.iscsi"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
dinfo "Found iscsi component $1"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Check once before getting explicit values, so we can bail out early,
|
|
Petr Šabata |
f5bf49 |
# e.g. in case of pure-hardware(all-offload) iscsi.
|
|
Petr Šabata |
f5bf49 |
if ! /sbin/iscsiadm -m session -r ${path} &>/dev/null ; then
|
|
Petr Šabata |
f5bf49 |
return 1
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if is_ibft ${path}; then
|
|
Petr Šabata |
f5bf49 |
return
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Remove software iscsi cmdline generated by 95iscsi,
|
|
Petr Šabata |
f5bf49 |
# and let kdump regenerate here.
|
|
Petr Šabata |
f5bf49 |
rm -f ${initdir}/etc/cmdline.d/95iscsi.conf
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
tgt_name=$(kdump_iscsi_get_rec_val ${path} "node.name")
|
|
Petr Šabata |
f5bf49 |
tgt_ipaddr=$(kdump_iscsi_get_rec_val ${path} "node.conn\[0\].address")
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# get and set username and password details
|
|
Petr Šabata |
f5bf49 |
username=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.username")
|
|
Petr Šabata |
f5bf49 |
[ "$username" == "<empty>" ] && username=""
|
|
Petr Šabata |
f5bf49 |
password=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.password")
|
|
Petr Šabata |
f5bf49 |
[ "$password" == "<empty>" ] && password=""
|
|
Petr Šabata |
f5bf49 |
username_in=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.username_in")
|
|
Petr Šabata |
f5bf49 |
[ -n "$username" ] && userpwd_str="$username:$password"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# get and set incoming username and password details
|
|
Petr Šabata |
f5bf49 |
[ "$username_in" == "<empty>" ] && username_in=""
|
|
Petr Šabata |
f5bf49 |
password_in=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.password_in")
|
|
Petr Šabata |
f5bf49 |
[ "$password_in" == "<empty>" ] && password_in=""
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
[ -n "$username_in" ] && userpwd_in_str=":$username_in:$password_in"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_install_net "$tgt_ipaddr"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# prepare netroot= command line
|
|
Petr Šabata |
f5bf49 |
# FIXME: Do we need to parse and set other parameters like protocol, port
|
|
Petr Šabata |
f5bf49 |
# iscsi_iface_name, netdev_name, LUN etc.
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if is_ipv6_address $tgt_ipaddr; then
|
|
Petr Šabata |
f5bf49 |
tgt_ipaddr="[$tgt_ipaddr]"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
netroot_str="netroot=iscsi:${userpwd_str}${userpwd_in_str}@$tgt_ipaddr::::$tgt_name"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
[[ -f $netroot_conf ]] || touch $netroot_conf
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# If netroot target does not exist already, append.
|
|
Petr Šabata |
f5bf49 |
if ! grep -q $netroot_str $netroot_conf; then
|
|
Petr Šabata |
f5bf49 |
echo $netroot_str >> $netroot_conf
|
|
Petr Šabata |
f5bf49 |
dinfo "Appended $netroot_str to $netroot_conf"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Setup initator
|
|
Petr Šabata |
f5bf49 |
initiator_str=$(kdump_get_iscsi_initiator)
|
|
Petr Šabata |
f5bf49 |
[ $? -ne "0" ] && derror "Failed to get initiator name" && return 1
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# If initiator details do not exist already, append.
|
|
Petr Šabata |
f5bf49 |
if ! grep -q "$initiator_str" $netroot_conf; then
|
|
Petr Šabata |
f5bf49 |
echo "$initiator_str" >> $netroot_conf
|
|
Petr Šabata |
f5bf49 |
dinfo "Appended "$initiator_str" to $netroot_conf"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_check_iscsi_targets () {
|
|
Petr Šabata |
f5bf49 |
# If our prerequisites are not met, fail anyways.
|
|
Petr Šabata |
f5bf49 |
type -P iscsistart >/dev/null || return 1
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_check_setup_iscsi() (
|
|
Petr Šabata |
f5bf49 |
local _dev
|
|
Petr Šabata |
f5bf49 |
_dev=$1
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
[[ -L /sys/dev/block/$_dev ]] || return
|
|
Petr Šabata |
f5bf49 |
cd "$(readlink -f /sys/dev/block/$_dev)"
|
|
Petr Šabata |
f5bf49 |
until [[ -d sys || -d iscsi_session ]]; do
|
|
Petr Šabata |
f5bf49 |
cd ..
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
[[ -d iscsi_session ]] && kdump_setup_iscsi_device "$PWD"
|
|
Petr Šabata |
f5bf49 |
)
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
[[ $hostonly ]] || [[ $mount_needs ]] && {
|
|
Petr Šabata |
f5bf49 |
for_each_host_dev_and_slaves_all kdump_check_setup_iscsi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# hostname -a is deprecated, do it by ourself
|
|
Petr Šabata |
f5bf49 |
get_alias() {
|
|
Petr Šabata |
f5bf49 |
local ips
|
|
Petr Šabata |
f5bf49 |
local entries
|
|
Petr Šabata |
f5bf49 |
local alias_set
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
ips=$(hostname -I)
|
|
Petr Šabata |
f5bf49 |
for ip in $ips
|
|
Petr Šabata |
f5bf49 |
do
|
|
Petr Šabata |
f5bf49 |
# in /etc/hosts, alias can come at the 2nd column
|
|
Petr Šabata |
f5bf49 |
entries=$(grep $ip /etc/hosts | awk '{ $1=""; print $0 }')
|
|
Petr Šabata |
f5bf49 |
if [ $? -eq 0 ]; then
|
|
Petr Šabata |
f5bf49 |
alias_set="$alias_set $entries"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
echo $alias_set
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
is_localhost() {
|
|
Petr Šabata |
f5bf49 |
local hostnames=$(hostname -A)
|
|
Petr Šabata |
f5bf49 |
local shortnames=$(hostname -A -s)
|
|
Petr Šabata |
f5bf49 |
local aliasname=$(get_alias)
|
|
Petr Šabata |
f5bf49 |
local nodename=$1
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
hostnames="$hostnames $shortnames $aliasname"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
for name in ${hostnames}; do
|
|
Petr Šabata |
f5bf49 |
if [ "$name" == "$nodename" ]; then
|
|
Petr Šabata |
f5bf49 |
return 0
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
return 1
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# retrieves fence_kdump nodes from Pacemaker cluster configuration
|
|
Petr Šabata |
f5bf49 |
get_pcs_fence_kdump_nodes() {
|
|
Petr Šabata |
f5bf49 |
local nodes
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
pcs cluster sync > /dev/null 2>&1 && pcs cluster cib-upgrade > /dev/null 2>&1
|
|
Petr Šabata |
f5bf49 |
# get cluster nodes from cluster cib, get interface and ip address
|
|
Petr Šabata |
f5bf49 |
nodelist=`pcs cluster cib | xmllint --xpath "/cib/status/node_state/@uname" -`
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# nodelist is formed as 'uname="node1" uname="node2" ... uname="nodeX"'
|
|
Petr Šabata |
f5bf49 |
# we need to convert each to node1, node2 ... nodeX in each iteration
|
|
Petr Šabata |
f5bf49 |
for node in ${nodelist}; do
|
|
Petr Šabata |
f5bf49 |
# convert $node from 'uname="nodeX"' to 'nodeX'
|
|
Petr Šabata |
f5bf49 |
eval $node
|
|
Petr Šabata |
f5bf49 |
nodename=$uname
|
|
Petr Šabata |
f5bf49 |
# Skip its own node name
|
|
Petr Šabata |
f5bf49 |
if is_localhost $nodename; then
|
|
Petr Šabata |
f5bf49 |
continue
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
nodes="$nodes $nodename"
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
echo $nodes
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# retrieves fence_kdump args from config file
|
|
Petr Šabata |
f5bf49 |
get_pcs_fence_kdump_args() {
|
|
Petr Šabata |
f5bf49 |
if [ -f $FENCE_KDUMP_CONFIG_FILE ]; then
|
|
Petr Šabata |
f5bf49 |
. $FENCE_KDUMP_CONFIG_FILE
|
|
Petr Šabata |
f5bf49 |
echo $FENCE_KDUMP_OPTS
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
get_generic_fence_kdump_nodes() {
|
|
Petr Šabata |
f5bf49 |
local filtered
|
|
Petr Šabata |
f5bf49 |
local nodes
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
nodes=$(get_option_value "fence_kdump_nodes")
|
|
Petr Šabata |
f5bf49 |
for node in ${nodes}; do
|
|
Petr Šabata |
f5bf49 |
# Skip its own node name
|
|
Petr Šabata |
f5bf49 |
if is_localhost $node; then
|
|
Petr Šabata |
f5bf49 |
continue
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
filtered="$filtered $node"
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
echo $filtered
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# setup fence_kdump in cluster
|
|
Petr Šabata |
f5bf49 |
# setup proper network and install needed files
|
|
Petr Šabata |
f5bf49 |
kdump_configure_fence_kdump () {
|
|
Petr Šabata |
f5bf49 |
local kdump_cfg_file=$1
|
|
Petr Šabata |
f5bf49 |
local nodes
|
|
Petr Šabata |
f5bf49 |
local args
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if is_generic_fence_kdump; then
|
|
Petr Šabata |
f5bf49 |
nodes=$(get_generic_fence_kdump_nodes)
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
elif is_pcs_fence_kdump; then
|
|
Petr Šabata |
f5bf49 |
nodes=$(get_pcs_fence_kdump_nodes)
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# set appropriate options in kdump.conf
|
|
Petr Šabata |
f5bf49 |
echo "fence_kdump_nodes $nodes" >> ${kdump_cfg_file}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
args=$(get_pcs_fence_kdump_args)
|
|
Petr Šabata |
f5bf49 |
if [ -n "$args" ]; then
|
|
Petr Šabata |
f5bf49 |
echo "fence_kdump_args $args" >> ${kdump_cfg_file}
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
# fence_kdump not configured
|
|
Petr Šabata |
f5bf49 |
return 1
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# setup network for each node
|
|
Petr Šabata |
f5bf49 |
for node in ${nodes}; do
|
|
Petr Šabata |
f5bf49 |
kdump_install_net $node
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
dracut_install /etc/hosts
|
|
Petr Šabata |
f5bf49 |
dracut_install /etc/nsswitch.conf
|
|
Petr Šabata |
f5bf49 |
dracut_install $FENCE_KDUMP_SEND
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Install a random seed used to feed /dev/urandom
|
|
Petr Šabata |
f5bf49 |
# By the time kdump service starts, /dev/uramdom is already fed by systemd
|
|
Petr Šabata |
f5bf49 |
kdump_install_random_seed() {
|
|
Petr Šabata |
f5bf49 |
local poolsize=`cat /proc/sys/kernel/random/poolsize`
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ ! -d ${initdir}/var/lib/ ]; then
|
|
Petr Šabata |
f5bf49 |
mkdir -p ${initdir}/var/lib/
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
dd if=/dev/urandom of=${initdir}/var/lib/random-seed \
|
|
Petr Šabata |
f5bf49 |
bs=$poolsize count=1 2> /dev/null
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_install_systemd_conf() {
|
|
Petr Šabata |
f5bf49 |
local failure_action=$(get_option_value "failure_action")
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Kdump turns out to require longer default systemd mount timeout
|
|
Petr Šabata |
f5bf49 |
# than 1st kernel(90s by default), we use default 300s for kdump.
|
|
Petr Šabata |
f5bf49 |
grep -r "^[[:space:]]*DefaultTimeoutStartSec=" ${initdir}/etc/systemd/system.conf* &>/dev/null
|
|
Petr Šabata |
f5bf49 |
if [ $? -ne 0 ]; then
|
|
Petr Šabata |
f5bf49 |
mkdir -p ${initdir}/etc/systemd/system.conf.d
|
|
Petr Šabata |
f5bf49 |
echo "[Manager]" > ${initdir}/etc/systemd/system.conf.d/kdump.conf
|
|
Petr Šabata |
f5bf49 |
echo "DefaultTimeoutStartSec=300s" >> ${initdir}/etc/systemd/system.conf.d/kdump.conf
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
DistroBaker |
5cac7c |
# Forward logs to console directly, and don't read Kmsg, this avoids
|
|
DistroBaker |
5cac7c |
# unneccessary memory consumption and make console output more useful.
|
|
Petr Šabata |
f5bf49 |
# Only do so for non fadump image.
|
|
DistroBaker |
624a64 |
mkdir -p ${initdir}/etc/systemd/journald.conf.d
|
|
DistroBaker |
624a64 |
echo "[Journal]" > ${initdir}/etc/systemd/journald.conf.d/kdump.conf
|
|
DistroBaker |
624a64 |
echo "Storage=volatile" >> ${initdir}/etc/systemd/journald.conf.d/kdump.conf
|
|
DistroBaker |
624a64 |
echo "ReadKMsg=no" >> ${initdir}/etc/systemd/journald.conf.d/kdump.conf
|
|
DistroBaker |
624a64 |
echo "ForwardToConsole=yes" >> ${initdir}/etc/systemd/journald.conf.d/kdump.conf
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
install() {
|
|
DistroBaker |
624a64 |
kdump_module_init
|
|
Petr Šabata |
f5bf49 |
kdump_install_conf
|
|
Petr Šabata |
f5bf49 |
overwrite_sysctl_conf
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if is_ssh_dump_target; then
|
|
Petr Šabata |
f5bf49 |
kdump_install_random_seed
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
dracut_install -o /etc/adjtime /etc/localtime
|
|
Petr Šabata |
f5bf49 |
inst "$moddir/monitor_dd_progress" "/kdumpscripts/monitor_dd_progress"
|
|
Petr Šabata |
f5bf49 |
chmod +x ${initdir}/kdumpscripts/monitor_dd_progress
|
|
Petr Šabata |
f5bf49 |
inst "/bin/dd" "/bin/dd"
|
|
Petr Šabata |
f5bf49 |
inst "/bin/tail" "/bin/tail"
|
|
Petr Šabata |
f5bf49 |
inst "/bin/date" "/bin/date"
|
|
Petr Šabata |
f5bf49 |
inst "/bin/sync" "/bin/sync"
|
|
Petr Šabata |
f5bf49 |
inst "/bin/cut" "/bin/cut"
|
|
Petr Šabata |
f5bf49 |
inst "/bin/head" "/bin/head"
|
|
Petr Šabata |
f5bf49 |
inst "/bin/awk" "/bin/awk"
|
|
Petr Šabata |
f5bf49 |
inst "/bin/sed" "/bin/sed"
|
|
Petr Šabata |
f5bf49 |
inst "/sbin/makedumpfile" "/sbin/makedumpfile"
|
|
Petr Šabata |
f5bf49 |
inst "/sbin/vmcore-dmesg" "/sbin/vmcore-dmesg"
|
|
DistroBaker |
5cac7c |
inst "/usr/bin/printf" "/sbin/printf"
|
|
DistroBaker |
5cac7c |
inst "/usr/bin/logger" "/sbin/logger"
|
|
|
337158 |
inst "/usr/bin/chmod" "/sbin/chmod"
|
|
Petr Šabata |
f5bf49 |
inst "/lib/kdump/kdump-lib.sh" "/lib/kdump-lib.sh"
|
|
Petr Šabata |
f5bf49 |
inst "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump-lib-initramfs.sh"
|
|
DistroBaker |
5cac7c |
inst "/lib/kdump/kdump-logger.sh" "/lib/kdump-logger.sh"
|
|
Petr Šabata |
f5bf49 |
inst "$moddir/kdump.sh" "/usr/bin/kdump.sh"
|
|
Petr Šabata |
f5bf49 |
inst "$moddir/kdump-capture.service" "$systemdsystemunitdir/kdump-capture.service"
|
|
DistroBaker |
7d0122 |
systemctl -q --root "$initdir" add-wants initrd.target kdump-capture.service
|
|
Petr Šabata |
f5bf49 |
inst "$moddir/kdump-error-handler.sh" "/usr/bin/kdump-error-handler.sh"
|
|
Petr Šabata |
f5bf49 |
inst "$moddir/kdump-error-handler.service" "$systemdsystemunitdir/kdump-error-handler.service"
|
|
Petr Šabata |
f5bf49 |
# Replace existing emergency service and emergency target
|
|
Petr Šabata |
f5bf49 |
cp "$moddir/kdump-emergency.service" "$initdir/$systemdsystemunitdir/emergency.service"
|
|
Petr Šabata |
f5bf49 |
cp "$moddir/kdump-emergency.target" "$initdir/$systemdsystemunitdir/emergency.target"
|
|
Petr Šabata |
f5bf49 |
# Also redirect dracut-emergency to kdump error handler
|
|
Petr Šabata |
f5bf49 |
ln_r "$systemdsystemunitdir/emergency.service" "$systemdsystemunitdir/dracut-emergency.service"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Check for all the devices and if any device is iscsi, bring up iscsi
|
|
Petr Šabata |
f5bf49 |
# target. Ideally all this should be pushed into dracut iscsi module
|
|
Petr Šabata |
f5bf49 |
# at some point of time.
|
|
Petr Šabata |
f5bf49 |
kdump_check_iscsi_targets
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
kdump_install_systemd_conf
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# nfs/ssh dump will need to get host ip in second kernel and need to call 'ip' tool, see get_host_ip for more detail
|
|
Petr Šabata |
f5bf49 |
if is_nfs_dump_target || is_ssh_dump_target; then
|
|
Petr Šabata |
f5bf49 |
inst "ip"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# For the lvm type target under kdump, in /etc/lvm/lvm.conf we can
|
|
Petr Šabata |
f5bf49 |
# safely replace "reserved_memory=XXXX"(default value is 8192) with
|
|
Petr Šabata |
f5bf49 |
# "reserved_memory=1024" to lower memory pressure under kdump. We do
|
|
Petr Šabata |
f5bf49 |
# it unconditionally here, if "/etc/lvm/lvm.conf" doesn't exist, it
|
|
Petr Šabata |
f5bf49 |
# actually does nothing.
|
|
Petr Šabata |
f5bf49 |
sed -i -e \
|
|
Petr Šabata |
f5bf49 |
's/\(^[[:space:]]*reserved_memory[[:space:]]*=\)[[:space:]]*[[:digit:]]*/\1 1024/' \
|
|
Petr Šabata |
f5bf49 |
${initdir}/etc/lvm/lvm.conf &>/dev/null
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Save more memory by dropping switch root capability
|
|
Petr Šabata |
f5bf49 |
if ! is_fadump_capable; then
|
|
Petr Šabata |
f5bf49 |
dracut_no_switch_root
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|