Resizing a volume, partition and filesystem on EC2
From within the console locate the volume attached to the EC2 instance that you want to modify, select and from the Actions dropdown select 'Modify Volume'.
Login to your EC2 as a user with sudo privileges.
Check the kernel version is greater than 4.2
If it is then you're good to go. The volume will resize automatically without further intervention. If not then you may need to remount the volume. For further information on this, check here:
At this point your partition will be the same size as it was previously although the volume size will reflect what you changed it to. Use the lsblk command to show your device information.
nvme0n1 259:0 0 16G 0 disk └─nvme0n1p1 259:1 0 8G 0 part /
Extend an existing partiton
To take advantage of the additional disk space on an existing partition, run the following command:
sudo growpart nvme0n1 1
This command tells linux to grow the first partition on nvme0n1.
If you run df you will see that your file system occupies the same space on the partition. In order to extend your file system to use more partition space, you need to establish what sort of file system you are using:
/dev/nvme0n1p1 ext4 9.0G 8.0G 1022M 89% /
In this case the file system is ext4 s we can use the following command:
sudo resize2fs /dev/nvme0n1p1
You should see something like:
resize2fs 1.44.1 (24-Mar-2018) Filesystem at /dev/nvme0n1p1 is mounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 2 The filesystem on /dev/nvme0n1p1 is now 4194043 (4k) blocks long.
If your file system type is xfs then you'll need
sudo apt-get install xfsprogs
and depending on the mount point -
sudo xfs_growfs -d /