So, as of 21.10 (and Kubuntu), it works as long as one starts using systemd-boot
instead of GRUB2
to start up the machine - that will also likely speed up boot by several seconds. Details are here: How to replace grub with bootloader "systemd-boot" in ubuntu 20.04?
Once that is ready, sudo systemctl kexec
just works.
It might be necessary to create a new systemd unit in case you are using Nvidia card and several monitors (and maybe even if not).
sudo gedit /usr/lib/systemd/system/unmodeset.service
[Unit]
Description=Unload nvidia modesetting modules from kernel
Documentation=man:modprobe(8)fi
DefaultDependencies=no
After=umount.target
Before=kexec.target
[Service]
Type=oneshot
ExecStart=modprobe -r nvidia_drm
In my case, some jobs took 90 seconds to shut down. Tinkering with these values in /etc/systemd/systemd.conf
helped:
DefaultTimeoutStartSec=3s
DefaultTimeoutStopSec=3s
DefaultStartLimitIntervalSec=2s
To make it the default reboot action when invoked from GNOME seems to be impossible. Per https://github.com/systemd/systemd/issues/15029#issuecomment-981781792 they call logind
directly, so without patching the software this is impossible. Good luck convincing GNOME developers about this. In KDE, the feature to override reboot action is in SDDM, but is broken right now: https://github.com/sddm/sddm/issues/434
systemdctl kexec
. But no matter what I try, I cannot make it the default action for reboot. – sup Jan 04 '21 at 13:51