DEV Community

Omkar Sharma
Omkar Sharma

Posted on • Edited on

Mounting and Making EBS Volume Persistent on EC2: Step-by-Step Guide

πŸ”§ Step 1: Create an EBS Volume

  1. Go to the EC2 Dashboard in AWS Console.
  2. In the left panel, click Elastic Block Store > Volumes.
  3. Click Create Volume.
  4. Fill in:
    • Size (e.g., 10 GiB)
    • Availability Zone (Must match your EC2 instance)
    • Leave other options default
  5. Click Create Volume.

omkarsharma2821

πŸ”— Step 2: Attach Volume to EC2 Instance

  1. Select the newly created volume.
  2. Click Actions > Attach Volume.
  3. Choose your instance and device name (e.g., /dev/xvdf).
  4. Click Attach.

omkarsharma2821

omkarsharma2821

omkarsharma2821

omkarsharma2821

The volume status changes from Available ➝ In-use.

πŸ§ͺ Step 3: Verify the Volume is Attached

lsblk
Enter fullscreen mode Exit fullscreen mode

Output will show /dev/xvdf (or similar) listed without a mountpoint.

omkarsharma2821

🧱 Step 4: Format the Volume with ext4

sudo mkfs -t ext4 /dev/xvdf
or
sudo mkfs.ext4 /dev/xvdf
Enter fullscreen mode Exit fullscreen mode

omkarsharma2821

❓ Why Do We Format the Volume?

When you create a new EBS volume, it's like a brand-new hard drive β€” it has no filesystem. Formatting it is essential because:

  • It defines how data is stored and organized.
  • It prepares the volume to store files and directories.
  • It enables the system to mount and use the volume.

⚠️ Without formatting, the volume cannot be used to store any data.

πŸ“‚ Step 5: Create a Mount Directory

sudo su : to swtich to super user
cd / : to go to home directory
mkdir /your-dir-name : to create new directory
Enter fullscreen mode Exit fullscreen mode

Learn Linux commands from scratch

omkarsharma2821

πŸ“Œ Step 6: Mount the Volume

mount /dev/xvdf /test
Enter fullscreen mode Exit fullscreen mode

omkarsharma2821

Verify the mount:

df -h
Enter fullscreen mode Exit fullscreen mode

πŸ” Step 7: Make the Mount Persistent (After Reboot)

To make the mount persistent, add an entry to /etc/fstab.

  1. First, get the UUID:
blkid
Enter fullscreen mode Exit fullscreen mode

omkarsharma2821

  1. Open the fstab file:
vi /etc/fstab
Enter fullscreen mode Exit fullscreen mode
Note:
press "i" to insert mode
press "esc" to return 
press ":wq!" to write and exit
Enter fullscreen mode Exit fullscreen mode

omkarsharma2821

πŸ”„ Step 8: Reboot and Verify

reboot
Enter fullscreen mode Exit fullscreen mode

After reboot, connect again and run:

df -h
Enter fullscreen mode Exit fullscreen mode

You should see /test mounted. βœ…

🧹 Optional: Test Persistence

You can unmount and remount to test:

umount /test
mount -a
df -h
Enter fullscreen mode Exit fullscreen mode

Top comments (0)