How to increase the root volume size using the aws cli

How to increase the root volume size using the aws cli

I love using the AWS CLI. It makes everything completely recreatable. I can add the commands to a run book, and presto, next time we need to spin something up we have the commands. No fumbling through the GUI, wondering which security groups or subnets to use. When the gremlins attack you will be in a lot better place with the cli commands documented.

Recently when spinning up a server I immediately got a warning about disk space on the root partition. That is odd, it did not come up in dev, but then again we don’t have Datadog running for our dev instances. I checked it out and it turns out that we install a lot of packages in this recipe. Just enough to put us over the 80% mark. My standard root partition is 8G. So now what? I couldn’t just leave it so I needed to figure out how to increase the root volume. I terminated the instance, and went back into our dev environment.

I am used to doing block mappings, and add them all the time:

aws ec2 run-instances \
--subnet-id subnet-99999999 \
--security-group-ids sg-99999999 \
--image-id ami-99999999 \
--key-name mykey \
--iam-instance-profile Name=my-default-ec2-role \
--instance-type t2.micro \
--block-device-mappings '[{"DeviceName":"/dev/sdb","Ebs":{"VolumeSize":5}}]' \
--output json

With the key there being the block device mappings. All root volumes are ebs volumes now, so it should be easy enough to change that, right?

Not sure if this would work I tested this in our dev account. It turns out it really is that simple, Just add another block mapping  for xvda and boom. It works like a champ

--block-device-mappings '[{"DeviceName":"/dev/sdb","Ebs":{"VolumeSize":5}}, {"DeviceName": "/dev/xvda", "Ebs": { "VolumeSize": 12 }}]'

When the instance booted it took the new setting and made the root partition 12G instead of the 8G that is default.

Comments are closed.