A simple Linux kernel module delaying power-off and restart, to allow for proper shutdown of devices, e.g. SATA disks.
There is a potential race between SATA disks shutting down and Linux powering down the platform. Symptoms are increasing SMART counters like "Power-Off_Retract_Count" or "Unsafe_Shutdown_Count", and filesystems reporting not being unmounted. (They have, but some sectors were not written.) See also https://lore.kernel.org/lkml/[email protected]/
$ git clone 'https://github.com/markuschaaf/linux-delay_power_off.git'
$ cd linux-delay_power_off
$ sudo make dkms-install
If and how to load the module depends on your distribution. It is probably best to add it to initrd. If you are using an Arch-like distribution:
...
$ make PKGBUILD
$ makepkg -si
$ sudo modprobe delay_power_off
$ sudoedit /etc/mkinitcpio.conf # add MODULES=(... delay_power_off)
$ sudo mkinitcpio -P