AWS Classroom Series – 30/Aug/2020

Elastic Volumes

  • Lets create one windows ec2 instance with t2.micro and one linux machine with t2.micro

Expanding EBS root volume on EC2 windows instance

  • Login into Windows ec2 and select disks from server manager
  • Now lets change the volume size from 30 GB to 32 GB and see how to reflect that in windows instance without restarting the windows ec2 instance
  • Run diskmgmt.msc command to open disk management & do the refresh.

  • Login into linux instance & execute the following command
sudo df -Th

  • Now lets change the volume size from 8 GB to 10 GB for the linux instance
  • Execute the following commands on linux
  • List the block devices
sudo lsblk

  • Now we need to extend the partition, to do that we need to execute the following command
sudo growpart /dev/xvda 1

  • Now we need to extend the filesystem
    • If the filesystem is ext2,ext3 or ext4
    sudo resize2fs /dev/xvda1
    
    • If the filesystem is xfs
    sudo xfs_growfs /dev/xvda1
    
  • Now lets verify the effective file system sizes
sudo df -h

AWS CLI for EBS Volumes

  • Lets use aws cli to create a volume in us-west-2c az with 1 GB size and General Purpose volume. Refer Here for the list of ec2 actions

  • Now lets try to search for volume based commands to find the create volume

  • Now open this command and navigate to synopsis Refer Here

aws ec2 create-volume
--availability-zone <value>
[--encrypted | --no-encrypted]
[--iops <value>]
[--kms-key-id <value>]
[--outpost-arn <value>]
[--size <value>]
[--snapshot-id <value>]
[--volume-type <value>]
[--dry-run | --no-dry-run]
[--tag-specifications <value>]
[--multi-attach-enabled | --no-multi-attach-enabled]
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]
  • The command would be
aws ec2 create-volume --availability-zone us-west-2c --size 1 --volume-type gp2

  • Now lets try to describe the volume which we created. The volume id in the above case is "vol-014f9f2b3e8487eb2". Now lets describe this volume Refer Here
  • The command would be
aws ec2 describe-volumes --volume-ids "vol-014f9f2b3e8487eb2"

  • We can also some filters
aws ec2 describe-volumes --filters "Name=availability-zone,Values=us-west-2c"

  • Lets delete the volume
  • Now create a linux based ec2 instance with t2.micro (CLI/console)
  • Now create a volume of 1 GB with general purpose in the az where your ec2 instance is created and make a note of volume id: "vol-07aa3361c8055b815"
  • Make a note of ec2-instance id and try to attach volume to ec2-instance (i-0c21d1c4e7c38c948)
aws ec2 attach-volume --volume-id "vol-07aa3361c8055b815" --instance-id i-0c21d1c4e7c38c948 --device "/dev/xvdb"

  • now lets login into ec2 instance and mount the volume to some drive
  • Lets modify the volume from 1 GB to 2 GB
aws ec2 modify-volume --volume-id "vol-07aa3361c8055b815" --size 2

  • Now login into ec2 instance and expand the volume
  • Exercise: Create CLI for the below activities
    1. Create an AWS CLI Command to create the snapshot of the volume created.
    2. From snapshot try to create a volume in a different AZ
    3. Copy the snapshot to different region

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%