Ubuntu 16.04 boot as init=/root/init.sh and exec init 3 in shell, but why X11 started?












0














Ubuntu 16.04.5 default environment.



I want to do some custom job before init. grub.cfg as



linux /boot/vmlinuz ... ro init=/root/init.sh



init.sh:



#!/bin/bash
# do some task
exec init 3


after boot, X started.



if grub
linux /boot/vmlinuz ... ro init=/root/init.sh 3,can success boot into text mode.



according to https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html , 3 is not a kernel’s command-line parameters, kernel will pass it as an argument to init, here is /root/init.sh.



change /root/init.sh to :



#!/bin/bash
# do some task
echo $1
sleep 3s
exec init 3


I can see the value passed from kernel.



In my submission,no matter what value grub -> kernel -> /root/init.sh , I will discard the value and exec init as runlevel 3. why it doesn't work.










share|improve this question



























    0














    Ubuntu 16.04.5 default environment.



    I want to do some custom job before init. grub.cfg as



    linux /boot/vmlinuz ... ro init=/root/init.sh



    init.sh:



    #!/bin/bash
    # do some task
    exec init 3


    after boot, X started.



    if grub
    linux /boot/vmlinuz ... ro init=/root/init.sh 3,can success boot into text mode.



    according to https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html , 3 is not a kernel’s command-line parameters, kernel will pass it as an argument to init, here is /root/init.sh.



    change /root/init.sh to :



    #!/bin/bash
    # do some task
    echo $1
    sleep 3s
    exec init 3


    I can see the value passed from kernel.



    In my submission,no matter what value grub -> kernel -> /root/init.sh , I will discard the value and exec init as runlevel 3. why it doesn't work.










    share|improve this question

























      0












      0








      0







      Ubuntu 16.04.5 default environment.



      I want to do some custom job before init. grub.cfg as



      linux /boot/vmlinuz ... ro init=/root/init.sh



      init.sh:



      #!/bin/bash
      # do some task
      exec init 3


      after boot, X started.



      if grub
      linux /boot/vmlinuz ... ro init=/root/init.sh 3,can success boot into text mode.



      according to https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html , 3 is not a kernel’s command-line parameters, kernel will pass it as an argument to init, here is /root/init.sh.



      change /root/init.sh to :



      #!/bin/bash
      # do some task
      echo $1
      sleep 3s
      exec init 3


      I can see the value passed from kernel.



      In my submission,no matter what value grub -> kernel -> /root/init.sh , I will discard the value and exec init as runlevel 3. why it doesn't work.










      share|improve this question













      Ubuntu 16.04.5 default environment.



      I want to do some custom job before init. grub.cfg as



      linux /boot/vmlinuz ... ro init=/root/init.sh



      init.sh:



      #!/bin/bash
      # do some task
      exec init 3


      after boot, X started.



      if grub
      linux /boot/vmlinuz ... ro init=/root/init.sh 3,can success boot into text mode.



      according to https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html , 3 is not a kernel’s command-line parameters, kernel will pass it as an argument to init, here is /root/init.sh.



      change /root/init.sh to :



      #!/bin/bash
      # do some task
      echo $1
      sleep 3s
      exec init 3


      I can see the value passed from kernel.



      In my submission,no matter what value grub -> kernel -> /root/init.sh , I will discard the value and exec init as runlevel 3. why it doesn't work.







      boot grub2 bash kernel init






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 6:57









      Bin Zhou

      1




      1






















          1 Answer
          1






          active

          oldest

          votes


















          0














          according to poettering's response to my issue at systemd: https://github.com/systemd/systemd/issues/10752




          we generally read /proc/cmdline, not argv, since the kernel removes some bits from the latter that we need to know. We essentially ignore argv altogether.



          Hence, what you are trying to do doesn't work, you'd have to overmount /proc/cmdline instead with some file with the new arguments.




          about 'overmount', according to https://unix.stackexchange.com/questions/364442/cant-mount-on-proc-cmdline/364448 ,




          1. make a copy of /proc/cmdline at /root/cmdline

          2. add 3 at the end of /root/cmdline

          3. run command mount -n --bind -o ro /root/cmdline /proc/cmdline

          4. run command exec init


          now system will boot with runlevel 3.



          In summary, change /root/init.sh to



          #!/bin/bash
          # do some task
          cp /proc/cmdline /root/cmdline
          sed -i.bck '$s/$/ 3/' /root/cmdline
          mount -n --bind -o ro /root/cmdline /proc/cmdline
          exec init


          system will boot into text mode after custom job finish as I except.






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "89"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2faskubuntu.com%2fquestions%2f1092451%2fubuntu-16-04-boot-as-init-root-init-sh-and-exec-init-3-in-shell-but-why-x11-st%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









            0














            according to poettering's response to my issue at systemd: https://github.com/systemd/systemd/issues/10752




            we generally read /proc/cmdline, not argv, since the kernel removes some bits from the latter that we need to know. We essentially ignore argv altogether.



            Hence, what you are trying to do doesn't work, you'd have to overmount /proc/cmdline instead with some file with the new arguments.




            about 'overmount', according to https://unix.stackexchange.com/questions/364442/cant-mount-on-proc-cmdline/364448 ,




            1. make a copy of /proc/cmdline at /root/cmdline

            2. add 3 at the end of /root/cmdline

            3. run command mount -n --bind -o ro /root/cmdline /proc/cmdline

            4. run command exec init


            now system will boot with runlevel 3.



            In summary, change /root/init.sh to



            #!/bin/bash
            # do some task
            cp /proc/cmdline /root/cmdline
            sed -i.bck '$s/$/ 3/' /root/cmdline
            mount -n --bind -o ro /root/cmdline /proc/cmdline
            exec init


            system will boot into text mode after custom job finish as I except.






            share|improve this answer


























              0














              according to poettering's response to my issue at systemd: https://github.com/systemd/systemd/issues/10752




              we generally read /proc/cmdline, not argv, since the kernel removes some bits from the latter that we need to know. We essentially ignore argv altogether.



              Hence, what you are trying to do doesn't work, you'd have to overmount /proc/cmdline instead with some file with the new arguments.




              about 'overmount', according to https://unix.stackexchange.com/questions/364442/cant-mount-on-proc-cmdline/364448 ,




              1. make a copy of /proc/cmdline at /root/cmdline

              2. add 3 at the end of /root/cmdline

              3. run command mount -n --bind -o ro /root/cmdline /proc/cmdline

              4. run command exec init


              now system will boot with runlevel 3.



              In summary, change /root/init.sh to



              #!/bin/bash
              # do some task
              cp /proc/cmdline /root/cmdline
              sed -i.bck '$s/$/ 3/' /root/cmdline
              mount -n --bind -o ro /root/cmdline /proc/cmdline
              exec init


              system will boot into text mode after custom job finish as I except.






              share|improve this answer
























                0












                0








                0






                according to poettering's response to my issue at systemd: https://github.com/systemd/systemd/issues/10752




                we generally read /proc/cmdline, not argv, since the kernel removes some bits from the latter that we need to know. We essentially ignore argv altogether.



                Hence, what you are trying to do doesn't work, you'd have to overmount /proc/cmdline instead with some file with the new arguments.




                about 'overmount', according to https://unix.stackexchange.com/questions/364442/cant-mount-on-proc-cmdline/364448 ,




                1. make a copy of /proc/cmdline at /root/cmdline

                2. add 3 at the end of /root/cmdline

                3. run command mount -n --bind -o ro /root/cmdline /proc/cmdline

                4. run command exec init


                now system will boot with runlevel 3.



                In summary, change /root/init.sh to



                #!/bin/bash
                # do some task
                cp /proc/cmdline /root/cmdline
                sed -i.bck '$s/$/ 3/' /root/cmdline
                mount -n --bind -o ro /root/cmdline /proc/cmdline
                exec init


                system will boot into text mode after custom job finish as I except.






                share|improve this answer












                according to poettering's response to my issue at systemd: https://github.com/systemd/systemd/issues/10752




                we generally read /proc/cmdline, not argv, since the kernel removes some bits from the latter that we need to know. We essentially ignore argv altogether.



                Hence, what you are trying to do doesn't work, you'd have to overmount /proc/cmdline instead with some file with the new arguments.




                about 'overmount', according to https://unix.stackexchange.com/questions/364442/cant-mount-on-proc-cmdline/364448 ,




                1. make a copy of /proc/cmdline at /root/cmdline

                2. add 3 at the end of /root/cmdline

                3. run command mount -n --bind -o ro /root/cmdline /proc/cmdline

                4. run command exec init


                now system will boot with runlevel 3.



                In summary, change /root/init.sh to



                #!/bin/bash
                # do some task
                cp /proc/cmdline /root/cmdline
                sed -i.bck '$s/$/ 3/' /root/cmdline
                mount -n --bind -o ro /root/cmdline /proc/cmdline
                exec init


                system will boot into text mode after custom job finish as I except.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 '18 at 13:34









                Bin Zhou

                1




                1






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • 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%2faskubuntu.com%2fquestions%2f1092451%2fubuntu-16-04-boot-as-init-root-init-sh-and-exec-init-3-in-shell-but-why-x11-st%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

                    How to make a Squid Proxy server?

                    Is this a new Fibonacci Identity?

                    Touch on Surface Book