[Recipes] Experiment with Amazon EBS Volumes and Snapshots in EC2


You have created an EC2 instance. Need to experiment with Amazon EBS Volumes and Snapshots in EC2 for better understanding.

Solution Summary: 

We will explore EBS volume parameters, modify them, create volume, create snapshots etc.


Created and launched an EC2 instance.

Solution Steps: 

  1. Create an EC2 instance following previous labs. Note: You may continue to use the same instance you have used before (in case if you have not deleted it yet) or create a new instance.

  2. Go to the EC2 dashboard and click on Volumes (left sidebar).

  3. Check the description and try to understand various values like:

    1. Volume ID - vol-014ac86c8b1ed4546

    2. Size - 8 GiB

    3. Snapshot - snap-0129739714cf9f3c0

    4. Availability Zone - us-west-2c

    5. State - in-use

    6. Encrypted - Not Encrypted

    7. Attachment information - i-03dfc64d9bddaee28:/dev/xvda (attached)

    8. Volume type - gp2

    9. IOPS - 100 / 3000

  4. Click on Actions and Modify Volume, and explore.

    1. Volume type can be one of: General purpose SSD (gp2), Provisioned IOPS SSD (IO1), Cold HDD (SC1), and Throughput Optimized HDD (ST1).

    2. You can also modify the size and is dependent on the volume type

      1. Gp2 - Min: 1 GiB, Max: 16384 GiB

      2. IO1 - Min: 4 GiB, Max: 16384 GiB

      3. SC1 - Min: 500 GiB, Max: 16384 GiB

      4. ST1 - Min: 500 GiB, Max: 16384 GiB

    3. Click on cancel and go to Volumes page.

  5. Click on Create Volume

    1. As this is a non-root volume, you can find an additional type of Magnetic, with size of Min: 1 GiB, Max: 1024 GiB.

      1. You can select availability zones and should be same as the AZ of the EC2 instance you want to attach it to. Note: Try creating one in a different AZ and try to attach. Attach option will only show EC2 instances in same AZ.

  6. After you have created a volume in the same AZ as your instance, select it and attach it going to Actions > Attach Volume.

    1. Device name is auto populated (e.g. /dev/sdf). Available device names depends on instance types (e.g. linux, windows etc.). It also shows a Note: Newer Linux kernels may rename your devices to /dev/xvdf through /dev/xvdp internally, even when the device name entered here (and shown in the details) is /dev/sdf through /dev/sdp.

    2. Verify and click on Attach

    3. In bit of time, you should see the status as “In-Use”

  7.  Login to the server through SSH and elevate to root privilege with sudo su

  8. Type and enter the command: lsblk

    1. You can find a new entry without a mount point: xvdf    202:80   0  500G  0 disk (NAME, MAJ:MIN, RM, SIZE, RO, TYPE.)

  9. Got to root and create a folder:

    1. cd /

    2. mkdir demofileserver

  10. Check if the new volume has any data in it: file –s /dev/xvdf

    1. It will show you /dev/xvdf: data, which means there is no data.

  11. Format it once: mkfs –t ext4 /dev/xvdf

  12. Mount it to the folder we had created: mount /dev/xvdf /demofileserver

    1. Verify it using: lsblk

  13. Go the mount folder and create a file:

    1. cd /demofileserver

    2. vi temp.txt

    3. Press INSERT (or i) and type something.

    4. Save as ESC :x

    5. Verify that new file was created using: ls

  14. Go outside of the demofileserver folder and unmount the volume:

    1. cd ..

    2. umount /dev/xvdf

    3. Verify using lsblk and going inside the folder and typing ls

  15. Go back to the AWS console EC2 volumes page, select the volume and detach it (Under Actions menu). Note: If you have not unmounted it, you will have to do a force detach.

  16. Create a Snapshot of this volume (Under Actions menu)

    1. Give some name and description. I have given: DemoSnapshot

    2. Once done, go to the Snapshots page and wait until snapshot creation is complete. May also try refreshing the page. Note: First time creation may take more time; subsequently it is incremental.

  17. Go back to the Volumes page and delete the volume we had created and taken snapshot (Under Actions menu).

  18. Go to Snapshots page and create a Volume from the snapshot.

    1. Actions > Create Volume

    2. Make sure you enter the same AZ as your EC2 instance

    3. Go back to Volumes page and wait until it is available.

  19. Attach this volume to the EC2 instance.

  20. From ssh console,

    1. First verify data is there and hence not format: file –s /dev/xvdf

    2. mount this into our demo folder demofileserver.

  21. Go inside our demo folder demofileserver and verify that the file is still present.

  22. You may keep the setup as is for the next lab, or do a cleanup of everything.


Lab Notes:

  1. Hyphens (e.g. –t) copied and pasted from notes may not work; please type them instead.

Learn Serverless from Serverless Programming Cookbook


Please first use the contact form or facebook page messaging to connect.

Offline Contact
We currently connect locally for discussions and sessions at Bangalore, India. Please follow us on our facebook page for details.
WhatsApp (Primary): (+91) 7411174113
Phone (Escalations): (+91) 7411174114

Business newsletter

Complete the form below, and we'll send you an e-mail every now and again with all the latest news.


Cloudericks.com is my blog to share notes and learning materials on Cloud and Data Analytics. My current focus is on Amazon Web Services.

I like to write. I try to document what I learn and share with others. I believe that knowledge is useless unless you share it; the more you share, the more you learn.

Recent comments

Photo Stream