From 14ea6786cde88fd644635ab5f75cc36578bc5d09 Mon Sep 17 00:00:00 2001 From: Will Fancher Date: Fri, 6 Mar 2026 21:09:51 -0500 Subject: [PATCH] linux/common-config: EFI_VARS_PSTORE=y This enables the kernel to save crash logs much earlier, rather than losing any log from before the efi_pstore module is loaded in stage 2. --- nixos/tests/systemd-pstore.nix | 27 ++++++++++++++++++- .../linux/kernel/common-config.nix | 1 + pkgs/os-specific/linux/systemd/default.nix | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/nixos/tests/systemd-pstore.nix b/nixos/tests/systemd-pstore.nix index 7eeb7209e4a4..7b9fc2f5142a 100644 --- a/nixos/tests/systemd-pstore.nix +++ b/nixos/tests/systemd-pstore.nix @@ -1,14 +1,39 @@ { name = "systemd-pstore"; - nodes.machine = { }; + nodes.machine = { + virtualisation.useEFIBoot = true; + boot.initrd.systemd.enable = true; + testing.initrdBackdoor = true; + }; testScript = '' + machine.switch_root() with subtest("pstore API fs is mounted"): machine.succeed("stat /sys/fs/pstore") with subtest("systemd-pstore.service doesn't run because nothing crashed"): output = machine.execute("systemctl status systemd-pstore.service", check_return=False)[1] t.assertIn("condition unmet", output) + machine.fail("stat /var/lib/systemd/pstore/*/*/dmesg.txt") + + with subtest("systemd-pstore.service saves dmesg.txt files"): + machine.execute("echo c > /proc/sysrq-trigger", check_return=False, check_output=False) + machine.wait_for_shutdown() + machine.switch_root() + machine.wait_for_unit("systemd-pstore.service") + machine.succeed("stat /var/lib/systemd/pstore/*/*/dmesg.txt") + + with subtest("crashes in initrd can be recovered too"): + machine.succeed( + "rm -r /var/lib/systemd/pstore/*", + "sync", + ) + machine.shutdown() + machine.execute("echo c > /proc/sysrq-trigger", check_return=False, check_output=False) + machine.wait_for_shutdown() + machine.switch_root() + machine.wait_for_unit("systemd-pstore.service") + machine.succeed("stat /var/lib/systemd/pstore/*/*/dmesg.txt") ''; } diff --git a/pkgs/os-specific/linux/kernel/common-config.nix b/pkgs/os-specific/linux/kernel/common-config.nix index 23b8aabf4e9a..2b3f540ec872 100644 --- a/pkgs/os-specific/linux/kernel/common-config.nix +++ b/pkgs/os-specific/linux/kernel/common-config.nix @@ -1224,6 +1224,7 @@ let EFI = lib.mkIf stdenv.hostPlatform.isEfi yes; EFI_STUB = yes; # EFI bootloader in the bzImage itself EFI_GENERIC_STUB_INITRD_CMDLINE_LOADER = whenOlder "6.2" yes; # initrd kernel parameter for EFI + EFI_VARS_PSTORE = yes; # Generic compression support for EFI payloads # Add new platforms only after they have been verified to build and boot. diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix index 77d8b4666219..ccd5495e42a3 100644 --- a/pkgs/os-specific/linux/systemd/default.nix +++ b/pkgs/os-specific/linux/systemd/default.nix @@ -930,6 +930,7 @@ stdenv.mkDerivation (finalAttrs: { systemd-nspawn-configfile systemd-oomd systemd-portabled + systemd-pstore systemd-resolved systemd-shutdown systemd-sysupdate