How do you completely switch the root files system on Linux?

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











up vote
2
down vote

favorite
1












I am running my rootfs on a flash device (MTD device with UBIFS) - Note: it's a bitbake system so its not full-blown ubuntu or anything.



I want to be able to format that device and write a new rootfs to it, and so I need to ubidetach this device, which I can do, but in order to do that I have to kill off every process/shell/app, etc... that ever lived - i.e. a similar list to if you do:



fuser -vm /dev.



So my attempt so far (that does work to a degree) is using pivot_root where I do the following:



  1. Copy the bin, sbin, lib etc... into my new /tmp_root/ folder

  2. Mount/bind /proc, /sys, dev, run into /tmp_root/

  3. Call pivot_root

  4. Unmount everything from oldroot

  5. Kill of all processes that are related to oldroot/dev

  6. unmount oldroot

This works ok - and at this point I can detatch the UBIFS an flash the MTD device. However I have had to kill off all the apps that are runnings - which is not very useful!



So, what I want to do is (at least as a trial) instead of pivot_root do a switch_root, or some such, and then I can run up all my apps AND (hopfully) flash the MTD device. Normally this is initramtfs (or so I have read), but in my case I just want to do some testing and switch file system on an already running rootfs.



With the same /tmp_root folder that I created I have tried:



  • exec switch_root /tmp_root /sbin/init

  • exec -c /dev/console switch_root /tmp_root /sbin/init

But I always get the same sort of result somthing like:




old root filesystem is not an initramfs: invalid argument




I am a bit stuck, is it even possible to completely switch the rootfs once the system is up and running?



note: running linux kernel 4.1.x










