๐ง Step 1: Create an EBS Volume
- Go to the EC2 Dashboard in AWS Console.
- In the left panel, click Elastic Block Store > Volumes.
- Click Create Volume.
- Fill in:
- Size (e.g., 10 GiB)
- Availability Zone (Must match your EC2 instance)
- Leave other options default
- Click Create Volume.
๐ Step 2: Attach Volume to EC2 Instance
- Select the newly created volume.
- Click Actions > Attach Volume.
- Choose your instance and device name (e.g.,
/dev/xvdf). - Click Attach.
The volume status changes from Available โ In-use.
๐งช Step 3: Verify the Volume is Attached
lsblk
Output will show /dev/xvdf (or similar) listed without a mountpoint.
๐งฑ Step 4: Format the Volume with ext4
sudo mkfs -t ext4 /dev/xvdf
or
sudo mkfs.ext4 /dev/xvdf
โ 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
| Basis | mkdir /test |
mkdir test |
|---|---|---|
| Path type | Absolute path | Relative path |
| Location | Creates test in the root directory (/). |
Creates test in the current working directory. |
| Starting point | Starts from / (root). |
Starts from the current directory. |
| Example current directory | /home/ubuntu |
/home/ubuntu |
| Result | /test |
/home/ubuntu/test |
| Permission | May require sudo. |
Usually requires write permission in the current directory. |
| Use case | When you want to create a directory at a specific absolute location. | When you want to create a directory in your current location. |
Easy trick to remember:
-
/testโ Root directory. -
testโ Current directory.
Example:
pwd
# Output: /home/ubuntu
mkdir test
# Creates /home/ubuntu/test
mkdir /test
# Creates /test
๐ Step 6: Mount the Volume
mount /dev/xvdf /test
if not want to mount at /
Verify the mount:
df -h
๐ Step 7: Make the Mount Persistent (After Reboot)
To make the mount persistent, add an entry to /etc/fstab.
- First, get the UUID:
blkid
- Open the fstab file:
if vi /etc/fstab
Note:
press "i" to insert mode
press "esc" to return
press ":wq!" to write and exit
๐ Step 8: Reboot and Verify
reboot
After reboot, connect again and run:
df -h
You should see /test mounted. โ
To increase the size of the same EBS volume, you must first modify the volume from the AWS Management Console (AWS Portal) and then extend the partition and file system inside the EC2 instance, if required.
sudo resize2fs /dev/nvme1n1
๐งน Optional: Test Persistence
You can unmount and remount to test:
umount /test
mount -a
df -h
mount -a
- Reads the file /etc/fstab.
- Mounts all configured file systems that are not currently mounted and are eligible for automatic mounting.
- Commonly used to test /etc/fstab entries without rebooting the server.













Top comments (0)