AWS Elastic Block Store (EBS) Exercise to help you understand how to create, attach, use, and manage EBS volumes in AWS.
You will:
- Create an EBS volume.
- Attach it to an EC2 instance.
- Format and mount the volume.
- Perform basic file operations.
- Detach and delete the EBS volume.
- An AWS account.
- An existing EC2 instance in the same Availability Zone (AZ) as the EBS volume.
- Basic knowledge of Linux commands.
- Login: Sign in to the AWS Management Console.
- Navigate: Go to the EC2 Dashboard.
- Create Volume:
- Click Volumes in the left-hand menu under "Elastic Block Store."
- Click Create Volume and configure:
- Size: 10 GiB
- Volume Type: General Purpose SSD (gp3 or gp2)
- Availability Zone: Same as your EC2 instance.
- Click Create Volume.
- Select the Volume:
- Find the newly created volume in the Volumes list.
- Select it and click Actions > Attach Volume.
- Attach:
- Choose your EC2 instance from the list.
- Note the device name (e.g.,
/dev/xvdf). - Click Attach Volume.
- Connect to the EC2 Instance:
- SSH into your EC2 instance using your key pair:
ssh -i <your-key-pair.pem> ec2-user@<instance-public-ip>
- SSH into your EC2 instance using your key pair:
- Verify the Volume:
- Run the following command to confirm the volume is attached:
You should see the attached volume (e.g.,
lsblk
/dev/xvdf).
- Run the following command to confirm the volume is attached:
- Format the Volume:
- Use the
mkfscommand to format the volume with an ext4 file system:sudo mkfs.ext4 /dev/xvdf
- Use the
- Create a Mount Point:
- Create a directory to mount the volume:
sudo mkdir /mnt/ebs-volume
- Create a directory to mount the volume:
- Mount the Volume:
- Mount the volume to the directory:
sudo mount /dev/xvdf /mnt/ebs-volume
- Mount the volume to the directory:
- Verify the Mount:
- Run
df -hto confirm the volume is mounted.
- Run
- Create a File:
- Navigate to the mount point:
cd /mnt/ebs-volume - Create a file:
echo "Hello, EBS!" | sudo tee test-file.txt
- Navigate to the mount point:
- List Files:
- Verify the file exists:
ls -l
- Verify the file exists:
- Unmount the Volume:
- Unmount the volume from the instance:
sudo umount /mnt/ebs-volume
- Unmount the volume from the instance:
- Detach the Volume:
- Go to the AWS Management Console.
- Select the volume, click Actions > Detach Volume, and confirm.
- Delete the Volume:
- Once detached, select the volume and click Actions > Delete Volume.