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