Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: How to extend EBS & filesystem online on AWS server  (Read 3479 times)

0 Members and 1 Guest are viewing this topic.

akhilt

  • Guest
How to extend EBS & filesystem online on AWS server
« on: March 03, 2018, 11:47:33 am »
Here we will discuss steps to extend EBS volume attached to AWS EC2 Linux server and then extend filesystem on it at Linux level using LVM.

It involves two steps –
1. Extend attached EBS volume on AWS console
2. Extend file system using LVM
Sample case:

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

The expected output of ‘lsblk’ command will be:
Code: [Select]
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

1. To extend EBS volume attached to EC2 server in AWS

Login to AWS EC2 console, click on ‘Volumes’ under ‘Elastic Block Store’ in left-hand side menu. Select the volume which is attached to our EC2 server and we want to extend. From ‘Actions’ drop down menu select ‘Modify Volume’. Now we can see the below screen :



Change size (here we changed from 10 to 16GB) and click ‘Modify’. Accept the confirmation dialogue box by clicking ‘Yes’.

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

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

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

Code: [Select]
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.

Code: [Select]
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

We can see in above output, now ‘xvdf’ disk is shown with size 16G. So, new disk size is identified. Now proceed to extend file system online using ‘lvextend’ and ‘resize2fs’.

Code: [Select]
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 mount point is showing new bigger size.

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

We can see as we expected, mount point is now 15G in size from 9.9GB earlier size. :)