1

The manpage of reboot() says

LINUX_REBOOT_CMD_RESTART2

(0xa1b2c3d4; since Linux 2.1.30). The message "Restarting system with command '%s'" is printed, and a restart (using the command string given in arg) is performed immediately. If not preceded by a sync(2), data will be lost.

How and when exactly is the command string given in arg is executed during shutdown process?

https://unix.stackexchange.com/a/489651/674 says about LINUX_REBOOT_CMD_RESTART2

An added confusion here is caused by the fact that the reboot() system call appears to be capable of running a process to do the restart (however that works)

Is the command string given in arg run before the kernel is shutdown, so can the command do some cleanup before kernel shutdown?

Thanks.

2

That command is not executed during the shutdown process. It's not a shell command or such; it's a string that's supposed to be passed as callback data (via machine_restart() => do_kernel_restart()) to the restart handler registered via register_restart_handler() by some driver (watchdog, etc).

But that mechanism is not used on x86; there that "command" is completely ignored. From arch/x86/kernel/reboot.c:

void machine_restart(char *cmd)
{
        machine_ops.restart(cmd);

struct machine_ops machine_ops __ro_after_init = {
        ...
        .restart = native_machine_restart,

static void native_machine_restart(char *__unused)
{

That string will be also passed to the handlers registered with register_reboot_notifier(). The only driver which is (ab)using that seems to be EFI Bootloader Control which is setting the non-volative LoaderEntryOneShot EFI variable from it, causing some bootloaders to determine which OS should be booted in next. I don't think that driver was ever used outside Android -- but in any case it looks quite clunky, as it's also detailed in an old lkml discussion concerning a previous version of that same thing.

  • Yeah, seems like I misinterpreted the meaning of that "with command" phrase in the man page. Not that the man page is too clear on what the commands could be, or what architectures even use it. Sigh. – ilkkachu Dec 20 '18 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.