2014-04-14 18:26:48 +04:00
|
|
|
{ config, lib, pkgs, ... }:
|
2012-03-18 02:21:37 +04:00
|
|
|
|
2014-04-14 18:26:48 +04:00
|
|
|
with lib;
|
2012-03-18 02:21:37 +04:00
|
|
|
|
|
|
|
let
|
|
|
|
crashdump = config.boot.crashDump;
|
2012-03-18 14:02:58 +04:00
|
|
|
|
|
|
|
kernelParams = concatStringsSep " " crashdump.kernelParams;
|
2012-09-05 11:55:02 +04:00
|
|
|
|
2012-03-18 02:21:37 +04:00
|
|
|
in
|
|
|
|
###### interface
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
boot = {
|
|
|
|
crashDump = {
|
|
|
|
enable = mkOption {
|
2013-10-30 20:37:45 +04:00
|
|
|
type = types.bool;
|
2012-03-18 02:21:37 +04:00
|
|
|
default = false;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
If enabled, NixOS will set up a kernel that will
|
2017-10-25 23:00:52 +03:00
|
|
|
boot on crash, and leave the user in systemd rescue
|
|
|
|
to be able to save the crashed kernel dump at
|
|
|
|
/proc/vmcore.
|
2012-03-18 02:21:37 +04:00
|
|
|
It also activates the NMI watchdog.
|
|
|
|
'';
|
|
|
|
};
|
2017-10-25 23:00:52 +03:00
|
|
|
reservedMemory = mkOption {
|
|
|
|
default = "128M";
|
2021-01-22 13:10:26 +03:00
|
|
|
type = types.str;
|
2012-03-18 02:21:37 +04:00
|
|
|
description = lib.mdDoc ''
|
2017-10-25 23:00:52 +03:00
|
|
|
The amount of memory reserved for the crashdump kernel.
|
|
|
|
If you choose a too high value, dmesg will mention
|
|
|
|
"crashkernel reservation failed".
|
2012-03-18 02:21:37 +04:00
|
|
|
'';
|
|
|
|
};
|
2012-03-18 14:02:58 +04:00
|
|
|
kernelParams = mkOption {
|
2013-10-30 20:37:45 +04:00
|
|
|
type = types.listOf types.str;
|
2017-10-25 23:00:52 +03:00
|
|
|
default = [ "1" "boot.shell_on_fail" ];
|
2012-03-18 14:02:58 +04:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Parameters that will be passed to the kernel kexec-ed on crash.
|
|
|
|
'';
|
|
|
|
};
|
2012-03-18 02:21:37 +04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf crashdump.enable {
|
|
|
|
boot = {
|
|
|
|
postBootCommands = ''
|
2017-10-25 23:00:52 +03:00
|
|
|
echo "loading crashdump kernel...";
|
2021-09-03 17:17:21 +03:00
|
|
|
${pkgs.kexec-tools}/sbin/kexec -p /run/current-system/kernel \
|
2012-07-16 19:27:59 +04:00
|
|
|
--initrd=/run/current-system/initrd \
|
2017-10-25 23:00:52 +03:00
|
|
|
--reset-vga --console-vga \
|
2019-04-26 13:02:11 +03:00
|
|
|
--command-line="init=$(readlink -f /run/current-system/init) irqpoll maxcpus=1 reset_devices ${kernelParams}"
|
2012-03-18 02:21:37 +04:00
|
|
|
'';
|
|
|
|
kernelParams = [
|
2017-10-25 23:00:52 +03:00
|
|
|
"crashkernel=${crashdump.reservedMemory}"
|
2012-07-18 23:50:18 +04:00
|
|
|
"nmi_watchdog=panic"
|
2012-09-05 11:55:02 +04:00
|
|
|
"softlockup_panic=1"
|
2012-03-18 02:21:37 +04:00
|
|
|
];
|
2017-10-25 23:00:52 +03:00
|
|
|
kernelPatches = [ {
|
|
|
|
name = "crashdump-config";
|
|
|
|
patch = null;
|
|
|
|
extraConfig = ''
|
2012-03-18 02:21:37 +04:00
|
|
|
CRASH_DUMP y
|
|
|
|
DEBUG_INFO y
|
|
|
|
PROC_VMCORE y
|
2012-07-18 23:50:18 +04:00
|
|
|
LOCKUP_DETECTOR y
|
|
|
|
HARDLOCKUP_DETECTOR y
|
2012-03-18 02:21:37 +04:00
|
|
|
'';
|
2017-10-25 23:00:52 +03:00
|
|
|
} ];
|
2012-03-18 02:21:37 +04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|