阅读背景:

AWS EC2:如何使用pivot_root重新挂载之前的EBS卷?

来源:互联网 

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.

我启动了一个EC2 Spot实例,并检查了EBS根卷的“在终止时删除”选项。我选择了Ubuntu 14.04 64位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.

在某些情况下,由于最大价格,实例被终止,而EBS卷按预期保留。现在,当Spot实例重新启动时,它将创建一个全新的EBS根卷。旧的EBS根卷仍然放在那里。

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.

实际上,我通过手动终止Spot实例并启动一个新的实例来模拟上述事件,但我假设在实际使用中结果是相同的。

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

那么,如何将旧的EBS卷重新挂载为当前根卷?

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

我尝试了https://linux.die.net/man/8/pivot_root的例子,做了一些修改以避免明显的错误:

# 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.

终端挂在exec chroot命令上,实例不接受新的ssh连接。

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.

我非常希望这个机制能够正常工作,因为它提供了一种方便的机制,可以节省开发、测试和面向批处理的EC2实例的按需价格,而不必重新架构整个应用程序部署,也不必承担保留实例的义务。

What am I missing?

我缺少什么?

1 个解决方案

#1


2  

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

答案是将pivot_root调用放在/sbin/init的初始(ephemeral) EBS根卷中。

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:

以下是一些脚本,它们可以自动启动一个新的Spot实例,并在第1 (ephemeral) EBS卷上修改/sbin/init,以从第2(持久)EBS卷加载系统:

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

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


分享到: