AWS EC2:如何使用ivot_root重新装载以前的EBS卷? [英] AWS EC2: How to remount previous EBS volume using pivot_root?

查看:191
本文介绍了AWS EC2:如何使用ivot_root重新装载以前的EBS卷?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我启动了EC2竞价型实例,并且未选中EBS根卷的终止时删除选项。我选择了Ubuntu 14.04 64位HVM AMI。



在某个时候,该实例由于最高价格而被终止,而EBS数量仍按预期滞后。现在,最终,当重新启动竞价型实例时,它将创建一个全新的EBS根卷。旧的EBS根卷仍然在那里。



实际上,为了测试目的,我通过手动终止竞价型实例并启动一个新实例来模拟上述事件,但是我认为结果在实际使用中是相同的。 / p>

所以现在,我如何才能将旧的EBS卷重新安装为当前的根卷?



I在 http://linux.die.net/man/8/pivot_root 中尝试了该示例,并进行了一些修改以解决明显的错误:

 #在AWS控制台中手动将旧EBS附加到/ dev / sdf,然后做:
sudo su-
mkdir / new-root
mkdir / new-root / old-root
mount / dev / xvdf1 / new-root
cd / new-root
ivot_root。老根
exec chroot。 sh< dev / console> dev / console 2>& 1
umount / old-root

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



我真的很想让这个工作正常进行,因为它提供了一种方便的机制来节省开发,测试和面向批处理的EC2实例的按需价格。



我缺少了什么?

解决方案

答案是将 pivot_root 调用放在 / sbin / init 关于初始(临时)EBS根卷。



以下是一些脚本,这些脚本可自动启动新竞价型实例并修改 / sbin / init 在第一个(临时)EBS卷上,以从第二个(持久)EBS卷进行链式加载系统:



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


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?

解决方案

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

这篇关于AWS EC2:如何使用ivot_root重新装载以前的EBS卷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