Expanding the storage of an AWS EC2 instance involves attaching an Elastic Block Store (EBS) volume, modifying it, and resizing the filesystem to use the additional space. This blog walks you through these steps with a detailed explanation of the commands you will use.
Prerequisites
- AWS EC2 instance: You need an Ubuntu-based EC2 instance running on AWS.
- Local Linux system: A Linux system (Ubuntu in this case) to SSH into the EC2 instance.
- AWS EBS Volume: An attached EBS volume to your instance.
Steps to Attach and Modify an EBS Volume
Step 1: Switch to the Root User
sudo su
This command allows you to switch to the root user for administrative privileges required to perform disk operations.
Step 2: Change to the Home Directory
cd
Navigate to the home directory to ensure you’re working in a familiar and safe location.
Step 3: Check Current Disk Usage
df -hT
-
df
: Displays the amount of disk space used and available on filesystems. -
-hT
: Displays sizes in a human-readable format (-h
) and includes filesystem types (-T
).
Use this to verify the current storage and note if the new EBS volume is recognized.
Step 4: List Block Devices
lsblk
- Displays information about available block devices such as disks and partitions.
- Confirm that the new EBS volume (
/dev/xvdb
) is attached to your instance.
Step 5: View Disk Partitions
fdisk -l
- Lists all disk partitions.
- Helps you identify the available disk space on the new EBS volume.
Step 6: Create a Partition on the New Volume
fdisk /dev/xvdb
- This command opens the partition editor for
/dev/xvdb
.
Follow these prompts:
-
n
: Create a new partition. -
w
: Write changes to disk and exit.
You now have a partition (/dev/xvdb1
) ready for formatting.
Step 7: Format the Partition with XFS
mkfs -t xfs /dev/xvdb1
-
mkfs
: Creates a filesystem on the partition. -
-t xfs
: Specifies the XFS filesystem type, known for scalability and performance.
Step 8: Create a Directory for Mounting
mkdir new_directory
Create a new directory where the EBS volume will be mounted.
Step 9: Mount the Partition
mount /dev/xvdb1 /new_directory
Mount the newly formatted partition to the new_directory
.
Step 10: Expand the Partition
If the EBS volume has been resized in AWS, you need to expand the partition to use the additional space.
Resize the Partition Table
growpart /dev/xvdb 1
-
growpart
: Extends a partition on a block device. -
/dev/xvdb 1
: Indicates the first partition of the volume.
Resize the Filesystem
xfs_growfs -d new_directory
-
xfs_growfs
: Grows the XFS filesystem. -
-d
: Expands the filesystem to the maximum available size. -
new_directory
: Specifies the mount point.
Verification
- Check Filesystem Usage:
df -hT
Verify that the filesystem reflects the increased size.
- Inspect the Mounted Volume:
lsblk
Confirm the updated partition and filesystem.
Conclusion
By following these steps, you can successfully attach, partition, format, and expand an AWS EBS volume on your EC2 instance. This process ensures that your instance can handle increased storage requirements seamlessly.
Happy cloud computing! 🚀
Top comments (0)