Question:
I’m having difficulty launching an EC2 instance and increasing the size of the root partition in a single command with aws ec2 run-instances
:
1 2 3 4 5 6 7 8 9 |
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 } } ]" |
The instance launches, and I can see the new 120GB volume listed (though not as root) in the console, but then the instance immediately stops (not terminates). I’ve tried renaming the DeviceName property per 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. This SO question suggests resizing the partition but I’m not sure if that’s what I need to do. As far as I can tell, the m3.2xlarge
instance type has EBS available. Am I naming the partition incorrectly? Is something in this configuration causing the stoppage of the instance?
EDIT
After the instance stops itself, I get the follow as part of the response to describe-instances
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
"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 |
Answer:
I think you’re running into the same problem that this SO question is having:
Your instance is an HVM instance and wants to use /dev/xvda
as the root device. However, you’re specifying /dev/sda1
. This is (a) creating a secondary volume instead, but then (b) preventing the instance from launching because that’s a PV-related device rather than HVM.
So, as a solution, use /dev/xvda
as the device name instead. Like the following command line:
1 2 3 4 5 6 7 8 9 |
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 } } ]" |