Elastic Block Storage

What is Amazon EBS?
Amazon Elastic Block Store (EBS) is a type of storage offered by Amazon Web Services (AWS) for storing data on their cloud servers. Think of it like a hard drive in the cloud that you can attach to your virtual servers (called EC2 instances).
Key Features of EBS
Persistent Storage:
- EBS volumes are like virtual hard drives that keep your data safe even if you stop or restart your server.
Scalability:
- You can easily resize your EBS volumes as your storage needs grow or shrink, ensuring you only pay for what you need.
High Availability:
- EBS volumes are replicated within the same Availability Zone to protect your data from hardware failures.
Performance:
- EBS offers different types of volumes optimized for various use cases, from general-purpose SSDs to high-performance SSDs for demanding applications.
Snapshots:
- You can take point-in-time snapshots (backups) of your EBS volumes, which are stored in Amazon S3. These snapshots help with data recovery and can be used to create new EBS volumes.
Types of EBS Volumes
General Purpose SSD (gp2):
- Balanced price and performance for a variety of workloads like small to medium-sized databases and development environments.
Provisioned IOPS SSD (io1):
- High-performance storage for applications that require a lot of input/output operations per second (IOPS), like large databases.
Cold HDD (sc1):
- Low-cost storage for data that is not accessed frequently, such as backups and archives.
Throughput Optimized HDD (st1):
- Cost-effective storage for frequently accessed data that requires high throughput, such as big data and data warehouses.
Magnetic (standard):
- Lowest cost per gigabyte, suitable for workloads with low I/O performance needs, like archival storage.
EBS vs. Instance Storage
Instance Storage (Ephemeral Storage):
Temporary storage directly attached to an EC2 instance.
Data is lost if the instance is stopped, terminated, or if the hardware fails.
Suitable for temporary data, caches, and high-performance computing tasks.
Automatically deleted when the instance is terminated.
EBS:
Persistent storage that can be detached from one instance and attached to another.
Data is retained even if the instance is stopped or terminated.
Ideal for long-term storage, databases, file systems, and critical applications.
Highly durable and can be replicated within an Availability Zone.
Creating an EBS Volume
Go to EC2 Console:
- Visit the Amazon EC2 website and log in to your AWS account.
Navigate to Volumes:
- In the menu, click on "Volumes" under the "Elastic Block Store" section.
Create a Volume:
Click on the "Create volume" button.

Choose Type:
- Decide the type of volume you need based on your requirements (e.g., General Purpose SSD, Provisioned IOPS SSD, etc.).
Specify Size:
- Enter the size of the volume in gigabytes (GiB).
(Optional) IOPS and Throughput:
- If needed, specify the maximum input/output operations per second (IOPS) or throughput in MiB/s.
Select Availability Zone:
- Choose the specific zone where the volume will be located. Ensure it matches the zone of your instance.
Encryption:
- Decide whether to enable encryption and select the encryption method and key if you choose to encrypt.
Tags (Optional):
- Add custom tags to the volume for better organization and identification.
Create the Volume:
Click on the "Create volume" button.

Attaching an EBS Volume to an EC2 Instance
Navigate to Volumes:
- In the EC2 Console, click on "Volumes" in the menu.
Select the Volume:
Choose the volume you want to attach, click "Actions," and select "Attach volume."

Choose an Instance:
- Enter the ID of the instance or select it from the list. Ensure the volume and the instance are in the same Availability Zone.
Device Name:
- Enter a name for the volume. This name is used by Amazon EC2, but it might get a different name when mounted on the instance.
Attach the Volume:
Click on the "Attach volume" button.

