AWS EC2 - 使用 运行 实例附加更大的卷

AWS EC2 - Attach Larger Volume with run-instances

我在使用 aws ec2 run-instances 的单个命令中启动 EC2 实例和增加根分区的大小时遇到​​困难:

aws ec2 run-instances \
--image-id ami-0b33d91d \
--count 1 \
--instance-type m3.2xlarge \
--key-name my_key \
--security-group-ids "sg-xxxxxxx" \
--ebs-optimized \
--block-device-mapping "[ { \"DeviceName\": \"/dev/sda1\", \"Ebs\": { \"VolumeSize\": 120 } } ]"

实例启动,我可以看到控制台中列出了新的 120GB 卷(虽然不是根),但实例立即停止(不是终止)。我已经尝试重命名 DeviceName 属性 每个 these conventions, This is a temporary instance that I'm going to launch, do stuff, then terminate. Maybe I need to run create-volume first and then attach it with a separate series of commands? The AWS documentation seems to be all over the place on this and I can't find a clear explanation, though I've come across a few links here and here. 建议调整分区大小,但我不确定这是否是我需要做的。据我所知,m3.2xlarge 实例类型具有可用的 EBS。我是否错误地命名了分区?此配置中的某些内容导致实例停止吗?

编辑

实例自行停止后,我得到以下响应作为对 describe-instances 的一部分:

"BlockDeviceMappings": [
                    {
                        "DeviceName": "/dev/xvda", 
                        "Ebs": {
                            "Status": "attached", 
                            "DeleteOnTermination": true, 
                            "VolumeId": "vol-xxxx", 
                            "AttachTime": "2017-03-05T00:57:23.000Z"
                        }
                    }, 
                    {
                        "DeviceName": "/dev/sda1", 
                        "Ebs": {
                            "Status": "attached", 
                            "DeleteOnTermination": true, 
                            "VolumeId": "vol-xxxx", 
                            "AttachTime": "2017-03-05T00:57:23.000Z"
                        }
                    }
                ], 
                "Architecture": "x86_64", 
                "StateReason": {
                    "Message": "Client.InstanceInitiatedShutdown: Instance initiated shutdown", 
                    "Code": "Client.InstanceInitiatedShutdown"
                }, 
                "RootDeviceName": "/dev/xvda", 
                "VirtualizationType": "hvm", 
                "AmiLaunchIndex": 0

我认为您 运行 遇到了与此 SO 问题相同的问题:

https://serverfault.com/questions/615188/aws-t1-to-t2-migration-client-instanceinitiatedshutdown-on-new-t2-instance

您的实例是一个 HVM 实例,想要使用 /dev/xvda 作为根设备。但是,您指定的是 /dev/sda1。这是 (a) 创建辅助卷,然后 (b) 阻止实例启动,因为这是一个 PV 相关设备而不是 HVM。

因此,解决方案是使用 /dev/xvda 作为设备名称。像下面的命令行:

aws ec2 run-instances \
  --image-id ami-0b33d91d \
  --count 1 \
  --instance-type m3.2xlarge \
  --key-name my_key \
  --security-group-ids "sg-xxxxxxx" \
  --ebs-optimized \
  --block-device-mapping "[ { \"DeviceName\": \"/dev/xvda\", \"Ebs\": { \"VolumeSize\": 120 } } ]"