Steps to extend disk (EBS) on Amazon Linux 2 without a downtime. The following instructions are for hypervisor type nitro based instances.
- Create a snapshot of the volume in case something goes wrong.
- Wait to make sure volume state is in optimizing or completed state.
- Extend the volume size to desired value (e.g. 10 GiB to 20 GiB)
- Check volume partition using lsblk. The partition size should be less than the volume size.
sudo lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT nvme0n1 259:0 0 10G 0 disk ├─nvme0n1p1 259:1 0 10G 0 part / └─nvme0n1p128 259:2 0 1M 0 part
- Extend the partition number using growpart. The command will need partition number. e.g. in
nvme0n1p1 partition number is number after p.sudo growpart /dev/nvme0n1 1
- Verify that the partition number has been extended using lsblk command again. New size will show 20G when increasing from 10G to 20G.
- Get the name, size, type, and mount point for the file system that you need to extend. Use the df -hT command
df -hT Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 957M 0 957M 0% /dev tmpfs tmpfs 975M 0 975M 0% /dev/shm tmpfs tmpfs 975M 436K 974M 1% /run tmpfs tmpfs 975M 0 975M 0% /sys/fs/cgroup /dev/nvme0n1p1 xfs 10G 9.0G 1G 90% / tmpfs tmpfs 195M 0 195M 0% /run/user/1001
- For xfs filesystem, use the xfs_growfs command and specify the mount point of the file system that you noted in the previous step
sudo xfs_growfs -d /
- Use df -hT to ensure the new size is available to use (20G instead of 10G in our example)