Problem:
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.
Prerequisites:
Created and launched an EC2 instance.
Solution Steps:
-
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.
-
Go to the EC2 dashboard and click on Volumes (left sidebar).
-
Check the description and try to understand various values like:
-
Volume ID - vol-014ac86c8b1ed4546
-
Size - 8 GiB
-
Snapshot - snap-0129739714cf9f3c0
-
Availability Zone - us-west-2c
-
State - in-use
-
Encrypted - Not Encrypted
-
Attachment information - i-03dfc64d9bddaee28:/dev/xvda (attached)
-
Volume type - gp2
-
IOPS - 100 / 3000
-
-
Click on Actions and Modify Volume, and explore.
-
Volume type can be one of: General purpose SSD (gp2), Provisioned IOPS SSD (IO1), Cold HDD (SC1), and Throughput Optimized HDD (ST1).
-
You can also modify the size and is dependent on the volume type
-
Gp2 - Min: 1 GiB, Max: 16384 GiB
-
IO1 - Min: 4 GiB, Max: 16384 GiB
-
SC1 - Min: 500 GiB, Max: 16384 GiB
-
ST1 - Min: 500 GiB, Max: 16384 GiB
-
-
Click on cancel and go to Volumes page.
-
-
Click on Create Volume
-
As this is a non-root volume, you can find an additional type of Magnetic, with size of Min: 1 GiB, Max: 1024 GiB.
-
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.
-
-
-
After you have created a volume in the same AZ as your instance, select it and attach it going to Actions > Attach Volume.
-
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.
-
Verify and click on Attach
-
In bit of time, you should see the status as “In-Use”
-
-
Login to the server through SSH and elevate to root privilege with sudo su
-
Type and enter the command: lsblk
-
You can find a new entry without a mount point: xvdf 202:80 0 500G 0 disk (NAME, MAJ:MIN, RM, SIZE, RO, TYPE.)
-
-
Got to root and create a folder:
-
cd /
-
mkdir demofileserver
-
-
Check if the new volume has any data in it: file –s /dev/xvdf
-
It will show you /dev/xvdf: data, which means there is no data.
-
-
Format it once: mkfs –t ext4 /dev/xvdf
-
Mount it to the folder we had created: mount /dev/xvdf /demofileserver
-
Verify it using: lsblk
-
-
Go the mount folder and create a file:
-
cd /demofileserver
-
vi temp.txt
-
Press INSERT (or i) and type something.
-
Save as ESC :x
-
Verify that new file was created using: ls
-
-
Go outside of the demofileserver folder and unmount the volume:
-
cd ..
-
umount /dev/xvdf
-
Verify using lsblk and going inside the folder and typing ls
-
-
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.
-
Create a Snapshot of this volume (Under Actions menu)
-
Give some name and description. I have given: DemoSnapshot
-
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.
-
-
Go back to the Volumes page and delete the volume we had created and taken snapshot (Under Actions menu).
-
Go to Snapshots page and create a Volume from the snapshot.
-
Actions > Create Volume
-
Make sure you enter the same AZ as your EC2 instance
-
Go back to Volumes page and wait until it is available.
-
-
Attach this volume to the EC2 instance.
-
From ssh console,
-
First verify data is there and hence not format: file –s /dev/xvdf
-
mount this into our demo folder demofileserver.
-
-
Go inside our demo folder demofileserver and verify that the file is still present.
-
You may keep the setup as is for the next lab, or do a cleanup of everything.
Lab Notes:
-
Hyphens (e.g. –t) copied and pasted from notes may not work; please type them instead.
Recent comments