How to swap root volume without rebooting server

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
-1
down vote

favorite












Context



My product provisions spot instances on AWS. The instances should appear identical after a user terminates, and then recreates that instance (we need to remount the volume). AWS suggests temporarily shutting down instances, and then swapping the volume via their API; unfortunately, they don't support this for all combinations of spot pricing & instance types.



NB: Depending on instance type, when you attach /dev/sdf it may show up as /dev/nvme1n1p1 instead.



What I've Tried



/sbin/init doesn't appear to do anything after running this script. I tried exec switch_root /next_root /sbin/init at some point to tidy things but that didn't work either.



sudo mkdir -p /next_root
sudo rm /sbin/init

# if the output of lsblk contains "nvme1n1p1"
# then DEVICE="nvme1n1p1"
# else DEVICE="sdf"
DEVICE="sdf" && [[ $(lsblk) = *"nvme1n1p1"* ]] && DEVICE="nvme1n1p1"
DEVICE="/dev/$DEVICE"

sudo e2label $DEVICE next_root
sudo tune2fs $DEVICE -U `uuidgen`

sudo tee /sbin/init > /dev/null <<EOF
#!/bin/sh

mount $DEVICE /next_root

cd /next_root
mkdir -p ./old_root
pivot_root . ./old_root

mount --move /sys ./sys
mount --move /proc ./proc
mount --move /dev ./dev
mount --move /run ./run

exec chroot . /sbin/init
EOF

sudo chmod +x /sbin/init
sudo telinit u


I also tried pivot_root as su but stderr reported pivot_root: failed to change root from '.' to './old_root': Invalid argument



# ...

sudo su - <<EOF
mount $DEVICE /next_root

cd /next_root
mkdir -p ./old_root
pivot_root . ./old_root

# ...

exec chroot . /sbin/init
EOF


I've been stumped on this one for a few days and would really appreciate your help!



Thank you for reading.







