Bug 8331 - kexec wants shutdown in /sbin, but systemd installs it in /usr/sbin
Summary: kexec wants shutdown in /sbin, but systemd installs it in /usr/sbin
Status: RESOLVED DUPLICATE of bug 8336
Alias: None
Product: buildroot
Classification: Unclassified
Component: Other (show other bugs)
Version: 2015.05
Hardware: PC Linux
: P5 minor
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-11 10:05 UTC by Dr I J Ormshaw
Modified: 2015-10-14 09:44 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dr I J Ormshaw 2015-09-11 10:05:54 UTC
Chaining a new kernel using kexec fails as /usr/sbin/shutdown is missing.

creating a link in the skeleton, or overlay file system from /usr/sbin/shutdown to /sbin/shutdown fixes the problem.
Comment 1 Peter Korsgaard 2015-09-13 20:20:49 UTC
Hmm, looking at the kexec source code I see:

static int my_shutdown(void)
{
        char *args[] = {
                "shutdown",
                "-r",
                "now",
                NULL
        };

        execv("/sbin/shutdown", args);
        execv("/etc/shutdown", args);
        execv("/bin/shutdown", args);

        perror("shutdown");
        return -1;
}

So having shutdown in /sbin seems fine?

Can you please provide more info about your config and what goes wrong?
Comment 2 Dr I J Ormshaw 2015-09-15 07:40:02 UTC
(In reply to comment #1)
> Hmm, looking at the kexec source code I see:
> 
> static int my_shutdown(void)
> {
>         char *args[] = {
>                 "shutdown",
>                 "-r",
>                 "now",
>                 NULL
>         };
> 
>         execv("/sbin/shutdown", args);
>         execv("/etc/shutdown", args);
>         execv("/bin/shutdown", args);
> 
>         perror("shutdown");
>         return -1;
> }
> 
> So having shutdown in /sbin seems fine?
> 
> Can you please provide more info about your config and what goes wrong?

The problem is that there is no shutdown in /sbin, shutdown is in /usr/sbin. I had to create a link in /sbin to /usr/sbin/shutdown.
Comment 3 Dr I J Ormshaw 2015-09-15 07:48:18 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > Hmm, looking at the kexec source code I see:
> > 
> > static int my_shutdown(void)
> > {
> >         char *args[] = {
> >                 "shutdown",
> >                 "-r",
> >                 "now",
> >                 NULL
> >         };
> > 
> >         execv("/sbin/shutdown", args);
> >         execv("/etc/shutdown", args);
> >         execv("/bin/shutdown", args);
> > 
> >         perror("shutdown");
> >         return -1;
> > }
> > 
> > So having shutdown in /sbin seems fine?
> > 
> > Can you please provide more info about your config and what goes wrong?
> 
> The problem is that there is no shutdown in /sbin, shutdown is in /usr/sbin. I
> had to create a link in /sbin to /usr/sbin/shutdown.

I also raised a similay bug report 8336, to which I had a responce citing http://patchwork.ozlabs.org/patch/514750/ as a fix.  That patch should also fix this bug.
Comment 4 Peter Korsgaard 2015-09-15 08:20:52 UTC
(In reply to comment #2)
> > Can you please provide more info about your config and what goes wrong?
> 
> The problem is that there is no shutdown in /sbin, shutdown is in /usr/sbin. I
> had to create a link in /sbin to /usr/sbin/shutdown.

Ok, what package do you have providing /usr/sbin/shutdown? I see that busybox doesn't provide a shutdown applet at all (it does provide halt/poweroff/reboot though).
Comment 5 Dr I J Ormshaw 2015-09-15 08:28:17 UTC
(In reply to comment #4)
> (In reply to comment #2)
> > > Can you please provide more info about your config and what goes wrong?
> > 
> > The problem is that there is no shutdown in /sbin, shutdown is in /usr/sbin. I
> > had to create a link in /sbin to /usr/sbin/shutdown.
> 
> Ok, what package do you have providing /usr/sbin/shutdown? I see that busybox
> doesn't provide a shutdown applet at all (it does provide halt/poweroff/reboot
> though).

Systemd is providing /usr/sbin/shutdown
Comment 6 Vicente Olivert Riera 2015-09-15 09:22:22 UTC
(In reply to comment #0)
> Chaining a new kernel using kexec fails as /usr/sbin/shutdown is missing.

That's not correct. /usr/sbin/shutdown does exists. The problem is that kexec is trying to find it at /sbin instead of /usr/sbin.

(In reply to comment #3)
> I also raised a similay bug report 8336, to which I had a responce citing
> http://patchwork.ozlabs.org/patch/514750/ as a fix.  That patch should also fix
> this bug.

Currently in Buildroot there are two ways to have shutdown installed in your target. The first one is using sysvinit as you init system, which will install shutdown in /sbin. The second one is using systemd as your init system, which will install shutdown in /usr/sbin.

Once we get the patch from Yann merged, kexec will be able to find shutdown because /sbin will be a symlink to /usr/sbin if you use systemd as your init system. So, yes, that patches fixes your problem.

The thing is that here we have highlighted a different problem. Busybox doesn't install shutdown, so kexec will never be able to find it, either if you have /sbin as a real directory or being a symlink to /usr/sbin. It simply doesn't exist.
Comment 7 Peter Korsgaard 2015-09-15 09:41:50 UTC
(In reply to comment #5)
> Systemd is providing /usr/sbin/shutdown


Ok, so there's two issues:

- Not all of our init implementations provide shutdown (busybox doesn't,
sysvinit has /sbin/shutdown, systemd has /usr/sbin/shutdown

- Systemd doesn't install it where kexec looks for it

I see that kexec-lite doesn't have such code.

I've never used kexec, but looking at the kexec code I'm not sure what the
shutdown code is for, it seems to just be a wrapper around shutting down that
isn't normally used (as it gets checked before do_exec).

What is your use case for needing it?
Comment 8 Vicente Olivert Riera 2015-09-15 09:42:19 UTC
By the way, is this helpful for you?

http://unix.stackexchange.com/questions/37323/kexec-from-within-initramfs

From the kexec man page:

-e (--exec)
      Run the currently loaded kernel. Note that it will  reboot  into
      the loaded kernel without calling shutdown(8).
Comment 9 Vicente Olivert Riera 2015-09-15 09:46:10 UTC
(In reply to comment #7)
> What is your use case for needing it?

I think he is loading a new kernel image using "kexec --load", and then he wants to reboot the board in order to boot with that kernel image, which should be able to do it with "kexec --exec", without calling shutdown.

Dr I J Ormshaw, please confirm.
Comment 10 Dr I J Ormshaw 2015-09-15 11:25:10 UTC
I was trying 

/usr/sbin/kexec --command-line="@kernelCommandLine@" "${mountPoint}"/boot/@kernelName@

Using kexec -l followed bu kexec -e will not shut down services correctly.

but I think I should be able to use:

kexec -l 

followed by 

systemctl isolate kexec.target

to achieve what I want, as I think systemd should kexec the loaded kernel once services are shutdown.
Comment 11 Vicente Olivert Riera 2015-09-15 13:05:52 UTC
(In reply to comment #10)
> Using kexec -l followed bu kexec -e will not shut down services correctly.

Well, but that's because you are using systemd, right? That would work with busybox.

> but I think I should be able to use:
> 
> kexec -l 
> 
> followed by 
> 
> systemctl isolate kexec.target
> 
> to achieve what I want, as I think systemd should kexec the loaded kernel once
> services are shutdown.

Or, in the meantime, you can create the symlink to workaround the problem until the patch from Yann gets applied.

You could also send a patch to kexec upstream in order to add...

execv("/usr/sbin/shutdown", args);

...to the my_shutdown() function, so it would also work on systemd although you don't have the /bin, /sbin and /lib symlinks stuff.

So, to summarize and make progress on this issue:

- systemd: symlink workaround until Yann's patch OR fix kexec upstream
- sysvinit: already works
- busybox: use "kexec -e"

Should we mark this bug as RESOLVED DUPLICATE (of #8336), Peter?
For busybox you can use the "-e (--exec)" option
Comment 12 Vicente Olivert Riera 2015-09-15 13:07:58 UTC
(In reply to comment #11)
> For busybox you can use the "-e (--exec)" option

Ignore that line (the last one of my previous comment). I forgot to remove it before sending my message.
Comment 13 Thomas Petazzoni 2015-10-14 09:44:55 UTC

*** This bug has been marked as a duplicate of bug 8336 ***