aports/testing/makedumpfile/kdump.initd
Dominique Martinet 2a15c351ad testing/makedumpfile: new aport
makedumpfile is used to take crash dumps with kexec on panic

The actual "load a backup kernel and take the dump" logic isn't that
complicated, but unfortunately each distro seems to roll their own:
https://github.com/rhkdump/kdump-utils
https://tracker.debian.org/pkg/kdump-tools

So I just whipped up a minimal example for people to customize instead
of doing something proper and checked it dumps in a VM and on a real
board after setting up /etc/conf.d/kdump + crashkernel boot param:
```
# vi /etc/conf.d/kdump
(set kernel etc)
# vi /etc/update-extlinux.conf
(add crashkernel= param, set custom kernel as default)
# update-extlinux
# reboot
...
 * Loading crash kernel ... [ ok ]
...
# echo c > /proc/sysrq-trigger
[   17.876403] sysrq: Trigger a crash
...
 * Dumping kernel /var/crash/2024-07-17-17:24:15 ...
Copying data                                      : [100.0 %] -           eta: 0s

The dumpfile is saved to /var/crash/2024-07-17-17:24:15/dump.

makedumpfile Completed.

The dmesg log is saved to /var/crash/2024-07-17-17:24:15/dmesg.

makedumpfile Completed.
 * Dump done, rebooting
...
# ls -lh /var/crash/2024-07-17-17:24:15/
total 35M
-rw-------    1 root     root       32.1K Jul 17 17:24 dmesg
-rw-------    1 root     root       34.6M Jul 17 17:24 dump
```
2024-07-18 07:19:33 +00:00

68 lines
1.4 KiB
Bash
Executable file

#!/sbin/openrc-run
description="Load crash kernel or take dump+reboot"
: "${cmdline_append:="reset_devices nr_cpus=1"}"
: "${kexec_args:=}"
: "${makedumpfile_args:="-z -d 31"}"
: "${kdump_dir:=/var/crash}"
depend() {
after localmount
}
start_load() {
if [ -z "$kexec_args" ]; then
eerror "Cannot load crash kernel without configuring kexec_args first"
return 1
fi
if ! grep -q crashkernel /proc/cmdline; then
einfo "Not loading crash kernel because crashkernel not set in cmdline"
return
fi
# if already loaded unload first
_stop
ebegin "Loading crash kernel"
local cmdline
cmdline="$(cat /proc/cmdline) $cmdline_append"
# shellcheck disable=SC2086 # allow spliting args
kexec -p --command-line="$cmdline" $kexec_args
eend "$?" "Could not load crash kernel"
}
start_dump() {
local dest
dest="$kdump_dir/$(date +%Y-%m-%d-%T)"
ebegin "Dumping kernel $dest"
mkdir -p "$dest"
# shellcheck disable=SC2086 # allow spliting args
makedumpfile $makedumpfile_args /proc/vmcore "$dest/dump"
makedumpfile --dump-dmesg /proc/vmcore "$dest/dmesg"
einfo "Dump done, rebooting"
reboot
eend 0
}
start() {
if [ -e "/proc/vmcore" ]; then
start_dump
else
start_load
fi
}
_stop() {
# we're not unloading the module on purpose to allow
# crashes to work at poweroff
# add `stop() { _stop; }` in conf.d/kdump to enable
# not loaded
kexec -S && return
ebegin "Unloading crash kernel"
kexec -p -u
eend "$?" "Could not unload crash kernel"
}