Create a XFS filesystem using LVM

In this blog post, I will demonstrate how to use LVM to create flexible XFS filesystems where it allows us to extend or reduce its size without disrupting services.

Instructions

Let’s initiate installing LVM:

Next, the disk should be already attached to the instance, and we can verify with fdisk command:

Now,  we will create a partition in the disk:

With the partition created, we will create the Volume Group :

The following step is to create the Logical Volume :

We can see our progress using lvdisplay to see the logical volume status:

Subsequently, the next step is to create the directory that we will use if it does not exist already:

Now, we create the XFS filesystem:

And, let’s mount the partition:

And it is done, we can check that using df command:

If you want to auto-mount when rebooting the OS, you can add the new partition to the fstab:

Conclusion

Using LVM is an excellent option to have flexible and easy management of disks and to extend the partition over time. If LVM is planned to be used in advance when deploying the instance, it can save time and avoid application downtime in the future.

For AWS using EBS volumes, it is possible to use the API itself to extend the partition size, which may be more straightforward and makes LVM redundant:

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/requesting-ebs-volume-modifications.html

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html

It might be interesting to use LVM on EC2 in case you want to overcome disk bandwidth and IOPs limitations since there is a limit for it. Another alternative is to switch to io1 or another type of disk. This topic may be of intense discussion since many aspects need to be taken into consideration to decide the disk architecture such as price and technical requirements, which are not the subject of this post.

Leave a Reply