Unlock Extra Storage: Mounting an EBS Volume on Your EC2 Instance
Day 10 - How to Mount a Volume in AWS EC2 Linux: A Beginner's Guide
If you're new to AWS (Amazon Web Services) and working with EC2 (Elastic Compute Cloud) instances, you might need to attach additional storage to your instance at some point. This storage comes in the form of EBS (Elastic Block Store) volumes. In this guide, we'll walk you through the steps to mount a volume to your EC2 Linux instance in simple terms.
What is an EBS Volume?
Think of an EBS volume as a USB drive for your computer. It's an additional storage device that you can attach to your EC2 instance to store more data. You can detach it and reattach it to another instance if needed.
Steps to Mount a Volume in AWS EC2 Linux
1. Create and Attach an EBS Volume
Log into AWS Console:
Go to AWS Management Console.
Log in with your credentials.
Navigate to EC2 Dashboard:
- Click on "Services" at the top and then select "EC2" under "Compute."
Create a New Volume:
In the left-hand menu, click on "Volumes" under the "Elastic Block Store" section.
Click the "Create Volume" button.
Specify the size, type, and Availability Zone (make sure it's the same zone as your EC2 instance).
Click "Create Volume."
Attach the Volume to Your EC2 Instance:
After the volume is created, right-click on the volume and select "Attach Volume."
Choose your instance from the list and click "Attach."
2. Connect to Your EC2 Instance
Open a Terminal:
- If you're on Windows, you might use PuTTY. On macOS or Linux, you can use the terminal.
Connect to Your EC2 Instance:
Use the following command to connect (replace
your-key.pem
with your key file andec2-user@your-instance-public-dns
with your instance details):ssh -i your-key.pem ec2-user@your-instance-public-dns
3. Mount the EBS Volume
List Attached Disks:
Once logged in, list all attached disks with:
lsblk
You should see a new disk (e.g.,
xvdf
ornvme1n1
) that wasn't there before.
Create a Filesystem on the Volume:
Format the new volume to prepare it for use. Replace
xvdf
with your actual device name:sudo mkfs -t ext4 /dev/xvdf
Create a Mount Point:
Create a directory where you will mount the volume:
sudo mkdir /mnt/mydata
Mount the Volume:
Mount the volume to the directory:
sudo mount /dev/xvdf /mnt/mydata
Verify the Mount:
Check if the volume is mounted correctly:
df -h
You should see your new volume listed with its mount point.
4. (Optional) Make the Mount Permanent
To ensure the volume is mounted automatically after a reboot:
Edit the fstab File:
Open the fstab file with a text editor like
nano
:sudo nano /etc/fstab
Add the following line at the end (replace
xvdf
and/mnt/mydata
with your actual device name and mount point):/dev/xvdf /mnt/mydata ext4 defaults,nofail 0 2
Save and Exit:
- Save the file and exit the editor (in
nano
, pressCtrl+X
, thenY
, andEnter
).
- Save the file and exit the editor (in
Conclusion
That's it! You've successfully mounted an EBS volume to your AWS EC2 Linux instance. Now you can use this additional storage for your applications or data. Remember, if you ever stop or terminate your instance, the data on the EBS volume will remain intact, but you'll need to remount it if you start a new instance.
Happy cloud computing!
Subscribe to my newsletter
Read articles from Ahini Roy directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Ahini Roy
Ahini Roy
Software Engineer and newbie in tech blogging with an experience in DevOps and API Management. In pursuit of a stage to facilitate the maximum utilization and application of my skills & experience in making a positive difference in the domain. Learning enthusiast for upcoming and new technologies.