AWS Cloud Practitioner CLF-C02
Technology Part One
AWS Storage EBS Demo
In this lesson, you will learn how to work with AWS Elastic Block Store (EBS) by creating an EBS volume, attaching it to an EC2 instance, configuring the file system, and then detaching and reattaching the volume to a different instance. This demonstration highlights that an EBS volume is independent of any specific EC2 instance.
Overview of EC2 Instances and Availability Zones
Two EC2 instances (instance 1 and instance 2) are provisioned in the same Availability Zone. This alignment is crucial because an EBS volume must be created in the same Availability Zone as the instance when attaching it.
Both instances are located in US East-1C, so any EBS volume created for these instances must also be in US East-1C.
Creating an EBS Volume
- Navigate to the EC2 dashboard.
- Scroll down to the Elastic Block Store section and select Volumes.
- Click the Create Volume button to start a new volume configuration.
When creating the volume, ensure you:
- Select General Purpose SSD as the volume type (default).
- Specify a size (for example, 20 GiB).
- Set the Availability Zone to US East-1C to match the EC2 instances.
- Optionally, assign a tag (e.g., Name tag: "EBS demo").
After you create the volume, its initial status will be "creating." After a brief wait, the status will update to "available."
Attaching the Volume to an EC2 Instance
With the volume available, follow these steps to attach it to instance 1:
- Select the newly created volume.
- Click on the Actions dropdown and choose Attach Volume.
- Choose instance 1 from the available instances.
- Note the device name shown on the instance (commonly /dev/sdf, which may appear as /dev/xvdf on newer Linux kernels).
A successful attachment is indicated by a green confirmation bar.
Configuring the EBS Volume on Instance 1
Log in to instance 1 and follow these steps to prepare and mount the volume:
List Block Devices
Run the following command to view all block devices on the instance:
sudo lsblk
You should see the root device (about 8 GiB) and the new 20 GiB volume as "xvdf" (or a similar name).
Verify the EBS Volume
Check if a file system already exists on the volume:
sudo file -s /dev/xvdf
If the output returns "data," no file system is present on the volume.
Create an EXT4 File System
To create a new file system on the volume, run:
sudo mkfs.ext4 /dev/xvdf
After formatting, verify again to ensure that an EXT4 filesystem is now present:
sudo file -s /dev/xvdf
Mount the File System
Create a directory serving as the mount point and mount the volume:
Create a directory (e.g.,
/ebsdemo
):sudo mkdir /ebsdemo
Mount the volume to the new directory:
sudo mount /dev/xvdf /ebsdemo
Validate the mount by listing the block devices:
sudo lsblk
To further confirm, use:
df -h
This command verifies that
/dev/xvdf
is mounted on/ebsdemo
.
Note
Remember to use the correct device name (/dev/xvdf
) which may vary depending on your Linux kernel.
Persisting the Mount Across Reboots
To automatically remount the EBS volume after a system reboot, update the /etc/fstab
file:
Retrieve the UUID
Run the command below to find the UUID of the volume:
sudo blkid
Identify the UUID corresponding to
/dev/xvdf
.Edit the fstab File
Open
/etc/fstab
with your favorite text editor:sudo vi /etc/fstab
Add the New Entry
Insert a new line similar to the following. Replace the UUID with the one you found:
UUID=d00f00f3-51b6-4669-acb0-363989486b91 /ebsdemo ext4 defaults 0 0
Double-check for typographical errors to avoid boot issues.
After saving, the EBS volume will be remounted automatically after each reboot.
Verifying the Setup
To validate your configuration, change to the mount point and create a test file:
Change the directory:
cd /ebsdemo
Create and edit a new file:
sudo vi example_file.txt
Enter some text (e.g., "I created this file on instance 1") and save the file.
List the contents of the directory:
ls -l
The new file should be visible, confirming that the volume is correctly mounted and writable.
Detaching the Volume and Attaching to Another Instance
To illustrate that an EBS volume is not tied to a single EC2 instance, detach it from instance 1 and attach it to instance 2 by following these steps:
- Go to the EC2 console and select instance 1. Stop instance 1 to ensure safe volume detachment.
- Navigate to the Volumes section, select the volume, and click Detach Volume.
- After detachment, attach the volume to instance 2 using the same device name:
- Select the volume.
- Click on Actions and choose Attach Volume.
- Select instance 2 from the dropdown list.
Log in to instance 2 and mount the volume:
Display block devices:
sudo lsblk
Create a mount directory and mount the volume:
sudo mkdir /instance2ebs sudo mount /dev/xvdf /instance2ebs
Verify that the file created on instance 1 is present:
cd /instance2ebs cat example_file.txt
The output should display the content "I created this file on instance 1," confirming that the data persists across instances.
Cleaning Up
After the demonstration is complete, make sure to clean up your AWS resources:
- Shut down and terminate both EC2 instances.
- Remember that EBS volumes persist beyond instance termination, so navigate to the Volumes section.
- Select and click Delete Volume to remove the volume.
This concludes the AWS EBS demo lesson. For further details on managing AWS resources, check out the AWS Documentation and our related guides.
Watch Video
Watch video content