Skip to content

How do I expand the Amazon EBS root volume of my Amazon EC2 Linux instance?

4 minute read
0

I want to expand the Amazon Elastic Block Store (Amazon EBS) root volume of my Amazon Elastic Compute Cloud (Amazon EC2) Linux instance.

Short description

Use the Amazon EBS Elastic Volumes feature to expand the root volume of an Amazon EC2 Linux instance that runs on a current generation instance. To expand the Amazon EBS root volume on a previous generation instance, you must detach and then reattach the volume.

Note: For Windows instances, see How do I increase the EBS root volume of my EC2 Windows instance?

Resolution

Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.

Before you modify your Amazon EBS volume, complete the following steps:

  1. Review the requirements for Amazon EBS volume modifications.
  2. Review the best practices for volume performance on Linux instances.
  3. Review how to modify your Amazon EBS volume to identify and address potential issues before you expand your volume.

Important: If you have volumes attached to current generation instances before November 3, 2016, you must either stop and restart the instance. Or, detach and then reattach the volume to initialize the Amazon EBS Elastic Volumes feature. This is a one-time requirement.

Warning: When you stop an instance, the instance store volumes lose all data. Back up the data on your instance store volumes to persistent storage before you stop the instance.

Modify the Amazon EBS volume size

To modify the volume size, use either the Amazon EC2 console or the AWS CLI.

Amazon EC2 console

  1. Open the Amazon EC2 console.
  2. In the navigation pane, choose Volumes.
  3. Select the root volume that you want to expand. To identify the root volume, check the Attachment information column for the device name.
    Note: The device name is typically /dev/xvda or /dev/sda1 for Linux and /dev/sda1 for Windows.
  4. Choose Actions, and then choose Modify volume.
  5. For Size, enter the new size in GiB.
  6. Choose Modify, and then choose Modify again.
  7. Wait for the volume state to change from modifying to optimizing, and then to in-use.
    Note: The wait time can take several minutes to several hours depending on the size of the change.

AWS CLI

To modify your Amazon EBS volume, run the following modify-volume command:

aws ec2 modify-volume --volume-id vol-EXAMPLE12345 --size 100

Note: Replace vol-EXAMPLE12345 with your root volume ID.

To monitor the modification progress, run the following describe-volumes-modifications command:

aws ec2 describe-volumes-modifications --volume-ids vol-EXAMPLE12345

Note: Replace vol-EXAMPLE12345 with your root volume ID.

Wait until the modification state shows optimizing or completed before proceeding.

Extend the file system

After the volume modification completes, you must extend the partition, if applicable, and the file system to use the new space.

Note: The following steps are for Linux instances.

  1. Use SSH to connect to your instance.

  2. To check the current block device layout, run the following command:

    lsblk

    Example output:

    NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    nvme0n1       259:0    0  100G  0 disk
    ├─nvme0n1p1   259:1    0   50G  0 part /
    └─nvme0n1p128 259:2    0    1M  0 part

    The disk (nvme0n1) in the example output shows 100 GiB, but the partition (nvme0n1p1) still shows 50 GiB.

  3. To grow the partition to use the available space, run the following growpart command:

    sudo growpart /dev/nvme0n1 1

    Note: Replace /dev/nvme0n1 and 1 with your device name and partition number from the lsblk output. There's a space between the device name and the partition number.

  4. To check your file system type, run the following command:

    df -hT
  5. Based on your file system type, run one of the following commands to extend the file system:

    For ext4, run the following command:

    sudo resize2fs /dev/nvme0n1p1

    Note: The ext4 file system includes Amazon Linux 2, Ubuntu, and Red Hat Enterprise Linux (RHEL).

    For XFS, run the following command:

    sudo xfs_growfs -d /

    Note: The XFS file system includes Amazon Linux 2023 and some RHEL versions.

Verify the new size

To verify the size of your modified volume, run the following command:

df -hT

Example output:

Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/nvme0n1p1 ext4   97G   15G   82G  16% /

Related information

How do I convert the default MBR partitioning scheme to GPT for my EC2 Ubuntu instance?

Root volumes for your Amazon EC2 instances

AWS OFFICIALUpdated 2 months ago