2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2012-03-17 23:21:37 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2012-03-17 23:21:37 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
crashdump = config.boot.crashDump;
|
2012-03-18 11:02:58 +01:00
|
|
|
|
|
|
|
kernelParams = concatStringsSep " " crashdump.kernelParams;
|
2012-09-05 09:55:02 +02:00
|
|
|
|
2012-03-17 23:21:37 +01:00
|
|
|
in
|
|
|
|
###### interface
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
boot = {
|
|
|
|
crashDump = {
|
|
|
|
enable = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
type = types.bool;
|
2012-03-17 23:21:37 +01:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If enabled, NixOS will set up a kernel that will
|
2017-10-25 22:00:52 +02: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-17 23:21:37 +01:00
|
|
|
It also activates the NMI watchdog.
|
|
|
|
'';
|
|
|
|
};
|
2017-10-25 22:00:52 +02:00
|
|
|
reservedMemory = mkOption {
|
|
|
|
default = "128M";
|
2012-03-17 23:21:37 +01:00
|
|
|
description = ''
|
2017-10-25 22:00:52 +02: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-17 23:21:37 +01:00
|
|
|
'';
|
|
|
|
};
|
2012-03-18 11:02:58 +01:00
|
|
|
kernelParams = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
type = types.listOf types.str;
|
2017-10-25 22:00:52 +02:00
|
|
|
default = [ "1" "boot.shell_on_fail" ];
|
2012-03-18 11:02:58 +01:00
|
|
|
description = ''
|
|
|
|
Parameters that will be passed to the kernel kexec-ed on crash.
|
|
|
|
'';
|
|
|
|
};
|
2012-03-17 23:21:37 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf crashdump.enable {
|
|
|
|
boot = {
|
|
|
|
postBootCommands = ''
|
2017-10-25 22:00:52 +02:00
|
|
|
echo "loading crashdump kernel...";
|
2012-07-16 17:27:59 +02:00
|
|
|
${pkgs.kexectools}/sbin/kexec -p /run/current-system/kernel \
|
|
|
|
--initrd=/run/current-system/initrd \
|
2017-10-25 22:00:52 +02:00
|
|
|
--reset-vga --console-vga \
|
|
|
|
--command-line="systemConfig=$(readlink -f /run/current-system) init=$(readlink -f /run/current-system/init) irqpoll maxcpus=1 reset_devices ${kernelParams}"
|
2012-03-17 23:21:37 +01:00
|
|
|
'';
|
|
|
|
kernelParams = [
|
2017-10-25 22:00:52 +02:00
|
|
|
"crashkernel=${crashdump.reservedMemory}"
|
2012-07-18 21:50:18 +02:00
|
|
|
"nmi_watchdog=panic"
|
2012-09-05 09:55:02 +02:00
|
|
|
"softlockup_panic=1"
|
2012-03-17 23:21:37 +01:00
|
|
|
];
|
2017-10-25 22:00:52 +02:00
|
|
|
kernelPatches = [ {
|
|
|
|
name = "crashdump-config";
|
|
|
|
patch = null;
|
|
|
|
extraConfig = ''
|
2012-03-17 23:21:37 +01:00
|
|
|
CRASH_DUMP y
|
|
|
|
DEBUG_INFO y
|
|
|
|
PROC_VMCORE y
|
2012-07-18 21:50:18 +02:00
|
|
|
LOCKUP_DETECTOR y
|
|
|
|
HARDLOCKUP_DETECTOR y
|
2012-03-17 23:21:37 +01:00
|
|
|
'';
|
2017-10-25 22:00:52 +02:00
|
|
|
} ];
|
2012-03-17 23:21:37 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|