chroot before pivot_root causes busy error

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite












# unshare -m
# mount --bind / /mnt
# cd /mnt
# chroot .
# pivot_root . mnt
pivot_root: failed to change root from `.' to `mnt': Device or resource busy


Why does it fail? I was following the instructions from man 2 pivot_mount.




pivot_root() may or may not change the current root and the current
working directory of any processes or threads which use the old root
directory. The caller of pivot_root() must ensure that processes with
root or current working directory at the old root operate correctly in
either case. An easy way to ensure this is to change their root and
current working directory to new_root before invoking pivot_root().




I don't see how this matches the documented EBUSY error.




ERRORS



pivot_root() may return (in errno) any of the errors returned by
stat(2). Additionally, it may return:



EBUSY new_root or put_old are on the current root filesystem, or a
filesystem is already mounted on put_old.








share|improve this question

























    up vote
    0
    down vote

    favorite












    # unshare -m
    # mount --bind / /mnt
    # cd /mnt
    # chroot .
    # pivot_root . mnt
    pivot_root: failed to change root from `.' to `mnt': Device or resource busy


    Why does it fail? I was following the instructions from man 2 pivot_mount.




    pivot_root() may or may not change the current root and the current
    working directory of any processes or threads which use the old root
    directory. The caller of pivot_root() must ensure that processes with
    root or current working directory at the old root operate correctly in
    either case. An easy way to ensure this is to change their root and
    current working directory to new_root before invoking pivot_root().




    I don't see how this matches the documented EBUSY error.




    ERRORS



    pivot_root() may return (in errno) any of the errors returned by
    stat(2). Additionally, it may return:



    EBUSY new_root or put_old are on the current root filesystem, or a
    filesystem is already mounted on put_old.








    share|improve this question





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      # unshare -m
      # mount --bind / /mnt
      # cd /mnt
      # chroot .
      # pivot_root . mnt
      pivot_root: failed to change root from `.' to `mnt': Device or resource busy


      Why does it fail? I was following the instructions from man 2 pivot_mount.




      pivot_root() may or may not change the current root and the current
      working directory of any processes or threads which use the old root
      directory. The caller of pivot_root() must ensure that processes with
      root or current working directory at the old root operate correctly in
      either case. An easy way to ensure this is to change their root and
      current working directory to new_root before invoking pivot_root().




      I don't see how this matches the documented EBUSY error.




      ERRORS



      pivot_root() may return (in errno) any of the errors returned by
      stat(2). Additionally, it may return:



      EBUSY new_root or put_old are on the current root filesystem, or a
      filesystem is already mounted on put_old.








      share|improve this question











      # unshare -m
      # mount --bind / /mnt
      # cd /mnt
      # chroot .
      # pivot_root . mnt
      pivot_root: failed to change root from `.' to `mnt': Device or resource busy


      Why does it fail? I was following the instructions from man 2 pivot_mount.




      pivot_root() may or may not change the current root and the current
      working directory of any processes or threads which use the old root
      directory. The caller of pivot_root() must ensure that processes with
      root or current working directory at the old root operate correctly in
      either case. An easy way to ensure this is to change their root and
      current working directory to new_root before invoking pivot_root().




      I don't see how this matches the documented EBUSY error.




      ERRORS



      pivot_root() may return (in errno) any of the errors returned by
      stat(2). Additionally, it may return:



      EBUSY new_root or put_old are on the current root filesystem, or a
      filesystem is already mounted on put_old.










      share|improve this question










      share|improve this question




      share|improve this question









      asked Jul 18 at 15:42









      sourcejedi

      18k22375




      18k22375




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          That part of the manpage is misleading. Generally you want a different ordering, as described in man 8 pivot_root.



          cd new_root # chdir(new_root);
          pivot_root . put_old # pivot_root(".", put_old);
          exec chroot . # chroot(".");


          This seems to be yet another subtle detail with pivot_root. Although the point of pivot_root is to rearrange the mount namespace, the kernel code seems to say that the root filesystem that it moves is determined by the per-process root, which is what chroot sets.



          As a result, we hit the error "new_root or put_old are on the current root filesystem".



          This subtle detail of pivot_root is necessary in order for it to work at all on modern Linux. If it was defined to work on the root mount of the mount namespace, it would try to move the special rootfs filesystem which you normally can't see. But this is not allowed, because rootfs must always be the root mount of the namespace.




          We can confirm pivot_root works this way, by continuing the example as follows.



          # unshare -m
          # mount --bind / /mnt
          # cd /mnt
          # chroot /mnt
          # pivot_root . mnt
          pivot_root: failed to change root from `.' to `mnt': Device or resource busy

          # exit # leave chroot
          # mount --bind . mnt
          # cd mnt
          # mount --bind /proc proc
          # findmnt | grep mnt
          └─/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
          └─/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
          └─/mnt/proc proc proc rw,nosuid,nodev,noexec,relatime

          # chroot /mnt # re-enter chroot
          # cd /mnt
          # pivot_root . mnt # this one works
          # exit # leave chroot
          # findmnt | grep mnt
          └─/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
          ├─/mnt/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
          └─/mnt/proc /dev/mapper/alan_dell_2016-fedora[/proc] ext4 rw,relatime,seclabel


          The second pivot_root call works. But it didn't have any effect on the root of the mount namespace. Looking from outside the chroot, it swapped /mnt and /mnt/mnt.






          share|improve this answer























            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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f457040%2fchroot-before-pivot-root-causes-busy-error%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            That part of the manpage is misleading. Generally you want a different ordering, as described in man 8 pivot_root.



            cd new_root # chdir(new_root);
            pivot_root . put_old # pivot_root(".", put_old);
            exec chroot . # chroot(".");


            This seems to be yet another subtle detail with pivot_root. Although the point of pivot_root is to rearrange the mount namespace, the kernel code seems to say that the root filesystem that it moves is determined by the per-process root, which is what chroot sets.



            As a result, we hit the error "new_root or put_old are on the current root filesystem".



            This subtle detail of pivot_root is necessary in order for it to work at all on modern Linux. If it was defined to work on the root mount of the mount namespace, it would try to move the special rootfs filesystem which you normally can't see. But this is not allowed, because rootfs must always be the root mount of the namespace.




            We can confirm pivot_root works this way, by continuing the example as follows.



            # unshare -m
            # mount --bind / /mnt
            # cd /mnt
            # chroot /mnt
            # pivot_root . mnt
            pivot_root: failed to change root from `.' to `mnt': Device or resource busy

            # exit # leave chroot
            # mount --bind . mnt
            # cd mnt
            # mount --bind /proc proc
            # findmnt | grep mnt
            └─/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
            └─/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
            └─/mnt/proc proc proc rw,nosuid,nodev,noexec,relatime

            # chroot /mnt # re-enter chroot
            # cd /mnt
            # pivot_root . mnt # this one works
            # exit # leave chroot
            # findmnt | grep mnt
            └─/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
            ├─/mnt/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
            └─/mnt/proc /dev/mapper/alan_dell_2016-fedora[/proc] ext4 rw,relatime,seclabel


            The second pivot_root call works. But it didn't have any effect on the root of the mount namespace. Looking from outside the chroot, it swapped /mnt and /mnt/mnt.






            share|improve this answer



























              up vote
              0
              down vote



              accepted










              That part of the manpage is misleading. Generally you want a different ordering, as described in man 8 pivot_root.



              cd new_root # chdir(new_root);
              pivot_root . put_old # pivot_root(".", put_old);
              exec chroot . # chroot(".");


              This seems to be yet another subtle detail with pivot_root. Although the point of pivot_root is to rearrange the mount namespace, the kernel code seems to say that the root filesystem that it moves is determined by the per-process root, which is what chroot sets.



              As a result, we hit the error "new_root or put_old are on the current root filesystem".



              This subtle detail of pivot_root is necessary in order for it to work at all on modern Linux. If it was defined to work on the root mount of the mount namespace, it would try to move the special rootfs filesystem which you normally can't see. But this is not allowed, because rootfs must always be the root mount of the namespace.




              We can confirm pivot_root works this way, by continuing the example as follows.



              # unshare -m
              # mount --bind / /mnt
              # cd /mnt
              # chroot /mnt
              # pivot_root . mnt
              pivot_root: failed to change root from `.' to `mnt': Device or resource busy

              # exit # leave chroot
              # mount --bind . mnt
              # cd mnt
              # mount --bind /proc proc
              # findmnt | grep mnt
              └─/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
              └─/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
              └─/mnt/proc proc proc rw,nosuid,nodev,noexec,relatime

              # chroot /mnt # re-enter chroot
              # cd /mnt
              # pivot_root . mnt # this one works
              # exit # leave chroot
              # findmnt | grep mnt
              └─/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
              ├─/mnt/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
              └─/mnt/proc /dev/mapper/alan_dell_2016-fedora[/proc] ext4 rw,relatime,seclabel


              The second pivot_root call works. But it didn't have any effect on the root of the mount namespace. Looking from outside the chroot, it swapped /mnt and /mnt/mnt.






              share|improve this answer

























                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                That part of the manpage is misleading. Generally you want a different ordering, as described in man 8 pivot_root.



                cd new_root # chdir(new_root);
                pivot_root . put_old # pivot_root(".", put_old);
                exec chroot . # chroot(".");


                This seems to be yet another subtle detail with pivot_root. Although the point of pivot_root is to rearrange the mount namespace, the kernel code seems to say that the root filesystem that it moves is determined by the per-process root, which is what chroot sets.



                As a result, we hit the error "new_root or put_old are on the current root filesystem".



                This subtle detail of pivot_root is necessary in order for it to work at all on modern Linux. If it was defined to work on the root mount of the mount namespace, it would try to move the special rootfs filesystem which you normally can't see. But this is not allowed, because rootfs must always be the root mount of the namespace.




                We can confirm pivot_root works this way, by continuing the example as follows.



                # unshare -m
                # mount --bind / /mnt
                # cd /mnt
                # chroot /mnt
                # pivot_root . mnt
                pivot_root: failed to change root from `.' to `mnt': Device or resource busy

                # exit # leave chroot
                # mount --bind . mnt
                # cd mnt
                # mount --bind /proc proc
                # findmnt | grep mnt
                └─/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
                └─/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
                └─/mnt/proc proc proc rw,nosuid,nodev,noexec,relatime

                # chroot /mnt # re-enter chroot
                # cd /mnt
                # pivot_root . mnt # this one works
                # exit # leave chroot
                # findmnt | grep mnt
                └─/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
                ├─/mnt/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
                └─/mnt/proc /dev/mapper/alan_dell_2016-fedora[/proc] ext4 rw,relatime,seclabel


                The second pivot_root call works. But it didn't have any effect on the root of the mount namespace. Looking from outside the chroot, it swapped /mnt and /mnt/mnt.






                share|improve this answer















                That part of the manpage is misleading. Generally you want a different ordering, as described in man 8 pivot_root.



                cd new_root # chdir(new_root);
                pivot_root . put_old # pivot_root(".", put_old);
                exec chroot . # chroot(".");


                This seems to be yet another subtle detail with pivot_root. Although the point of pivot_root is to rearrange the mount namespace, the kernel code seems to say that the root filesystem that it moves is determined by the per-process root, which is what chroot sets.



                As a result, we hit the error "new_root or put_old are on the current root filesystem".



                This subtle detail of pivot_root is necessary in order for it to work at all on modern Linux. If it was defined to work on the root mount of the mount namespace, it would try to move the special rootfs filesystem which you normally can't see. But this is not allowed, because rootfs must always be the root mount of the namespace.




                We can confirm pivot_root works this way, by continuing the example as follows.



                # unshare -m
                # mount --bind / /mnt
                # cd /mnt
                # chroot /mnt
                # pivot_root . mnt
                pivot_root: failed to change root from `.' to `mnt': Device or resource busy

                # exit # leave chroot
                # mount --bind . mnt
                # cd mnt
                # mount --bind /proc proc
                # findmnt | grep mnt
                └─/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
                └─/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
                └─/mnt/proc proc proc rw,nosuid,nodev,noexec,relatime

                # chroot /mnt # re-enter chroot
                # cd /mnt
                # pivot_root . mnt # this one works
                # exit # leave chroot
                # findmnt | grep mnt
                └─/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
                ├─/mnt/mnt /dev/mapper/alan_dell_2016-fedora ext4 rw,relatime,seclabel
                └─/mnt/proc /dev/mapper/alan_dell_2016-fedora[/proc] ext4 rw,relatime,seclabel


                The second pivot_root call works. But it didn't have any effect on the root of the mount namespace. Looking from outside the chroot, it swapped /mnt and /mnt/mnt.







                share|improve this answer















                share|improve this answer



                share|improve this answer








                edited Jul 22 at 16:29


























                answered Jul 18 at 15:42









                sourcejedi

                18k22375




                18k22375






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f457040%2fchroot-before-pivot-root-causes-busy-error%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay