@@ -305,25 +305,30 @@ in
305305 in listToAttrs (map formatDevice (filter (fs: fs.autoFormat) fileSystems)) // {
306306 # Mount /sys/fs/pstore for evacuating panic logs and crashdumps from persistent storage onto the disk using systemd-pstore.
307307 # This cannot be done with the other special filesystems because the pstore module (which creates the mount point) is not loaded then.
308− # Since the pstore filesystem is usually empty right after mounting because the backend isn't registered yet, and a path unit cannot detect files inside of it, the same service waits for that to happen. systemd's restart mechanism can't be used here because the first failure also fails all dependent units.
309308 "mount-pstore" = {
310309 serviceConfig = {
311310 Type = "oneshot";
312311 # skip on kernels without the pstore module
313312 ExecCondition = "${pkgs.kmod}/bin/modprobe -b pstore";
314− ExecStart = "${pkgs.util-linux}/bin/mount -t pstore -o nosuid,noexec,nodev pstore /sys/fs/pstore";
315− ExecStartPost = pkgs.writeShellScript "wait-for-pstore.sh" ''
313+ ExecStart = pkgs.writeShellScript "mount-pstore.sh" ''
316314 set -eu
317− TRIES=0
318− while [ $TRIES -lt 20 ] && [ "$(cat /sys/module/pstore/parameters/backend)" = "(null)" ]; do
319− sleep 0.1
320− TRIES=$((TRIES+1))
315+ # if the pstore module is builtin it will have mounted the persistent store automatically. it may also be already mounted for other reasons.
316+ ${pkgs.util-linux}/bin/mountpoint -q /sys/fs/pstore || ${pkgs.util-linux}/bin/mount -t pstore -o nosuid,noexec,nodev pstore /sys/fs/pstore
317+ # wait up to five seconds (arbitrary, happened within one in testing) for the backend to be registered and the files to appear. a systemd path unit cannot detect this happening; and succeeding after a restart would not start dependent units.
318+ TRIES=50
319+ while [ "$(cat /sys/module/pstore/parameters/backend)" = "(null)" ]; do
320+ if (( $TRIES )); then
321+ sleep 0.1
322+ TRIES=$((TRIES-1))
323+ else
324+ echo "Persistent Storage backend was not registered in time." >&2
325+ exit 1
326+ fi
321327 done
322328 '';
323329 RemainAfterExit = true;
324330 };
325331 unitConfig = {
326− ConditionPathIsMountPoint = "!/sys/fs/pstore";
327332 ConditionVirtualization = "!container";
328333 DefaultDependencies = false; # needed to prevent a cycle
329334 };