11. Introduction to AWS Block Storage Types
Table of contents
- Mounting and Attaching EBS Volume to an EC2 Instance
- Step 1: Create an EC2 Instance
- Step 2: Create an EBS Volume
- Step 3: Attach the Volume
- Step 4: Login and Verify the Block Device
- Step 5: Format the Disk and Create a Partition
- Step 6: Validate the Partition
- Step 7: Create a Filesystem
- Step 8: Prerequisite to Mount the Disk
- Step 9: Mount the Partition
- Step 10: Persist Mount on Reboot
- Step 11: Test Persistence
Understanding Storage Types In AWS, storage options vary based on the type of data you're working with and your performance and durability requirements. Let's delve into the different types of storage available, focusing on EBS, which provides block-level storage volumes for use with EC2 instances.
Storage Types
Block Storage Elastic Block Storage (EBS) Volumes: Provides persistent block storage volumes that can be attached to EC2 instances. Allows you to create, attach, and detach volumes to EC2 instances as needed. Supports different volume types optimized for various workloads, including General Purpose SSD (gp2/gp3), Provisioned IOPS SSD (io1/io2), and Throughput Optimized HDD (st1). Instance Storage: Directly attached storage to EC2 instances. Provides high I/O performance but is non-persistent. Data stored in instance storage is lost if the instance is stopped or terminated. Typically available in fixed sizes and types and limited to specific instance types.
File Storage AWS Elastic File System (EFS): Fully managed file storage service that supports NFSv4 protocol. Offers scalable and highly available file storage for Linux-based workloads, allowing multiple EC2 instances to access the same file system concurrently. AWS FSx: Provides fully managed file systems optimized for Windows-based workloads, including Windows File Server and Lustre.
Object Storage Amazon Simple Storage Service (S3): Object storage service designed to store and retrieve any amount of data from anywhere on the web. Ideal for storing unstructured data, such as images, videos, documents, and backups. Offers high durability, availability, and scalability at a low cost.
Amazon Glacier: Low-cost storage service designed for long-term data archiving and backup. Offers multiple retrieval options with varying latency, allowing you to optimize costs based on your access requirements.
Advantages and Use Cases of EBS Volumes Permanent Storage: EBS volumes provide persistence, ensuring that data remains intact even if the associated EC2 instance is stopped or terminated.
Flexible Volume Types: Choose from a variety of EBS volume types optimized for different performance and cost requirements, ranging from high-performance SSDs to cost-effective HDDs. Scalability and Attachment Flexibility: Easily scale EBS volumes up to 16TB in size and attach/detach them to different EC2 instances as needed. Practical Implementation and Best Practices Volume
Provisioning and Mounting: Provision EBS volumes and mount them to EC2 instances using standard Linux commands like lsblk, fdisk, mkfs, and mount. Update the /etc/fstab file to automatically mount EBS volumes at boot time. Performance Optimization: Utilize different EBS volume types based on your application's performance requirements, ensuring optimal I/O performance and cost-effectiveness. By understanding the various storage options available in AWS, including EBS volumes, you can architect scalable and reliable storage solutions tailored to your specific workload requirements and budget constraints.
Mounting and Attaching EBS Volume to an EC2 Instance
Step 1: Create an EC2 Instance
Launch an EC2 instance with the following specs:
Instance Type: t2.micro
Root Volume: 8 GB
Step 2: Create an EBS Volume
Navigate to the EBS Dashboard and create a volume:
Type: GP2
Size: 4 GB
Ensure the volume is in the same Availability Zone (AZ) as your EC2 instance.
Step 3: Attach the Volume
Attach the newly created EBS volume to your EC2 instance.
Step 4: Login and Verify the Block Device
SSH into your EC2 instance.
List the block devices using:
lsblk
Confirm the new volume is listed and matches the size you created.
Step 5: Format the Disk and Create a Partition
Start the disk partitioning tool:
sudo fdisk <diskName>
Follow these steps in
fdisk
:Type
n
to create a new partition.Type
p
to make it a primary partition.Press Enter three times to accept defaults.
Type
w
to write changes and exit.
Step 6: Validate the Partition
Run the lsblk
command again to ensure the partition is listed under the disk.
Step 7: Create a Filesystem
Format the partition with the ext4
filesystem:
sudo mkfs -t ext4 <diskPartition>
Step 8: Prerequisite to Mount the Disk
Create a directory to mount the volume:
sudo mkdir /<folderName>
Add some test data to validate persistence later.
Step 9: Mount the Partition
Mount the partition to the folder:
sudo mount <diskPartition> /<folderName>
Step 10: Persist Mount on Reboot
Edit the
fstab
file:sudo vi /etc/fstab
Add the line. Note: Give the relative (full) path of the folder
<diskPartition> /<folderName> ext4 defaults 0 0
Save and verify using:
cat /etc/fstab
Step 11: Test Persistence
Stop and start the EC2 instance.
Verify the mount and test data:
ls /<folderName>