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