Bug 671673

Summary: systemd: kexec reboots instead of kexecing
Product: [openSUSE] openSUSE 11.4 Reporter: Jiri Slaby <jslaby>
Component: BasesystemAssignee: Frederic Crozat <fcrozat>
Status: VERIFIED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None    
Version: Factory   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Jiri Slaby 2011-02-14 11:10:48 UTC
After I switched to systemd, if I try to kexec a new kernel, the system reboots instead of kexec. With sysvinit it works as expected.

I run:
kexec /boot/vmlinuz --initrd=/boot/initrd --append='3 console=ttyS0,115200'
Comment 1 Kay Sievers 2011-02-14 11:18:01 UTC
systemd has native kexec support. does:
  systemd kexec
work?
Comment 2 Kay Sievers 2011-02-14 11:18:19 UTC
oops, systemctl, i meant
Comment 3 Jiri Slaby 2011-02-14 11:29:39 UTC
(In reply to comment #1)
> systemd has native kexec support. does:
>   systemd kexec
> work?

Hmm, no. How the parameters are supposed to be passed:
# systemctl kexec /boot/vmlinuz --initrd abc
systemctl: unrecognized option '--initrd'
Comment 4 Kay Sievers 2011-02-16 14:53:30 UTC
"kexec -l ..." loads the kernel and the parameters
"kexec -e" boots the kernel

with native systemd, the "kexec -e" step should be "systemctl kexec"
Comment 5 Jiri Slaby 2011-02-19 18:27:55 UTC
(In reply to comment #4)
> "kexec -l ..." loads the kernel and the parameters
> "kexec -e" boots the kernel
> 
> with native systemd, the "kexec -e" step should be "systemctl kexec"

There is a third functionality of kexec. Without loading you do:
kexec /boot/vmlinuz --initrd=/boot/initrd --command-line='...'

and it does all the needed steps including services shutdown. And that one doesn't work with systemd.
Comment 6 Jiri Slaby 2011-02-19 18:30:45 UTC
Manpage says:
It's also possible to invoke kexec without an option parameter. In that        case,  kexec  loads  the specified kernel and then invokes shutdown(1). If the shutdown scripts of your Linux distribution support  kexec-based rebooting, they  then call kexec -e just before actually rebooting the machine. That way, the machine does  a  clean  shutdown  including  all shutdown scripts.
Comment 7 Kay Sievers 2011-02-20 12:37:59 UTC
Yeah, that's currently the expected behavior with systemd.

/sbin/shutdown is linked to "systemctl poweroff" For kexec execution, systemd does not do implicit different behavior depending on the load-state of a possible kexec kernel like the sysv halt script did, it requires the explicit "kexec" command to be given.

We might want to patch the kexec binary to know about systemd, or just the sysv compat code in systemctl. I'll check with upstream ...
Comment 8 Kay Sievers 2011-02-20 20:11:25 UTC
Added code to the systemctl sysv compat support:
  http://cgit.freedesktop.org/systemd/commit/?id=5622dde36deb414ab372a2d767584eaca73aec46

This:
  kexec /boot/vmlinuz --initrd=/boot/initrd --command-line='...'
now results in:
  systemd[1]: About to execute: /bin/systemctl --force kexec
during reboot.
Comment 9 Jiri Slaby 2011-08-20 21:48:44 UTC
(In reply to comment #8)
> Added code to the systemctl sysv compat support:
>  
> http://cgit.freedesktop.org/systemd/commit/?id=5622dde36deb414ab372a2d767584eaca73aec46

The commit is part of systemd 19. But it still doesn't work with factory (systemd 33). It just reboots...
Comment 10 Frederic Crozat 2011-08-22 09:29:27 UTC
hmm, I just ran 
"kexec /boot/vmlinuz --initrd=/boot/initrd --command-line='3'" under a Factory system running with systemd and system shutdowned, ran kexec on the kernel and booted correctly.

Could you give me a complete test case ?
Comment 11 Jiri Slaby 2011-08-22 10:50:18 UTC
(In reply to comment #10)
> hmm, I just ran 
> "kexec /boot/vmlinuz --initrd=/boot/initrd --command-line='3'" under a Factory
> system running with systemd and system shutdowned, ran kexec on the kernel and
> booted correctly.
> 
> Could you give me a complete test case ?

Hmm, this is interesting. I don't know what exactly I should provide. When I boot with sysvinit and do the command you do, it works. With systemd it shutdowns the system and reboots. It is an updated factory with the -next kernel. But I also tried 3.0 and 2.6.37 from kernel:11.4 and kernel:stable respectively with the same result.
Comment 12 Frederic Crozat 2011-08-22 11:23:11 UTC
hmm, interesting indeed, now, I tried again to run the test and running the command reboots the system (and it was working this morning)..
Comment 13 Frederic Crozat 2011-08-22 12:47:37 UTC
After testing more, there is a different behaviour if systemd-sysvinit is installed or not :
- if systemd-sysvinit is installed, kexec works as expected
- if systemd-sysvinit is not installed, reboot is done instead of kexec, because /sbin/shutdown is handled by sysvinit and systemd doesn't check for kexec_loaded value.

I'll fix that.
Comment 14 Frederic Crozat 2011-08-22 14:26:29 UTC
fixed in home:fcrozat:systemd/systemd. Will land in Base:System (and Factory) later.
Comment 15 Frederic Crozat 2011-08-24 16:49:05 UTC
landed in Base:System
Comment 16 Bernhard Wiedemann 2011-08-24 17:00:09 UTC
This is an autogenerated message for OBS integration:
This bug (671673) was mentioned in
https://build.opensuse.org/request/show/79689 Factory / systemd