Creating and Attaching New EBS Volume
Create EBS volume in AWS Console:
Select desired size, volume type, and availability zone
Note: AZ must match EC2 instance
Attach volume to EC2 instance:
Select volume in AWS Console
Click "Actions" > "Attach Volume"
Choose target EC2 instance
Note device name (e.g., /dev/sdb)
Verify disk attachment:
lsblk
ls /dev/
- Check filesystem:
sudo file -s /dev/sdb
- Create filesystem (if output shows "data"):
sudo mkfs -t ext4 /dev/sdb
- Verify filesystem:
sudo file -s /dev/sdb
- Mount volume:
sudo mkdir /test
sudo mount /dev/sdb /test
df -h
Expanding Existing EBS Volume
Modify volume size in AWS Console:
Select volume
"Actions" > "Modify Volume"
Enter new size
Verify new size on instance:
lsblk
- Resize partition using parted:
sudo parted /dev/sdb
(parted) resizepart
Partition number? 1
Warning: Partition is being used. Continue? yes
End? 100%
quit
- Check filesystem:
sudo file -s /dev/sdb
- Unmount volume:
sudo umount /dev/sdb
- Check filesystem integrity:
sudo e2fsck -f /dev/sdb
- Resize filesystem:
sudo resize2fs /dev/sdb
- Remount volume:
sudo mount /dev/sdb /test
df -h
Best Practices
Always backup data before resizing
Verify size changes using both
lsblk
anddf -h
Run e2fsck before resize2fs
Use consistent mount points