share|improve this question



























    up vote
    -1
    down vote

    favorite












    Context



    My product provisions spot instances on AWS. The instances should appear identical after a user terminates, and then recreates that instance (we need to remount the volume). AWS suggests temporarily shutting down instances, and then swapping the volume via their API; unfortunately, they don't support this for all combinations of spot pricing & instance types.



    NB: Depending on instance type, when you attach /dev/sdf it may show up as /dev/nvme1n1p1 instead.



    What I've Tried



    /sbin/init doesn't appear to do anything after running this script. I tried exec switch_root /next_root /sbin/init at some point to tidy things but that didn't work either.



    sudo mkdir -p /next_root
    sudo rm /sbin/init

    # if the output of lsblk contains "nvme1n1p1"
    # then DEVICE="nvme1n1p1"
    # else DEVICE="sdf"
    DEVICE="sdf" && [[ $(lsblk) = *"nvme1n1p1"* ]] && DEVICE="nvme1n1p1"
    DEVICE="/dev/$DEVICE"

    sudo e2label $DEVICE next_root
    sudo tune2fs $DEVICE -U `uuidgen`

    sudo tee /sbin/init > /dev/null <<EOF
    #!/bin/sh

    mount $DEVICE /next_root

    cd /next_root
    mkdir -p ./old_root
    pivot_root . ./old_root

    mount --move /sys ./sys
    mount --move /proc ./proc
    mount --move /dev ./dev
    mount --move /run ./run

    exec chroot . /sbin/init
    EOF

    sudo chmod +x /sbin/init
    sudo telinit u


    I also tried pivot_root as su but stderr reported pivot_root: failed to change root from '.' to './old_root': Invalid argument



    # ...

    sudo su - <<EOF
    mount $DEVICE /next_root

    cd /next_root
    mkdir -p ./old_root
    pivot_root . ./old_root

    # ...

    exec chroot . /sbin/init
    EOF


    I've been stumped on this one for a few days and would really appreciate your help!



    Thank you for reading.







    share|improve this question























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      Context



      My product provisions spot instances on AWS. The instances should appear identical after a user terminates, and then recreates that instance (we need to remount the volume). AWS suggests temporarily shutting down instances, and then swapping the volume via their API; unfortunately, they don't support this for all combinations of spot pricing & instance types.



      NB: Depending on instance type, when you attach /dev/sdf it may show up as /dev/nvme1n1p1 instead.



      What I've Tried



      /sbin/init doesn't appear to do anything after running this script. I tried exec switch_root /next_root /sbin/init at some point to tidy things but that didn't work either.



      sudo mkdir -p /next_root
      sudo rm /sbin/init

      # if the output of lsblk contains "nvme1n1p1"
      # then DEVICE="nvme1n1p1"
      # else DEVICE="sdf"
      DEVICE="sdf" && [[ $(lsblk) = *"nvme1n1p1"* ]] && DEVICE="nvme1n1p1"
      DEVICE="/dev/$DEVICE"

      sudo e2label $DEVICE next_root
      sudo tune2fs $DEVICE -U `uuidgen`

      sudo tee /sbin/init > /dev/null <<EOF
      #!/bin/sh

      mount $DEVICE /next_root

      cd /next_root
      mkdir -p ./old_root
      pivot_root . ./old_root

      mount --move /sys ./sys
      mount --move /proc ./proc
      mount --move /dev ./dev
      mount --move /run ./run

      exec chroot . /sbin/init
      EOF

      sudo chmod +x /sbin/init
      sudo telinit u


      I also tried pivot_root as su but stderr reported pivot_root: failed to change root from '.' to './old_root': Invalid argument



      # ...

      sudo su - <<EOF
      mount $DEVICE /next_root

      cd /next_root
      mkdir -p ./old_root
      pivot_root . ./old_root

      # ...

      exec chroot . /sbin/init
      EOF


      I've been stumped on this one for a few days and would really appreciate your help!



      Thank you for reading.







      share|improve this question













      Context



      My product provisions spot instances on AWS. The instances should appear identical after a user terminates, and then recreates that instance (we need to remount the volume). AWS suggests temporarily shutting down instances, and then swapping the volume via their API; unfortunately, they don't support this for all combinations of spot pricing & instance types.



      NB: Depending on instance type, when you attach /dev/sdf it may show up as /dev/nvme1n1p1 instead.



      What I've Tried



      /sbin/init doesn't appear to do anything after running this script. I tried exec switch_root /next_root /sbin/init at some point to tidy things but that didn't work either.



      sudo mkdir -p /next_root
      sudo rm /sbin/init

      # if the output of lsblk contains "nvme1n1p1"
      # then DEVICE="nvme1n1p1"
      # else DEVICE="sdf"
      DEVICE="sdf" && [[ $(lsblk) = *"nvme1n1p1"* ]] && DEVICE="nvme1n1p1"
      DEVICE="/dev/$DEVICE"

      sudo e2label $DEVICE next_root
      sudo tune2fs $DEVICE -U `uuidgen`

      sudo tee /sbin/init > /dev/null <<EOF
      #!/bin/sh

      mount $DEVICE /next_root

      cd /next_root
      mkdir -p ./old_root
      pivot_root . ./old_root

      mount --move /sys ./sys
      mount --move /proc ./proc
      mount --move /dev ./dev
      mount --move /run ./run

      exec chroot . /sbin/init
      EOF

      sudo chmod +x /sbin/init
      sudo telinit u


      I also tried pivot_root as su but stderr reported pivot_root: failed to change root from '.' to './old_root': Invalid argument



      # ...

      sudo su - <<EOF
      mount $DEVICE /next_root

      cd /next_root
      mkdir -p ./old_root
      pivot_root . ./old_root

      # ...

      exec chroot . /sbin/init
      EOF


      I've been stumped on this one for a few days and would really appreciate your help!



      Thank you for reading.









      share|improve this question












      share|improve this question




      share|improve this question








      edited Aug 4 at 2:47
























      asked Aug 4 at 2:26









      Ashton War

      991




      991

























          active

          oldest

          votes











          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%2f460446%2fhow-to-swap-root-volume-without-rebooting-server%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460446%2fhow-to-swap-root-volume-without-rebooting-server%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