Post

How to Extend Disk Space on an EC2 Instance

If you’ve increased the size of your EC2 instance’s disk but don’t see the additional space, follow these simple steps to extend the partition and resize the filesystem on an Ubuntu instance.

Step 1: Log in to Your EC2 Instance

Use SSH to connect to your EC2 instance:

1
ssh -i your-key-file.pem ec2-user@your-ec2-instance-public-dns

or ssh normally if you have already added the key.

Step 2: Check Current Disk Space

1
df -h

Step 3: List Partitions

1
lsblk

Step 4: Extend the Partition

Install growpart if not already installed:

1
2
sudo apt-get update
sudo apt-get install cloud-guest-utils

Run growpart to extend the partition:

1
sudo growpart /dev/xvda 1

Step 5: Resize the Filesystem

  • For ext4 filesystem:
    1
    
    sudo resize2fs /dev/xvda1
    
  • For xfs filesystem:
    1
    
    sudo xfs_growfs /
    

Step 6: Verify the Changes

Check the new disk space:

1
df -h

Example Commands

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Step 1: Log in
ssh -i your-key-file.pem ec2-user@your-ec2-instance-public-dns

# Step 2: Check current disk space
df -h

# Step 3: List partitions
lsblk

# Step 4: Extend the partition
sudo apt-get update
sudo apt-get install cloud-guest-utils
sudo growpart /dev/xvda 1

# Step 5: Resize the filesystem (choose the appropriate command)
sudo resize2fs /dev/xvda1  # For ext4
# or
sudo xfs_growfs /          # For xfs

# Step 6: Verify the changes
df -h

By following these steps, you can effectively extend the disk space on your EC2 instance.

This post is licensed under CC BY 4.0 by the author.

© 2023 by Rana Waqas. Proudly created with Jekyll and Chirpy.