share|improve this question



























    up vote
    2
    down vote

    favorite
    1












    I am running my rootfs on a flash device (MTD device with UBIFS) - Note: it's a bitbake system so its not full-blown ubuntu or anything.



    I want to be able to format that device and write a new rootfs to it, and so I need to ubidetach this device, which I can do, but in order to do that I have to kill off every process/shell/app, etc... that ever lived - i.e. a similar list to if you do:



    fuser -vm /dev.



    So my attempt so far (that does work to a degree) is using pivot_root where I do the following:



    1. Copy the bin, sbin, lib etc... into my new /tmp_root/ folder

    2. Mount/bind /proc, /sys, dev, run into /tmp_root/

    3. Call pivot_root

    4. Unmount everything from oldroot

    5. Kill of all processes that are related to oldroot/dev

    6. unmount oldroot

    This works ok - and at this point I can detatch the UBIFS an flash the MTD device. However I have had to kill off all the apps that are runnings - which is not very useful!



    So, what I want to do is (at least as a trial) instead of pivot_root do a switch_root, or some such, and then I can run up all my apps AND (hopfully) flash the MTD device. Normally this is initramtfs (or so I have read), but in my case I just want to do some testing and switch file system on an already running rootfs.



    With the same /tmp_root folder that I created I have tried:



    • exec switch_root /tmp_root /sbin/init

    • exec -c /dev/console switch_root /tmp_root /sbin/init

    But I always get the same sort of result somthing like:




    old root filesystem is not an initramfs: invalid argument




    I am a bit stuck, is it even possible to completely switch the rootfs once the system is up and running?



    note: running linux kernel 4.1.x










    share|improve this question

























      up vote
      2
      down vote

      favorite
      1









      up vote
      2
      down vote

      favorite
      1






      1





      I am running my rootfs on a flash device (MTD device with UBIFS) - Note: it's a bitbake system so its not full-blown ubuntu or anything.



      I want to be able to format that device and write a new rootfs to it, and so I need to ubidetach this device, which I can do, but in order to do that I have to kill off every process/shell/app, etc... that ever lived - i.e. a similar list to if you do:



      fuser -vm /dev.



      So my attempt so far (that does work to a degree) is using pivot_root where I do the following:



      1. Copy the bin, sbin, lib etc... into my new /tmp_root/ folder

      2. Mount/bind /proc, /sys, dev, run into /tmp_root/

      3. Call pivot_root

      4. Unmount everything from oldroot

      5. Kill of all processes that are related to oldroot/dev

      6. unmount oldroot

      This works ok - and at this point I can detatch the UBIFS an flash the MTD device. However I have had to kill off all the apps that are runnings - which is not very useful!



      So, what I want to do is (at least as a trial) instead of pivot_root do a switch_root, or some such, and then I can run up all my apps AND (hopfully) flash the MTD device. Normally this is initramtfs (or so I have read), but in my case I just want to do some testing and switch file system on an already running rootfs.



      With the same /tmp_root folder that I created I have tried:



      • exec switch_root /tmp_root /sbin/init

      • exec -c /dev/console switch_root /tmp_root /sbin/init

      But I always get the same sort of result somthing like:




      old root filesystem is not an initramfs: invalid argument




      I am a bit stuck, is it even possible to completely switch the rootfs once the system is up and running?



      note: running linux kernel 4.1.x










      share|improve this question















      I am running my rootfs on a flash device (MTD device with UBIFS) - Note: it's a bitbake system so its not full-blown ubuntu or anything.



      I want to be able to format that device and write a new rootfs to it, and so I need to ubidetach this device, which I can do, but in order to do that I have to kill off every process/shell/app, etc... that ever lived - i.e. a similar list to if you do:



      fuser -vm /dev.



      So my attempt so far (that does work to a degree) is using pivot_root where I do the following:



      1. Copy the bin, sbin, lib etc... into my new /tmp_root/ folder

      2. Mount/bind /proc, /sys, dev, run into /tmp_root/

      3. Call pivot_root

      4. Unmount everything from oldroot

      5. Kill of all processes that are related to oldroot/dev

      6. unmount oldroot

      This works ok - and at this point I can detatch the UBIFS an flash the MTD device. However I have had to kill off all the apps that are runnings - which is not very useful!



      So, what I want to do is (at least as a trial) instead of pivot_root do a switch_root, or some such, and then I can run up all my apps AND (hopfully) flash the MTD device. Normally this is initramtfs (or so I have read), but in my case I just want to do some testing and switch file system on an already running rootfs.



      With the same /tmp_root folder that I created I have tried:



      • exec switch_root /tmp_root /sbin/init

      • exec -c /dev/console switch_root /tmp_root /sbin/init

      But I always get the same sort of result somthing like:




      old root filesystem is not an initramfs: invalid argument




      I am a bit stuck, is it even possible to completely switch the rootfs once the system is up and running?



      note: running linux kernel 4.1.x







      linux initramfs root-filesystem ubifs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 4 at 11:17

























      asked Oct 4 at 10:24









      code_fodder

      1235




      1235




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          INFO:



          switch_root




          switch_root moves already mounted /proc, /dev, /sys and /run to
          newroot and makes newroot the new root filesystem and starts init
          process.




          init




          The program init is the process with process ID 1. It is responsible
          for initializing the system in the required way. init is started
          directly by the kernel and resists signal 9, which normally kills
          processes. All other programs are either started directly by init or
          by one of its child processes.




          Any programs, daemons, modules (?) started before switch_root is started by init process 1. switch_root will kill that init therefore all started after init is killed, gone.



          You new rootfs must have the modules (?), programs, daemons for the new init to start. It is the new process 1 that will reload modules (?), restart daemons, and spawn user programs.




          "I want to be able to format that device and write a new rootfs to it"



          Assume you have the new rootfs built already and ready to "install".



          After you format how will you boot into this? Is this why you want to switch_root because it is already booted?



          If yes switch_root may not be the tool you need.



          Other tools that may allow you to format and copy your new rootfs.



          • Your boot loader.

          • A live linux distro installed on a bootable USB.

          • A custom bitbaked filesystem with only the bare minimum need to boot the system and tools (programs) need to partition, format and copy. This will ether be on another 'drive' a different partition on the MTD or even on a USB or a memory only initramfs that is part of the bzImage.

          • Your new rootfs that is temporally on another partition like an USB. Must adjust your boot loader to boot from it in place of the current kernel and rootfs.

          • Network boot ether PXE or even a NFS.

          Does this help at all?






          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%2f473192%2fhow-do-you-completely-switch-the-root-files-system-on-linux%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













            INFO:



            switch_root




            switch_root moves already mounted /proc, /dev, /sys and /run to
            newroot and makes newroot the new root filesystem and starts init
            process.




            init




            The program init is the process with process ID 1. It is responsible
            for initializing the system in the required way. init is started
            directly by the kernel and resists signal 9, which normally kills
            processes. All other programs are either started directly by init or
            by one of its child processes.




            Any programs, daemons, modules (?) started before switch_root is started by init process 1. switch_root will kill that init therefore all started after init is killed, gone.



            You new rootfs must have the modules (?), programs, daemons for the new init to start. It is the new process 1 that will reload modules (?), restart daemons, and spawn user programs.




            "I want to be able to format that device and write a new rootfs to it"



            Assume you have the new rootfs built already and ready to "install".



            After you format how will you boot into this? Is this why you want to switch_root because it is already booted?



            If yes switch_root may not be the tool you need.



            Other tools that may allow you to format and copy your new rootfs.



            • Your boot loader.

            • A live linux distro installed on a bootable USB.

            • A custom bitbaked filesystem with only the bare minimum need to boot the system and tools (programs) need to partition, format and copy. This will ether be on another 'drive' a different partition on the MTD or even on a USB or a memory only initramfs that is part of the bzImage.

            • Your new rootfs that is temporally on another partition like an USB. Must adjust your boot loader to boot from it in place of the current kernel and rootfs.

            • Network boot ether PXE or even a NFS.

            Does this help at all?






            share|improve this answer


























              up vote
              0
              down vote













              INFO:



              switch_root




              switch_root moves already mounted /proc, /dev, /sys and /run to
              newroot and makes newroot the new root filesystem and starts init
              process.




              init




              The program init is the process with process ID 1. It is responsible
              for initializing the system in the required way. init is started
              directly by the kernel and resists signal 9, which normally kills
              processes. All other programs are either started directly by init or
              by one of its child processes.




              Any programs, daemons, modules (?) started before switch_root is started by init process 1. switch_root will kill that init therefore all started after init is killed, gone.



              You new rootfs must have the modules (?), programs, daemons for the new init to start. It is the new process 1 that will reload modules (?), restart daemons, and spawn user programs.




              "I want to be able to format that device and write a new rootfs to it"



              Assume you have the new rootfs built already and ready to "install".



              After you format how will you boot into this? Is this why you want to switch_root because it is already booted?



              If yes switch_root may not be the tool you need.



              Other tools that may allow you to format and copy your new rootfs.



              • Your boot loader.

              • A live linux distro installed on a bootable USB.

              • A custom bitbaked filesystem with only the bare minimum need to boot the system and tools (programs) need to partition, format and copy. This will ether be on another 'drive' a different partition on the MTD or even on a USB or a memory only initramfs that is part of the bzImage.

              • Your new rootfs that is temporally on another partition like an USB. Must adjust your boot loader to boot from it in place of the current kernel and rootfs.

              • Network boot ether PXE or even a NFS.

              Does this help at all?






              share|improve this answer
























                up vote
                0
                down vote










                up vote
                0
                down vote









                INFO:



                switch_root




                switch_root moves already mounted /proc, /dev, /sys and /run to
                newroot and makes newroot the new root filesystem and starts init
                process.




                init




                The program init is the process with process ID 1. It is responsible
                for initializing the system in the required way. init is started
                directly by the kernel and resists signal 9, which normally kills
                processes. All other programs are either started directly by init or
                by one of its child processes.




                Any programs, daemons, modules (?) started before switch_root is started by init process 1. switch_root will kill that init therefore all started after init is killed, gone.



                You new rootfs must have the modules (?), programs, daemons for the new init to start. It is the new process 1 that will reload modules (?), restart daemons, and spawn user programs.




                "I want to be able to format that device and write a new rootfs to it"



                Assume you have the new rootfs built already and ready to "install".



                After you format how will you boot into this? Is this why you want to switch_root because it is already booted?



                If yes switch_root may not be the tool you need.



                Other tools that may allow you to format and copy your new rootfs.



                • Your boot loader.

                • A live linux distro installed on a bootable USB.

                • A custom bitbaked filesystem with only the bare minimum need to boot the system and tools (programs) need to partition, format and copy. This will ether be on another 'drive' a different partition on the MTD or even on a USB or a memory only initramfs that is part of the bzImage.

                • Your new rootfs that is temporally on another partition like an USB. Must adjust your boot loader to boot from it in place of the current kernel and rootfs.

                • Network boot ether PXE or even a NFS.

                Does this help at all?






                share|improve this answer














                INFO:



                switch_root




                switch_root moves already mounted /proc, /dev, /sys and /run to
                newroot and makes newroot the new root filesystem and starts init
                process.




                init




                The program init is the process with process ID 1. It is responsible
                for initializing the system in the required way. init is started
                directly by the kernel and resists signal 9, which normally kills
                processes. All other programs are either started directly by init or
                by one of its child processes.




                Any programs, daemons, modules (?) started before switch_root is started by init process 1. switch_root will kill that init therefore all started after init is killed, gone.



                You new rootfs must have the modules (?), programs, daemons for the new init to start. It is the new process 1 that will reload modules (?), restart daemons, and spawn user programs.




                "I want to be able to format that device and write a new rootfs to it"



                Assume you have the new rootfs built already and ready to "install".



                After you format how will you boot into this? Is this why you want to switch_root because it is already booted?



                If yes switch_root may not be the tool you need.



                Other tools that may allow you to format and copy your new rootfs.



                • Your boot loader.

                • A live linux distro installed on a bootable USB.

                • A custom bitbaked filesystem with only the bare minimum need to boot the system and tools (programs) need to partition, format and copy. This will ether be on another 'drive' a different partition on the MTD or even on a USB or a memory only initramfs that is part of the bzImage.

                • Your new rootfs that is temporally on another partition like an USB. Must adjust your boot loader to boot from it in place of the current kernel and rootfs.

                • Network boot ether PXE or even a NFS.

                Does this help at all?







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Oct 4 at 15:50

























                answered Oct 4 at 15:34









                jc__

                1,338517




                1,338517



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473192%2fhow-do-you-completely-switch-the-root-files-system-on-linux%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