How and when is the command string arg to reboot() with LINUX_REBOOT_CMD_RESTART2 executed?












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.










share|improve this question



























    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.










    share|improve this question

























      1












      1








      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.










      share|improve this question













      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.







      linux reboot






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      Tim

      25.5k74245449




      25.5k74245449






















          1 Answer
          1






          active

          oldest

          votes


















          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.






          share|improve this answer























          • Thanks. I am using X86-64.
            – Tim
            22 hours ago










          • 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
            12 hours ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489995%2fhow-and-when-is-the-command-string-arg-to-reboot-with-linux-reboot-cmd-restart%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          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.






          share|improve this answer























          • Thanks. I am using X86-64.
            – Tim
            22 hours ago










          • 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
            12 hours ago
















          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.






          share|improve this answer























          • Thanks. I am using X86-64.
            – Tim
            22 hours ago










          • 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
            12 hours ago














          2












          2








          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.






          share|improve this answer














          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 21 hours ago

























          answered 22 hours ago









          mosvy

          5,4491323




          5,4491323












          • Thanks. I am using X86-64.
            – Tim
            22 hours ago










          • 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
            12 hours ago


















          • Thanks. I am using X86-64.
            – Tim
            22 hours ago










          • 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
            12 hours ago
















          Thanks. I am using X86-64.
          – Tim
          22 hours ago




          Thanks. I am using X86-64.
          – Tim
          22 hours ago












          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
          12 hours ago




          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
          12 hours ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489995%2fhow-and-when-is-the-command-string-arg-to-reboot-with-linux-reboot-cmd-restart%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          サソリ

          広島県道265号伴広島線

          Setup Asymptote in Texstudio