Preparing an EBS Volume for Use
For Linux:
Connect to Your Instance:
- Use SSH to connect to your Linux instance.
Check Device Name and File System:
Use
lsblklist information about all available block devices
Use
nvme1n1to list block devices andsudo file -s /dev/nvme1n1to check the existing file system.
Create File System (If Needed) : If we want to store any data on this volume, we need to format it with a file system.
If there's no file system, create one using
sudo mkfs.ext4 /dev/nvme1n1
Create Mount Point:
- Create a directory to mount the volume using
sudo mkdir /test.
- Create a directory to mount the volume using
Mount the Volume:
Mount the volume with
sudo mount /dev/nvme1n1 /test.The
mountpoint /testcommand checks if the directory/testis a mount point
For Windows:
Login to Your Windows Instance:
- Access your Windows instance via Remote Desktop.
Determine Disk Number:
- Open Windows PowerShell and use
Get-Diskto list available disks. Note the disk number.
- Open Windows PowerShell and use
Create a DiskPart Script:
- Create a text file (e.g.,
diskpart.txt) with commands to make the disk accessible.
- Create a text file (e.g.,
Run DiskPart Script:
- Open a command prompt and run the script with
diskpart /s diskpart.txt.
- Open a command prompt and run the script with
Detaching and Deleting an EBS Volume
Unmount the Volume:
From your Linux instance, unmount the volume with
sudo umount -d /dev/nvme1n1.
Detach the Volume:
In the EC2 Console, go to "Volumes," select the volume, choose "Actions," and click "Detach Volume."

Delete the Volume:
If you no longer need the volume, delete it in the EC2 Console by selecting the volume, choosing "Actions," and clicking "Delete volume."

Confirm Deletion:
- Confirm the action by clicking "Delete."
Key Points to Remember
Data Preservation: Detaching a volume does not delete the data stored on it.
Explicit Detachment: Always unmount the volume before detaching it.
Root Devices: Stop the instance before detaching a root device.
Storage Charges: You continue to incur charges for detached volumes unless they are deleted.
By following these steps, you can efficiently manage your Amazon EBS volumes, ensuring data persistence, backup, and disaster recovery for your AWS environment.
Modifying EBS Volume on AWS
Open EC2 Console:
Go to the Amazon EC2 website: https://console.aws.amazon.com/ec2/
Log in to your AWS account.
Navigate to Volumes:
- In the left navigation pane, click on "Volumes."
Select and Modify Volume:
Choose the volume you want to modify.
Click "Actions" and select "Modify volume."

Adjust Settings:
On the "Modify volume" screen, you'll see the current configuration.
You can change the volume type, size, IOPS (for gp3, io1, and io2 types), and throughput (for gp3 type).
Confirm Changes:
After making your adjustments, click "Modify."

Confirm the modifications when prompted.
Note: You cannot decrease the size of an EBS volume due to technical constraints. You can only increase its size.
Extending a Linux File System After Resizing an EBS Volume
Connect to Your Instance:
- Use SSH to connect to your Linux instance.
Check for Partition:
- Use the command
sudo lsblkto check if the volume has increased.
- Use the command

Extend Partition (if needed):
If the size has increased, use
sudo resize2fs /dev/nvme2n1to extend it and utilize this volume.
Verify the extension with
sudo lsblk.
Extend the File System:
- Use
df -hto get information about the file system.
- Use
Example output:
Filesystem Type Size Used Avail Use% Mounted on
/dev/xvdf ext4 24.0G 1.9G 22.1G 10% /data
Run Extension Command:
Depending on the file system type:
For XFS:
sudo xfs_growfs -d /For Ext4:
sudo resize2fs /dev/xvda1
Verify Extension:
- Use
df -hTagain to confirm the file system extension.
- Use
These steps ensure your Linux file system is extended after resizing an EBS volume on AWS. By following these instructions, you can easily modify your EBS volumes and extend your file system to accommodate the new size.
Modifying an EBS Root Volume on AWS
Open the EC2 Console:
Go to the Amazon EC2 website: https://console.aws.amazon.com/ec2/
Log in to your AWS account.
Navigate to Volumes:
- In the left navigation pane, click on "Volumes."
Select and Modify the Volume:
Choose the root volume you want to modify.
Click "Actions" and then select "Modify volume."
Adjust the Settings:
On the "Modify volume" screen, you'll see the current settings (type, size, IOPS, throughput).
Change the volume type if needed.
Increase the size of the volume (you can't decrease it).
For gp3, io1, and io2 types, adjust the IOPS (input/output operations per second) as needed.
For gp3 type, you can also adjust the throughput.

Confirm the Changes:
After making your adjustments, click "Modify."
Confirm the modifications when prompted.
Note: You can only increase the size of an EBS volume; decreasing the size is not allowed due to technical constraints. This ensures data integrity and consistent performance.
Extending a Linux File System After Resizing an EBS Root Volume
Connect to Your Instance:
- Use SSH to connect to your Linux instance.
Check for Partitions:
- Run the command
sudo lsblkto list block devices and check if your root volume has a partition.
- Run the command

Extend the Partition (if needed):
If there is a partition, use
sudo growpart /dev/nvme0n1 1to extend it.
Verify the extension with
sudo lsblk.
Extend the File System:
- Use the command
df -hTto get information about the file system.
- Use the command

Run the Extension Command:
Depending on the file system type and we can check file type by
lsblk -fcommand:For XFS:
sudo xfs_growfs -d /For Ext4:
sudo resize2fs /dev/nvme0n1p1as my file system type is ext4

Verify the Extension:
- Use
df -hTagain to confirm the file system extension.
- Use
These steps ensure that your Linux file system is extended after resizing an EBS root volume on AWS, allowing you to make use of the additional space.
Attaching One EBS Volume to Multiple EC2 Instances
Amazon EBS Multi-Attach allows you to connect a single Provisioned IOPS SSD (io1 or io2) volume to multiple EC2 instances in the same Availability Zone. This feature is particularly useful for applications that need to handle concurrent write operations, increasing application availability.
Considerations and Limitations
Number of Instances:
- You can attach a Multi-Attach enabled volume to up to 16 Linux instances on the Nitro System within the same Availability Zone.
Volume Types:
- Multi-Attach only works with Provisioned IOPS SSD (io1 and io2) volumes.
Regions:
- Multi-Attach for io1 volumes is available in specific regions, while io2 volumes support it across all regions.
File System Recommendation:
- Standard file systems like XFS and EXT4 are not designed for simultaneous access by multiple servers. For data resiliency, use a clustered file system.
I/O Fencing:
- io2 volumes support I/O fencing to ensure data consistency, but io1 volumes do not.
Performance Considerations
Each attached instance can achieve its maximum IOPS performance.
The total performance of all attached instances cannot exceed the volume's maximum provisioned performance.
Working with multi-attach
Enable Multi-Attach During Volume Creation:
Use the AWS Console or Command Line Interface (CLI) when creating a volume.
Choose "Provisioned IOPS SSD (io1/io2)" as the volume type and enable Multi-Attach in the options.

Enable Multi-Attach for io2 After Creation:
You can enable Multi-Attach for io2 volumes that are not attached to any instances using the AWS Console or CLI.

Disable Multi-Attach:
- You can disable Multi-Attach through the AWS Console or CLI.
Attach Volume to Instances:
Attach Multi-Attach enabled volumes to instances using the standard procedures.
Ensure all instances are in the same Availability Zone.


here we can, volume is attached with both servers

Delete on Termination:
- Configure Multi-Attach volumes to be deleted when the instances they are attached to are terminated.
Summary
Amazon EBS Multi-Attach simplifies the process of attaching a single EBS volume to multiple EC2 instances, making it easier to manage applications that require concurrent write operations. By following the considerations and steps outlined above, you can effectively use Multi-Attach to enhance application availability and performance.
Amazon EBS Volume Types
Understanding Amazon Elastic Block Store (EBS) volume types is essential for optimizing performance and costs in your AWS environment. Here’s a simple breakdown of the three main EBS volume types:
1. General Purpose SSD Volumes (gp3)
Overview: General Purpose SSD volumes, known as gp3, offer a balanced mix of performance and cost-effectiveness suitable for various workloads.
Use Cases:
Virtual Servers Boot Volumes: Perfect for quickly launching virtual servers with balanced I/O performance.
Small to Medium-sized Databases: Cost-effective storage for databases with moderate I/O needs.
Development and Test Environments: Affordable and balanced performance for non-production environments.
2. Provisioned IOPS SSD Volumes (io1 and io2)
Overview: Provisioned IOPS SSD volumes (io1 and io2) are designed for applications requiring consistent and predictable I/O performance.
Use Cases:
High-performance Databases: Ensures low-latency and high-throughput for transactional databases.
Business-critical Applications: Provides predictable performance for I/O-sensitive applications with customizable IOPS settings.
Big Data and Analytics Applications: High-performance storage for data-intensive analytics workloads.
3. Throughput Optimized HDD and Cold HDD Volumes
Overview: Throughput Optimized HDD (st1) and Cold HDD (sc1) volumes are built for large, sequential I/O workloads, with st1 for frequent access and sc1 for infrequent access.
Use Cases:
Throughput Optimized HDD (st1) - Big Data Processing: Ideal for Hadoop and Spark environments with high throughput needs.
Throughput Optimized HDD (st1) - Data Warehousing: Well-suited for large sequential data access patterns in data warehousing.
Cold HDD (sc1) - Data Archiving and Backup: Cost-effective storage for infrequently accessed data, perfect for long-term storage compliance.
Conclusion
Choosing the right Amazon EBS volume type is crucial for optimizing your AWS storage. Whether you need balanced performance, high I/O predictability, or throughput for specific workloads, understanding these EBS types helps you make informed decisions. Consider the use cases outlined above to find the perfect balance between performance and cost-efficiency.
Comparison Table
Here's a comparison of the key features:
| Feature | General Purpose SSD (gp3) | Provisioned IOPS SSD (io1, io2) |
| Volume Type | gp3 | io1, io2, Block Express 3 |
| Durability | 99.8% - 99.9% (0.1% - 0.2% annual failure rate) | 99.999% (0.001% annual failure rate) |
| Use Cases | Transactional workloads, Virtual desktops, Medium-sized databases, Boot volumes, Development and test environments | Workloads with Sub-millisecond latency, Sustained IOPS performance, More than 64,000 IOPS or 1,000 MiB/s of throughput, I/O-intensive databases |
| Volume Size | 1 GiB - 16 TiB | 4 GiB - 64 TiB (io1, io2), 4 GiB - 16 TiB (Block Express 3) |
| Max IOPS per Volume | 16,000 (64 KiB I/O) | 16,000 (16 KiB I/O) (io1, io2), 256,000 (16 KiB I/O) (Block Express 3) |
| Max Throughput per Volume | 1,000 MiB/s | 250 MiB/s (io1, io2), 4,000 MiB/s (Block Express 3) |
| EBS Multi-Attach | Not supported | Supported |
| NVMe Reservations | Not supported | Supported (io1, io2) |
| Boot Volume | Supported | Supported |



