- Increase the volume to the desired size either using 1) console ->ec2 Instances → volume → select the volume and choose the option to increase in the right side buttons or 2) cli command
aws ec2 modify-volume --size 150 --volume-id vol-1234567890abcdef0
Pre-Requisite
- Create a snapshot of the volume, in case you need to roll back your changes. For more information, see Create Amazon EBS snapshots.
- Confirm that the volume modification succeeded and that it is in the
optimizing
orcompleted
state. For more information, see Monitor the progress of volume modifications. - Ensure that the volume is attached to the instance and that it is formatted and mounted. For more information, see Format and mount an attached volume.
- If you are using logical volumes on the Amazon EBS volume, you must use Logical Volume Manager (LVM) to extend the logical volume. For instructions about how to do this, see the Extend the logical volume section in the How do I create an LVM logical volume on an entire EBS volume? AWS Knowledge Center article.
Extend the file system of EBS volumes
To extend the file system of EBS volumes
-
Resize the partition, if needed. To do so:
a. Check whether the volume has a partition. Use the lsblk command.
In the following example output, the root volume (xvda) has a partition (xvda1), while the additional
volume (xvdf) has no partition.``` [ec2-user ~]$ sudo lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 16G 0 disk └─xvda1 202:1 0 8G 0 part / xvdf 202:80 0 24G 0 disk
If the volume has a partition, continue the procedure from the following step (2b). If the volume has no partitions, skip steps 2b, 2c, and 2d, and continue the procedure from step 3.
b. Check whether the partition needs to be extended. In the lsblk command output from the previous step, compare the partition size and the volume size.
If the partition size is smaller than the volume size, continue to the next step. If the partition size is equal to the volume size, the partition can’t be extended.
c. Extend the partition. Use the growpart command and specify the partition to extend.
[ec2-user ~]$ sudo growpart /dev/xvda 1
d. Verify that the partition has been extended. Use the lsblk command. The partition size should now be equal to the volume size.
[ec2-user ~]$ sudo lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 16G 0 disk └─xvda1 202:1 0 16G 0 part / xvdf 202:80 0 24G 0 disk
-
Extend the file system.
a. Get the name, size, type, and mount point for the file system that you need to extend. Use the **df -hT** command.
The commands to extend the file system differ depending on the file system type. Choose the following correct command based on the file system type that you noted in the previous step.
-
[XFS file system] Use the xfs_growfs command and specify the mount point of the file system that you noted in the previous step.
[ec2-user ~]$ sudo xfs_growfs -d /
[Ext4 file system] Use the resize2fs command and specify the name of the file system that you noted in the previous step.
[ec2-user ~]$ sudo resize2fs /dev/xvda1