Tag Archives: how to extend ebs volume

How to extend EBS & filesystem online on AWS server

Learn how to extend EBS & filesystem online on the AWS EC2 Linux server. Step by step procedure along with screenshots and sample outputs.

Extend EBS & filesystem online on AWS

In this article, we will walk you through steps to extend EBS volume attached to the EC2  Linux server and then extend the filesystem on it at Linux level using LVM. Read here about how to attach EBS volume to the EC2 server in AWS.

It involves two steps –

  1. Extend the attached EBS volume on AWS console
  2. Extend file system using LVM

Current setup :

We have a 10GB EBS volume attached to the Linux EC2 server. /testmount of 9.9GB is created using this disk at OS level. We will be increasing it to 15GB.

root@kerneltalks # lsblk
NAME                   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda                   202:0    0   10G  0 disk
└─xvda1                202:1    0   10G  0 part /
xvdf                   202:80   0   10G  0 disk
└─datavg-datalv (dm-0) 253:0    0  9.9G  0 lvm  /testmount

Step 1: How to extend EBS volume attached to the EC2 server in AWS

Login to AWS EC2 console, click on Volumes under Elastic Block Store in the left-hand side menu. Then select the volume you want to extend. From Actions drop-down menu select Modify Volume  You will see below screen :

Modify EBS volume in AWS

Change size (in our case we changed from 10 to 16GB) and click Modify. Accept the confirmation dialogue box by clicking Yes.

Once modify operation succeeded, refresh the Volume list page and confirm the new size is being shown against the volume you modified just now. Now, your EBS volume is extended successfully at the AWS level. You need to extend it at OS level now.

Step 2: How to re-scan new size of EBS volume in Linux & extend filesystem online

Since EBS volumes size has been changed you need to rescan it in OS so that kernel and volume managers (LVM in our case) should make a note about the new size. In LVM, you can use pvresize command to rescan this extended EBS volume.

root@kerneltalks # pvresize /dev/xvdf
  Physical volume "/dev/xvdf" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

After successful rescan, check if the new size is identified by the kernel or not using lsblk command.

root@kerneltalks # lsblk
NAME                   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda                   202:0    0   10G  0 disk
└─xvda1                202:1    0   10G  0 part /
xvdf                   202:80   0   16G  0 disk
└─datavg-datalv (dm-0) 253:0    0  9.9G  0 lvm  /testmount

You can see in the above output, now xvdf disk is shown with size 16G! So, the new disk size is identified. Now proceed to extend file system online using lvextend and resize2fs. Read how to extend the filesystem online for more details.

root@kerneltalks # lvextend -L 15G /dev/datavg/datalv
  Extending logical volume datalv to 15.00 GiB
  Logical volume datalv successfully resized

root@kerneltalks # resize2fs /dev/datavg/datalv
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/datavg/datalv is mounted on /testmount; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/datavg/datalv to 3932160 (4k) blocks.
The filesystem on /dev/datavg/datalv is now 3932160 blocks long.

Check if the mount point is showing new bigger size.

root@kerneltalks # df -Ph /testmount
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/datavg-datalv   15G  153M   14G   2% /testmount

Yup, as we planned /testmount is now 15G in size from 9.9GB earlier size.