Boost EC2 Storage: Create and Attach EBS Volumes Step-by-Step
When you launch an EC2 instance, AWS automatically creates a root volume.
If your application needs more storage, you can:
Add a volume during launch
Or attach an EBS volume later (this lab covers that)
Step 1: Launch an EC2 Instance
Go to Amazon Web Services Console
Navigate to Amazon EC2
Click Launch Instance
Configure:
AMI (e.g., Ubuntu)
Instance type (e.g., t2.micro)
Key pair
Launch the instance
π A default root EBS volume is created automatically.
To add an additional volume during instance creation, select "Add New Volume" in the configuration step.
Step 2: To create an Additional EBS Volume
Go to EBS β Volumes
Click Create Volume
Configure:
Size (e.g., 10 GB)
Volume type (gp3 recommended)
β οΈ IMPORTANT: Select the same Availability Zone as your EC2 instance
Click Create Volume
Step 3: Attach Volume to EC2
Select the newly created volume
Click Actions β Attach Volume
Choose your EC2 instance
Click Attach
Step 4: Connect to EC2 Instance
Use SSH:
ssh -i your-key.pem ubuntu@your-public-ip
Step 5: Detect Attached Volume
List block devices:
lsblk
Shows:
All block devices detected by OS
Even unmounted volumes
Example volume names:
/dev/nvme0n1β root volume/dev/nvme1n1β additional volume
Check mounted file systems:
df -Th
Shows:
Mounted volumes only
File system type
Human-readable sizes
From the df -Th output, you'll notice that the new volume (e.g., /dev/nvme1n1) is not listed because it hasn't been mounted yet. Once mounted, it will appear.
Step 6: Verify File System Presence
sudo file -s /dev/nvme1n1
Output Meaning:
dataβ No filesystem existsXFS/ext4β Filesystem already exists
file -s /dev/nvme1n1
From this output, "data" indicates that no file system is present. To mount the volume, first create an XFS file system.
7: Create XFS File System
π One-time activity
sudo mkfs -t xfs /dev/nvme1n1
Verify:
sudo file -s /dev/nvme1n1
Verify the output: It displays as an XFS file system.
8: Create Mount Directory
First, create a directory that will act as the mount point for your EBS volume:
mkdir -p /home/ubuntu/production
π Create a Sample File
Create a test file inside the directory:
This file will help verify that data written to this directory is stored on the attached EBS volume.
touch /home/ubuntu/production/abc.logs
The /home/ubuntu/production directory will be used as the mount point for the EBS volume in Amazon EC2.
Once the volume is mounted:
Any data written inside this directory will be stored on the Amazon Elastic Block Store volume
This ensures data persistence, even if the EC2 instance is stopped or terminated (depending on volume settings)
π This is a common real-world use case of EBS for storing logs, application data, or backups.
9: Mount the Volume (Temporary)
sudo mount /dev/nvme1n1 /home/ubuntu/production
Verify:
df -Th
π Volume is now mounted
Step 10: Make Mount Permanent
Temporary mounts are stored in:
sudo cat /etc/mtab
Get last entry:
tail -1 /etc/mtab
Copy the last line
Edit fstab:
sudo vi /etc/fstab
Add the last line you copied above.
Step 11: Test Persistence
Reboot:
Now, even if you reboot the server, the volume should remain mounted. β
12: Increase the EBS volume
You can increase EBS volume size anytime
You cannot decrease volume size
As you can see, I can't decrease the size, but I can increase it.
Expand File System (Linux β XFS)
When you increase the size of an EBS volume in Amazon Elastic Block Store, the operating system does not automatically use the extra space.
π You must manually expand the filesystem to utilize the new capacity.
Step 1: Verify Current Disk Size
Check the current disk and mount details:
lsblk
df -Th
π You may notice:
Disk size increased (from AWS side)
Filesystem size still unchanged
sudo xfs_growfs -d /home/ubuntu/production
xfs_growfsβ Expands an XFS filesystem-dβ Uses all available free space on the disk/home/ubuntu/productionβ Mount point of the volume
π This command resizes the filesystem without unmounting
Verify Expansion
df -Th
π Now you should see:
Increased total size
More available space
Important Notes
β Only works if filesystem type is XFS
β Volume must already be mounted
β Safe operation (no data loss)
β Cannot shrink XFS filesystem
Key Concepts Learned
EBS works at block level storage
Volume must be in same Availability Zone
Mounting connects storage to filesystem
UUID ensures stable mounting
XFS supports online expansion
Real-World Use Case
Mounting /home/ubuntu/production ensures:
Logs and application data are stored on EBS
Data persists even if EC2 instance is stopped or replaced
Ideal for production workloads
Conclusion
You now have a complete understanding of:
Managing storage in AWS
Attaching and mounting EBS volumes
Ensuring persistence
Scaling storage without downtime
π This is a core DevOps skill used in real production environments.
