Percona Server for MongoDB Data Directory ResizeRunning a customer’s technical infrastructure often necessitates making changes in response to the shifting requirements of the industry. Thankfully, with the introduction of cloud computing, adapting the infrastructure has never been easier. These days, we can quickly add or remove resources as conditions dictate.

Historically, businesses’ storage capacity needs have fluctuated, and responding to these ever-changing needs has required regular attention. In the past, altering storage capacity typically meant expanding it—a tedious and time-consuming process. Recently, however, cloud computing has made increasing capacity much easier.

In this blog, we will be looking at the processes involved with how to resize EBS volumes in AWS. Once you increase the volume size on the cloud provider level, the commands to increase the size on the OS level will be the same irrespective of the cloud provider.

Suppose a customer is running an environment on an EC2 instance—perhaps a small application that doesn’t require many resources. Since this application uses little storage, a small 15 GB general purpose AWS EBS volume has been attached. As the business needs grow, the customer would like to add more AWS resources, making it necessary to grow your EBS volume to support more data. Needless to say, you would prefer to do this without any downtime. I have divided this into three parts and further subdivided them. The first part will be where we are going to see how we will extend the underlying volume. Following how we can resize the volume depending on the use case like whether the disk is partitioned, not partitioned, or using LVM. In the end, we will be expanding the file system.

Extending underlying volume

Below are steps performed on AWS EBS, you can check and do it as per your cloud service provider.

First, you need to log in to your AWS account and go to the volume and choose the volume you want to resize. After selecting the volume click on “Modify volume” under “Action”. 

Percona Server for MongoDB Data Directory

You are then given the option to change both the disk size and the volume type. You can increase the size now. 

Percona Server for MongoDB Data Directory Resize

 

Once you increase the volume, wait till it reflects on instance level and on OS too. In this blog, we’ll extend the volume to 20 GB and retain the volume type. After the volume has been extended, the EC2 instance and the system both need to be adjusted to adapt to the new size. Note that you can do this adjustment either as a root or as a user with Sudo privileges. Below I will do it as a root user.

Resizing volume

  • Below are the steps you have to perform when you have an LVM.
    1. The first step in this process is checking the volume, partition, and LVM size.

                    Before extending the underlying volume:

                    After extending the underlying volume:

The above shows that the volume has been extended when the disk has LVM. However, the disk having the primary partition is still at the volume’s original size. 

                2. To expand the partition, use the below command. After you do so, you will see that the partition has grown to match the volume size.

Note that there is a space between “/dev/xvdf” and “1.” “1” refers to the partition number.

Also, if you do not have growpart installed, you can do it using the below command:

Above you can see that the partition has been expanded. 

                3. Now we are going to expand the LVM. In order to do that, first we need to resize the physical volume.                             Resize physical volume:

                    Extending size of LV:
                    Below we have extended the LV to 100% of free space-

If you want to extend the LV to a particular size then you can use the below command (for example I have increased it by 3G):

  • Below are the steps when you don’t have a partition:
    1. First, you need to check the volume size.

                    Before extending the volume:

                    After extending the volume:

The above shows that the volume has been extended when the disk does not have any partition. 

  • Below are the steps when you have a partition.
    1. The first step in this process is checking the volume and partition size.

                    Before extending the underlying volume:

                    After extending the underlying volume:

The above shows that the volume has been extended when the disk has a partition. However, the disk having the primary partition is still at the volume’s original size. 

                    2. To expand the partition, use the below command. After you do so, you will see that the partition has grown to match the volume size.

Note that there is a space between “/dev/xvdf” and “1.” “1” refers to the partition number.

Also, if you do not have growpart installed, you can do it using the below command:

Above you can see that the partition has been expanded.

Expanding file system

Now the file system size needs to be checked. Below you will notice that it is still only 15GB, even though the volume/partition/LVM has been resized above.

In our case, since the file system is XFS, we have to rely on the “xfs_growfs” tool, which should already be in the system. If not, you can install it yourself as part of the “xfsprogs” package.

You can run the below command to expand the XFS Filesystem:

If you are using an ext4 file system, you could extend it using the below command:

The volume is now fully resized and ready to be used, and no downtime resulted from this process. You can extend any other partition with the steps shown above, and you just have to ensure you’re using LVM and know the partition you’re extending.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments