[systemd-devel] The best way to execute kexec via dbus

Andrei Borzenkov arvidjaar at gmail.com
Fri Aug 26 04:55:15 UTC 2022


On 26.08.2022 03:59, Tomáš Hnyk wrote:
> Hello,I am trying to be able to reboot with kexec from a GUI (I am 
> modifying this: https://github.com/varlesh/org.kde.plasma.compact-shutdown 
> ). As far as I can tell, I need to use qdbus. Via command line, I can 
> successfully reboot with kexec with:
> systemctl start kexec.target --job-mode=replace-irreversibly --no-block
> 
> When I remove the --noblock parameter, the kexed reboot fails and normal 
> reboot is performed. 

There should be no difference between the two. Both do exactly the same
D-Bus call. Debug logs in both cases would be interesting.

> If I read the docs ( 
> https://www.freedesktop.org/wiki/Software/systemd/dbus/ ) correctly, I 
> cannot start a unit with no-block via D-Bus. Is that a bug or a feature? 

--no-block is relevant only for systemctl itself and makes systemctl
monitor D-Bus for results of previous invocation of Start/Stop unit. It
does not change D-Bus method invocation.

> And can I somehow get around it? I am now using this:
> qdbus --system org.freedesktop.systemd1 /org/freedesktop/systemd1 
> org.freedesktop.systemd1.Manager.StartUnit kexec.target 
> replace-irreversibly
> 
> 
> Which results in attempt at kexec that fails.
> 
> 
> I could call:
>   qdbus --system org.freedesktop.login1 /org/freedesktop/login1 
> org.freedesktop.login1.Manager.RebootWithFlags 2
> 
> 
> but since /sys/kernel/kexec_loaded by default is 0, the command above only 
> works if I first run:
> kexec -l /boot/vmlinuz --initrd=/boot/initrd.img --reuse-cmdline
> 

This method ends up doing exactly the same - it starts special
kexec.target which calls "systemctl --force kexec". And *this*
"sytsemctl kexec" invocation should (try to) load kexec kernel.

Are you sure you actually get kexec with --no-block?

> But this feels like reinventing the wheel, because systemd already knows 
> how to load the kernel if I just call "systemctl kexec".
> 
> Am I missing something or there is no easy way to do kexec via qdbus?
> 
> Kind regards,
> Tomas
> 



More information about the systemd-devel mailing list