AWS EC2: How to remount previous EBS volume using pivot_root?

陌路散爱 提交于 2019-12-22 12:26:26

问题


I launched an EC2 Spot Instance and unchecked the "Delete On Termination" option for the EBS root volume. I chose the Ubuntu 14.04 64-bit HVM AMI.

At some point the instance got terminated due to max price and the EBS volume stayed behind as intended. Now eventually when the Spot Instance is relaunched it creates a brand-new EBS root volume. The old EBS root volume is still sitting out there.

Actually I simulated the above events for testing purposes by manually terminating the Spot Instance and launching a new one, but I assume the result would be the same in real usage.

So now, how can I get the old EBS volume re-mounted as the current root volume?

I tried the example from http://linux.die.net/man/8/pivot_root, with a few modifications to get around obvious errors:

# manually attach old EBS to /dev/sdf in the AWS console, then do:
sudo su -
mkdir /new-root
mkdir /new-root/old-root
mount /dev/xvdf1 /new-root
cd /new-root
pivot_root . old-root
exec chroot . sh <dev/console >dev/console 2>&1
umount /old-root

The terminal hangs at the exec chroot command, and the instance won't accept new ssh connections.

I'd really like to get this working, as it provides a convenient mechanism to save money off the On Demand prices for development, test, and batch-oriented EC2 instances without having to re-architect the whole application deployment, and without the commitment of a Reserved Instance.

What am I missing?


回答1:


The answer is to place the pivot_root call inside of /sbin/init on the initial (ephemeral) EBS root volume.

Here are some scripts that automate the process of launching a new Spot Instance and modifying the /sbin/init on the 1st (ephemeral) EBS volume to chain-load the system from a 2nd (persistent) EBS volume:

https://github.com/atramos/ec2-spotter



来源:https://stackoverflow.com/questions/32108767/aws-ec2-how-to-remount-previous-ebs-volume-using-pivot-root

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!