• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

ebs

EBS DeleteOnTermination

March 22, 2020

Here’s how to set the DeleteOnTermination setting on EBS volumes. The DeleteOnTermination flag determines if an EBS volume will be kept or deleted when an EC2 instance is terminated. The DeleteOnTermination setting can be set during EC2 instance creation, or it can be applied to an existing or a running EC2 instance. The settings can be placed in a JSON file and loaded using –block-device-mappings option upon creation.

During creation.

aws ec2 run-instances \
--count 1 \
--region us-east-2 \
--key-name tfc-ohio \
--image-id ami-xxxxxxxx \
--instance-type t2.large \
--subnet-id subnet-xxxxxxx \
--private-ip-address 10.0.4.100 \
--iam-instance-profile Name=machinerole \
--security-group-ids sg-xxxxxxxxxxxxx \
--block-device-mappings file://mapping.json

aws ec2 run-instances \ --count 1 \ --region us-east-2 \ --key-name tfc-ohio \ --image-id ami-xxxxxxxx \ --instance-type t2.large \ --subnet-id subnet-xxxxxxx \ --private-ip-address 10.0.4.100 \ --iam-instance-profile Name=machinerole \ --security-group-ids sg-xxxxxxxxxxxxx \ --block-device-mappings file://mapping.json

Contents of mapping.json

[
  {
    "DeviceName": "/dev/sda1",
    "Ebs": {
      "DeleteOnTermination": true,
      "VolumeSize": 30
      "VolumeType": "gp2"
    }
  }
]

[ { "DeviceName": "/dev/sda1", "Ebs": { "DeleteOnTermination": true, "VolumeSize": 30 "VolumeType": "gp2" } } ]

Device name is /dev/sda1. Termination is set to true. Volume size is 30GB and EBS type is gp2.

Modifying an existing EC2 instance.

aws ec2 modify-instance-attribute \
--instance-id i-xxxxxxxxxxxxx \
--block-device-mappings file://mapping.json

aws ec2 modify-instance-attribute \ --instance-id i-xxxxxxxxxxxxx \ --block-device-mappings file://mapping.json

Here’s the mapping.json file.

[
  {
    "DeviceName": "/dev/sda1",
    "Ebs": {
      "DeleteOnTermination": false,
    }
  }
]

[ { "DeviceName": "/dev/sda1", "Ebs": { "DeleteOnTermination": false, } } ]

Obviously, you can’t change Volume size and type to an existing EBS volume, but you can flip the DeleteOnTermination flag and vice versa.

Filed Under: Cloud Tagged With: aws, deleteontermination, ebs, ec2, false, true

AWS Backup

January 16, 2019

AWS just introduced Backup, a new managed service for backing up AWS resources. You can now create backup policies of EC2, RDS, DynamoDB, and EFS systems. The default backup uses S3 buckets, but storage can be moved to Glacier or it can be expired. The backup service is initially available in Virginia, Ohio, Oregon and Ireland.

AWS Backup

Filed Under: Cloud Tagged With: aws, backup, ebs, efs, rds, s3

Attach an EBS Volume to an Instance

October 10, 2018

Attaching an EBS volume to an existing instance is quite easy. You can easily add them via the AWS Console. With just a few clicks, you can add an EBS volume in no time. Just click the Create Volume button, indicate the size of the volume, choose which availability zone (preferably the same AZ where your instance resides), and enable encryption if you decide to do so. You can also add an EBS volume from an existing snapshot.

There are 2 steps to attaching an EBS volume to an existing instance.

Step 1. Attach an EBS volume.

How to attach an EBS to an existing Instance.

Step 2. Make the EBS volume available to your instance whether it’s Linux or Windows. This requires SSH access.

Making an EBS volume available to Linux.
Making an EBS volume available to Windows.

Filed Under: Cloud Tagged With: attach, ebs, instance

Extend an EBS Volume

March 5, 2018

As a Cloud Engineer, I get a few requests to extend an EBS volume. For example, the application owner wants to double the size of the /data volume from 10GB to 20GB. The nice part about extending an EBS volume is that it can all be done on the fly without bringing down the instance. Adding more storage can be done via the AWS Console. Check out this article from AWS about modifying an EBS volume. But that’s just the first part. Although you’ve doubled the disk space, you still have to let the system know it now has doubled it’s disk space. The second part is to grow or resize the file system. Here’s the other article on how to extend a file system.

# expand
growpart /dev/xvdb
# for ext2, ext3 and ext4
resize2fs /dev/xvdb
# for xfs
xfs_growfs -d /dev/xvdb

# expand growpart /dev/xvdb # for ext2, ext3 and ext4 resize2fs /dev/xvdb # for xfs xfs_growfs -d /dev/xvdb

Filed Under: Cloud Tagged With: ebs, extend, volume

  • Home
  • About
  • Archives

Copyright © 2023