systemd icon indicating copy to clipboard operation
systemd copied to clipboard

systemd-hibernate-resume breaks the HibernateLocation EFI variable

Open alois31 opened this issue 1 year ago • 4 comments
trafficstars

systemd version the issue has been seen with

256.4

Used distribution

NixOS 24.11

Linux kernel version used

6.10.7

CPU architectures issue was seen on

x86_64

Component

other

Expected behaviour you didn't see

/sys/firmware/efi/efivars/HibernateLocation-8cf2644b-4b0b-428f-9387-6d876050dc67 does not exist after resume from hibernate (or at least works if it does exist).

Unexpected behaviour you saw

/sys/firmware/efi/efivars/HibernateLocation-8cf2644b-4b0b-428f-9387-6d876050dc67 exists, but is broken (reading gives nothing (not even the usual header), deletion fails with input/output error). The reason appears to be that systemd-hibernate-resume deletes this variable while the kernel is still hibernated, so after resume efivarfs thinks the variable is still there but it actually isn't.

Steps to reproduce the problem

  1. Hibernate system
  2. Resume system
  3. Observe the file /sys/firmware/efi/efivars/HibernateLocation-8cf2644b-4b0b-428f-9387-6d876050dc67 exists
  4. Try to delete it (for example using systemctl start systemd-hibernate-clear.service, or using chattr and rm)

Additional program output to the terminal or log subsystem illustrating the issue

No response

alois31 avatar Sep 07 '24 09:09 alois31

Hmm, I'm quite sure this should be considered a kernel bug. Boot loaders might change/remove efivars before hibernation takes place, hence this is not a systemd-hibernate-resume specific thing.

YHNdnzj avatar Sep 07 '24 10:09 YHNdnzj

I am also having this issue on NixOS

Lyndeno avatar Oct 06 '24 02:10 Lyndeno

Same issue on NixOS Seems like everyone else's also having it on that distro, could this be an upstream issue?

griffi-gh avatar Oct 20 '24 09:10 griffi-gh

I guess NixOS users are just particularly prone to attempting to restart that unit, as switching configuration does.

alois31 avatar Oct 20 '24 11:10 alois31

Hmm, I'm quite sure this should be considered a kernel bug

This is intended behavior. Looking at https://github.com/torvalds/linux/blob/c2ee9f594da826bea183ed14f2cc029c719bf4da/fs/efivarfs/file.c#L81-L88 reveals that empty files represent uncommitted EFI vars. The code that causes the error here is this: https://github.com/systemd/systemd/blob/b6b8527cd184085008585c1a1f9725eb97c342ef/src/basic/efivars.c#L99-L101

Scrumplex avatar Oct 23 '24 10:10 Scrumplex

perhaps the service should check for this then?

griffi-gh avatar Oct 23 '24 10:10 griffi-gh

I create a PR to fix that, introduce the PR into my nixos config fix the problem. Maybe you can try the PR if you are on nixos.

https://github.com/systemd/systemd/pull/35497

wrvsrx avatar Dec 07 '24 03:12 wrvsrx

Is there any way to get around this problem if it occurs in NixOS, e.g. after a hibernation and one runs nixos-rebuild switch?

Granddave avatar Dec 17 '24 16:12 Granddave

Is there any way to get around this problem if it occurs in NixOS, e.g. after a hibernation and one runs nixos-rebuild switch?

@Granddave Apply my patch. After that, you need to reboot your nixos to ensure overrided systemd package is used.

{ config, lib, pkgs, ... }:
{ systemd.package = pkgs.systemd.overrideAttrs (old: {
  patches = old.patches ++ [ 
    (pkgs.fetchurl {
      url = "https://github.com/wrvsrx/systemd/compare/tag_fix-hibernate-resume%5E...tag_fix-hibernate-resume.patch";
      hash = "sha256-iDC5lenk4LhDdU4ZRHjestYu2jXNvNZCgSCkE2hQHuQ=";
    })
  ];
}) };

wrvsrx avatar Dec 18 '24 06:12 wrvsrx