Extend AWS EBS Volume Without Downtime in Linux

Today we will learn, How to extend your AWS EC2 EBS volume disk without Downtime.

If you are using Windows you can easily extend your EBS drive without downtime and without any problem. You can use this link for window process. But if come to Linux, Disk extend part will become some headache.

So, Let start the process and make it easy:

Lets first, extend (modify) the disk size from the AWS Console.

1: Login to your AWS console.

2: Choose “EC2” from the services list.

3: Click on “Volumes” under ELASTIC BLOCK STORE menu (on the left)

4: Choose the volume that you want to resize, right click on “Modify Volume”

5 Set the new size for your EBS volume.

6. Click on modify.

Please wait, till its not modified completely from the console.

Once its completed, we need to extend the partition from the server.

Lets start the extend process:

First, SSH to the EC2 instance where the EBS we’ve just extended is attached to.

Type the following command to expend the disk size:

1: List the block devices using the below command:

1> lsblk

Nitro based instance Output:

1NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
2nvme0n1       259:1    0  16G  0 disk
3└─nvme0n1p1   259:2    0   8G  0 part /
4└─nvme0n1p128 259:3    0   1M  0 part

Non Nitro based instance Output:

1NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
2xvda    202:0    0  16G  0 disk
3└─xvda1 202:1    0   8G  0 part /

Note: If you see, size of the root volume reflects the new size and the size of the partition reflects the original size, then we must extend the partition before you can extend the file system using growpart command.

2: Expend the partition : For Nitro Based Instance:

1> sudo growpart /dev/nvme0n1 1

For Non Nitro based instance:

1> sudo growpart /dev/xvda 1

3: Now check the partition is expended or not by entering below command:

1> lsblk

Nitro based instance Output:

1NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
2nvme0n1       259:1    0  16G  0 disk
3└─nvme0n1p1   259:2    0  16G  0 part /
4└─nvme0n1p128 259:3    0   1M  0 part

Non Nitro based instance Output:

1NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
2xvda    202:0    0  16G  0 disk
3└─xvda1 202:1    0  16G  0 part /

4: Partition is extended, Now Use the file system-specific command to resize each file system to the new volume capacity.

Before resize, enter the below command to check the size of file-system:

1> df -h

Output:

1Filesystem       Size  Used Avail Use% Mounted on
2/dev/xvda1       8.0G  1.9G  6.2G  24% /

Also, Please verify the file system using the below command:

For Nitro based instance:

1sudo file -s /dev/nvme?n*

Output:

1/dev/nvme0n1:     x86 boot sector ...
2/dev/nvme0n1p1:   SGI XFS filesystem data ...

For Non-Nitro based instance:

1sudo file -s /dev/xvd*

Output:

1/dev/xvda:  DOS/MBR boot sector ..
2/dev/xvda1: Linux rev 1.0 ext4 filesystem data ...
Now extend the filesystem:

For ext2, ext3, or ext4 file system, Use the resize2fs command to extend the file system:

1> sudo resize2fs /dev/xvda1

For XFS file system, Use the xfs_growfs command to extend the file system:

1sudo xfs_growfs -d /

Note: If XFS tools is not already installed, Please install the XFS tools using below command:

1sudo yum install xfsprogs

5: Lastly, You can verify that the file system reflects the increased volume size by using the df -h command.

Reference link: https://docs.amazonaws.cn/en_us/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html

I :heart: AWS! :smile: Enjoy