How to swap root volume without rebooting server
Clash 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.
ubuntu chroot block-device amazon-ec2
add a comment |Â
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.
ubuntu chroot block-device amazon-ec2
add a comment |Â
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.
ubuntu chroot block-device amazon-ec2
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.
ubuntu chroot block-device amazon-ec2
edited Aug 4 at 2:47
asked Aug 4 at 2:26
Ashton War
991
991
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password