Pingfan Liu aa204a
#!/bin/bash
Pingfan Liu aa204a
# $1: target arch
Pingfan Liu aa204a
Pingfan Liu aa204a
SED_EXP=""
Pingfan Liu aa204a
Pingfan Liu aa204a
generate()
Pingfan Liu aa204a
{
Pingfan Liu aa204a
	sed "$SED_EXP" << EOF
Petr Šabata f5bf49
# This file contains a series of commands to perform (in order) in the kdump
Petr Šabata f5bf49
# kernel after a kernel crash in the crash kernel(1st kernel) has happened.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# Directives in this file are only applicable to the kdump initramfs, and have
Petr Šabata f5bf49
# no effect once the root filesystem is mounted and the normal init scripts are
Petr Šabata f5bf49
# processed.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# Currently, only one dump target and path can be specified.  If the dumping to
Petr Šabata f5bf49
# the configured target fails, the failure action which can be configured via
Petr Šabata f5bf49
# the "failure_action" directive will be performed.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# Supported options:
Petr Šabata f5bf49
#
Coiby Xu 7ac560
# auto_reset_crashkernel <yes|no>
Coiby Xu 7ac560
#           - whether to reset kernel crashkernel to new default value
Coiby Xu 7ac560
#             or not when kexec-tools updates the default crashkernel value and
Coiby Xu 7ac560
#             existing kernels using the old default kernel crashkernel value.
Coiby Xu 7ac560
#             The default value is yes.
Coiby Xu 7ac560
#
Petr Šabata f5bf49
# raw <partition>
Petr Šabata f5bf49
#           - Will dd /proc/vmcore into <partition>.
Petr Šabata f5bf49
#             Use persistent device names for partition devices,
Petr Šabata f5bf49
#             such as /dev/vg/<devname>.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# nfs <nfs mount>
Petr Šabata f5bf49
#           - Will mount nfs to <mnt>, and copy /proc/vmcore to
Petr Šabata f5bf49
#             <mnt>/<path>/%HOST-%DATE/, supports DNS.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# ssh <user@server>
DistroBaker 624a64
#           - Will save /proc/vmcore to <user@server>:<path>/%HOST-%DATE/,
Petr Šabata f5bf49
#             supports DNS.
Petr Šabata f5bf49
#             NOTE: make sure the user has write permissions on the server.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# sshkey <path>
Petr Šabata f5bf49
#           - Will use the sshkey to do ssh dump.
Petr Šabata f5bf49
#             Specify the path of the ssh key to use when dumping
Petr Šabata f5bf49
#             via ssh. The default value is /root/.ssh/kdump_id_rsa.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# <fs type> <partition>
Petr Šabata f5bf49
#           - Will mount -t <fs type> <partition> <mnt>, and copy
Petr Šabata f5bf49
#             /proc/vmcore to <mnt>/<path>/%HOST_IP-%DATE/.
Petr Šabata f5bf49
#             NOTE: <partition> can be a device node, label or uuid.
Petr Šabata f5bf49
#             It's recommended to use persistent device names
Petr Šabata f5bf49
#             such as /dev/vg/<devname>.
Petr Šabata f5bf49
#             Otherwise it's suggested to use label or uuid.
dcaec9
#             Supported fs types: ext[234], xfs, btrfs, minix, virtiofs
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# path <path>
Petr Šabata f5bf49
#           - "path" represents the file system path in which vmcore
Petr Šabata f5bf49
#             will be saved.  If a dump target is specified in
Petr Šabata f5bf49
#             kdump.conf, then "path" is relative to the specified
Petr Šabata f5bf49
#             dump target.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
#             Interpretation of "path" changes a bit if the user didn't
Petr Šabata f5bf49
#             specify any dump target explicitly in kdump.conf.  In this
Petr Šabata f5bf49
#             case, "path" represents the absolute path from root. The
Petr Šabata f5bf49
#             dump target and adjusted path are arrived at automatically
Petr Šabata f5bf49
#             depending on what's mounted in the current system.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
#             Ignored for raw device dumps.  If unset, will use the default
Petr Šabata f5bf49
#             "/var/crash".
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# core_collector <command> <options>
Petr Šabata f5bf49
#           - This allows you to specify the command to copy
Petr Šabata f5bf49
#             the vmcore.  The default is makedumpfile, which on
Petr Šabata f5bf49
#             some architectures can drastically reduce vmcore size.
Petr Šabata f5bf49
#             See /sbin/makedumpfile --help for a list of options.
Petr Šabata f5bf49
#             Note that the -i and -g options are not needed here,
Petr Šabata f5bf49
#             as the initrd will automatically be populated with a
Petr Šabata f5bf49
#             config file appropriate for the running kernel.
Petr Šabata f5bf49
#             The default core_collector for raw/ssh dump is:
DistroBaker 5cac7c
#             "makedumpfile -F -l --message-level 7 -d 31".
Petr Šabata f5bf49
#             The default core_collector for other targets is:
DistroBaker 5cac7c
#             "makedumpfile -l --message-level 7 -d 31".
Petr Šabata f5bf49
#
Petr Šabata f5bf49
#             "makedumpfile -F" will create a flattened vmcore.
Petr Šabata f5bf49
#             You need to use "makedumpfile -R" to rearrange the dump data to
Petr Šabata f5bf49
#             a normal dumpfile readable with analysis tools.  For example:
Petr Šabata f5bf49
#             "makedumpfile -R vmcore < vmcore.flat".
Petr Šabata f5bf49
#
Petr Šabata f5bf49
#             For core_collector format details, you can refer to
Petr Šabata f5bf49
#             kexec-kdump-howto.txt or kdump.conf manpage.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# kdump_post <binary | script>
Petr Šabata f5bf49
#           - This directive allows you to run a executable binary
Petr Šabata f5bf49
#             or script after the vmcore dump process terminates.
Petr Šabata f5bf49
#             The exit status of the current dump process is fed to
Petr Šabata f5bf49
#             the executable binary or script as its first argument.
Petr Šabata f5bf49
#             All files under /etc/kdump/post.d are collectively sorted
Petr Šabata f5bf49
#             and executed in lexical order, before binary or script
Petr Šabata f5bf49
#             specified kdump_post parameter is executed.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# kdump_pre <binary | script>
Petr Šabata f5bf49
#           - Works like the "kdump_post" directive, but instead of running
Petr Šabata f5bf49
#             after the dump process, runs immediately before it.
Petr Šabata f5bf49
#             Exit status of this binary is interpreted as follows:
Petr Šabata f5bf49
#               0 - continue with dump process as usual
Petr Šabata f5bf49
#               non 0 - run the final action (reboot/poweroff/halt)
Petr Šabata f5bf49
#             All files under /etc/kdump/pre.d are collectively sorted and
Petr Šabata f5bf49
#             executed in lexical order, after binary or script specified
Petr Šabata f5bf49
#             kdump_pre parameter is executed.
Petr Šabata f5bf49
#             Even if the binary or script in /etc/kdump/pre.d directory
Petr Šabata f5bf49
#             returns non 0 exit status, the processing is continued.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# extra_bins <binaries | shell scripts>
Petr Šabata f5bf49
#           - This directive allows you to specify additional binaries or
Petr Šabata f5bf49
#             shell scripts to be included in the kdump initrd.
Petr Šabata f5bf49
#             Generally they are useful in conjunction with a kdump_post
Petr Šabata f5bf49
#             or kdump_pre binary or script which depends on these extra_bins.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# extra_modules <module(s)>
Petr Šabata f5bf49
#           - This directive allows you to specify extra kernel modules
Petr Šabata f5bf49
#             that you want to be loaded in the kdump initrd.
Petr Šabata f5bf49
#             Multiple modules can be listed, separated by spaces, and any
Petr Šabata f5bf49
#             dependent modules will automatically be included.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# failure_action <reboot | halt | poweroff | shell | dump_to_rootfs>
Petr Šabata f5bf49
#           - Action to perform in case dumping fails.
Petr Šabata f5bf49
#             reboot:   Reboot the system.
Petr Šabata f5bf49
#             halt:     Halt the system.
Petr Šabata f5bf49
#             poweroff: Power down the system.
Petr Šabata f5bf49
#             shell:    Drop to a bash shell.
Petr Šabata f5bf49
#                       Exiting the shell reboots the system by default,
Petr Šabata f5bf49
#                       or perform "final_action".
Petr Šabata f5bf49
#             dump_to_rootfs:  Dump vmcore to rootfs from initramfs context and
Petr Šabata f5bf49
#                       reboot by default or perform "final_action".
Petr Šabata f5bf49
#                       Useful when non-root dump target is specified.
Petr Šabata f5bf49
#             The default option is "reboot".
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# default <reboot | halt | poweroff | shell | dump_to_rootfs>
Petr Šabata f5bf49
#           - Same as the "failure_action" directive above, but this directive
Petr Šabata f5bf49
#             is obsolete and will be removed in the future.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# final_action <reboot | halt | poweroff>
Petr Šabata f5bf49
#           - Action to perform in case dumping succeeds. Also performed
Petr Šabata f5bf49
#             when "shell" or "dump_to_rootfs" failure action finishes.
Petr Šabata f5bf49
#             Each action is same as the "failure_action" directive above.
Petr Šabata f5bf49
#             The default is "reboot".
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# force_rebuild <0 | 1>
Petr Šabata f5bf49
#           - By default, kdump initrd will only be rebuilt when necessary.
Petr Šabata f5bf49
#             Specify 1 to force rebuilding kdump initrd every time when kdump
Petr Šabata f5bf49
#             service starts.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# force_no_rebuild <0 | 1>
Petr Šabata f5bf49
#           - By default, kdump initrd will be rebuilt when necessary.
Petr Šabata f5bf49
#             Specify 1 to bypass rebuilding of kdump initrd.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
#             force_no_rebuild and force_rebuild options are mutually
Petr Šabata f5bf49
#             exclusive and they should not be set to 1 simultaneously.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# override_resettable <0 | 1>
Petr Šabata f5bf49
#           - Usually an unresettable block device can't be a dump target.
Petr Šabata f5bf49
#             Specifying 1 when you want to dump even though the block
Petr Šabata f5bf49
#             target is unresettable
Petr Šabata f5bf49
#             By default, it is 0, which will not try dumping destined to fail.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# dracut_args <arg(s)>
Petr Šabata f5bf49
#           - Pass extra dracut options when rebuilding kdump initrd.
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# fence_kdump_args <arg(s)>
Petr Šabata f5bf49
#           - Command line arguments for fence_kdump_send (it can contain
Petr Šabata f5bf49
#             all valid arguments except hosts to send notification to).
Petr Šabata f5bf49
#
Petr Šabata f5bf49
# fence_kdump_nodes <node(s)>
Petr Šabata f5bf49
#           - List of cluster node(s) except localhost, separated by spaces,
Petr Šabata f5bf49
#             to send fence_kdump notifications to.
Petr Šabata f5bf49
#             (this option is mandatory to enable fence_kdump).
Petr Šabata f5bf49
#
Petr Šabata f5bf49
Petr Šabata f5bf49
#raw /dev/vg/lv_kdump
Petr Šabata f5bf49
#ext4 /dev/vg/lv_kdump
Petr Šabata f5bf49
#ext4 LABEL=/boot
Petr Šabata f5bf49
#ext4 UUID=03138356-5e61-4ab3-b58e-27507ac41937
dcaec9
#virtiofs myfs
Petr Šabata f5bf49
#nfs my.server.com:/export/tmp
DistroBaker 624a64
#nfs [2001:db8::1:2:3:4]:/export/tmp
Petr Šabata f5bf49
#ssh user@my.server.com
DistroBaker 624a64
#ssh user@2001:db8::1:2:3:4
Petr Šabata f5bf49
#sshkey /root/.ssh/kdump_id_rsa
Coiby Xu 7ac560
auto_reset_crashkernel yes
Petr Šabata f5bf49
path /var/crash
DistroBaker 5cac7c
core_collector makedumpfile -l --message-level 7 -d 31
Petr Šabata f5bf49
#core_collector scp
Petr Šabata f5bf49
#kdump_post /var/crash/scripts/kdump-post.sh
Petr Šabata f5bf49
#kdump_pre /var/crash/scripts/kdump-pre.sh
Petr Šabata f5bf49
#extra_bins /usr/bin/lftp
Petr Šabata f5bf49
#extra_modules gfs2
Petr Šabata f5bf49
#failure_action shell
Petr Šabata f5bf49
#force_rebuild 1
Petr Šabata f5bf49
#force_no_rebuild 1
Petr Šabata f5bf49
#dracut_args --omit-drivers "cfg80211 snd" --add-drivers "ext2 ext3"
Petr Šabata f5bf49
#fence_kdump_args -p 7410 -f auto -c 0 -i 10
Petr Šabata f5bf49
#fence_kdump_nodes node1 node2
Pingfan Liu aa204a
EOF
Pingfan Liu aa204a
}
Pingfan Liu aa204a
Pingfan Liu aa204a
update_param()
Pingfan Liu aa204a
{
Pingfan Liu aa204a
	SED_EXP="${SED_EXP}s/^$1.*$/$1 $2/;"
Pingfan Liu aa204a
}
Pingfan Liu aa204a
Pingfan Liu aa204a
case "$1" in
Pingfan Liu aa204a
aarch64) ;;
Pingfan Liu aa204a
Pingfan Liu aa204a
i386) ;;
Pingfan Liu aa204a
Pingfan Liu aa204a
ppc64) ;;
Pingfan Liu aa204a
Pingfan Liu aa204a
ppc64le) ;;
Pingfan Liu aa204a
Pingfan Liu aa204a
s390x)
Pingfan Liu aa204a
	update_param core_collector \
Pingfan Liu aa204a
		"makedumpfile -c --message-level 7 -d 31"
Pingfan Liu aa204a
	;;
Pingfan Liu aa204a
x86_64) ;;
Pingfan Liu aa204a
Pingfan Liu aa204a
*)
Pingfan Liu aa204a
	echo "Warning: Unknown architecture '$1', using default kdump.conf template."
Pingfan Liu aa204a
	;;
Pingfan Liu aa204a
esac
Pingfan Liu aa204a
Pingfan Liu aa204a
generate