AWS: Expanding the Linux root Volume without stopping/shutdown (online).

In this tutorial, we will learn how to expand or increase the Linux root volume without stopping/shutdown the instance or stopping any services on the instance without restart.

In this, we have 2 steps to be followed.

  1. We have to change the volume size on the AWS console.
  2. We have to increase the partition size on the Linux Instance.

AWS Console Changes

  • Log in to the AWS Console.
  • Click on EC2
  • Find the Instance on which we want to increase the volume.
  • Find the Root partition of the Instance in the description panel.

linux1

  • Click on the Root Device, which will show all the device information on the popup.

linux2

  • Click on EBI ID. This will take you to respective volume on EBS Volumes
  • Right-Click on the respective volume where we want to increase the disk space.
  • Click on Modify Volume.linux3
  • Once the Modify Volume pop-up, increase the size of the Volume to our need and Click on Modify.

linux4

  • It will take around 5 – 8 min to increase the volume size on the AWS console after some time we can see the increased size on the AWS console.

Linux Instance Side.

  • Log in to the Instance using the Credentials and corresponding key pair.
  • Check the Existing disk space using the command df –h
$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  7.1M  0.8G  90% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
  • Change the login to root user by using sudo –i.
  • Run lsbk to show the block devices attached to the instance.
# lsbk
NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
xvda    202:0    0   10 G  0 disk
└─xvda1 202:1    0   7.9G  0 part /

Here if we see that the block device xvda has 10 GB attached and having 1 partition with 7.9 GB for the root

  • Run the growpart command to increase the root partition (/)
# growpart /dev/xvda 1

The filesystem on /dev/xvda1 is now 18350080 blocks long.

  • Finally, increase the root partition with resize command
# resize2fs /dev/xvda1
resize2fs 1.42.3
   Filesystem at /dev/xvda1 is mounted on /; on-line resizing required
    old_desc_blocks = 1, new_desc_blocks = 5
    Performing an on-line resize of /dev/xvda1 to 18350080 (4k) blocks.
    The filesystem on /dev/xvda1 is now 18350080 blocks long.
  • Now if we check the disk space using df, we can observe the disk space has been increased to a size we have extended on the AWS.
# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            10G  7.1M  2.9G  69% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm

Leave a Reply

Your email address will not be published.

Have a Question?