Bobcares

How to extend XFS filesystem with LVM

by | Apr 2, 2023

Learn how to extend XFS filesystem with LVM. Our Server Management Support team is here to help you with your questions and concerns.

How to extend XFS filesystem with LVM

XFS is a popular file system that offers high scalability, high performance, as well as capacity. It comes in handy when a large amount of data has to be stored or used on the File system.

Furthermore, it offers several useful features like xfs_freeze, snapshot, xfs_unfreeze, and so on.

How to extend XFS filesystem with LVM

Unfortunately, a key limitation of XFS is that we can not downsize or reduce the file system.

However, in modern Linux distributions like Rocky Linux, Fedora, RHEL 8/9, AlmaLinux, and Ubuntu, XFS is still the default file system.

Today. We are going to take a look at how to extend XFS filesystem with LVM. Before we begin, we have to ensure that a new disk (/dev/sdb) has been added to the Linux system so that we can carry out the following steps on it:

  1. First, we have to check if the lvm2 package is installed. If not, run the following commands:
    • For Ubuntu & Debian System

      $ sudo apt install -y lvm2

    • For RHEL 7 & CentOS 7

      # yum install lvm2 -y

    • For RHEL 9/8, Rocky Linux & AlmaLinux

      # dnf install lvm2 -y

  2. Then, we have to create a partition with the fdisk command as seen here:

    fdisk /dev/sdb

    Then enter n to create the new partition.

  3. At this point, we have to enter p as the partition type.
  4. Then, enter 1 as the Partition number.
  5. Next, we have to enter the starting and ending sectors of our hard drive.
  6. Finally, we have to enter the size of the partition. For example, if we want a 10GB partition, we have to enter +10GB.
  7. After the above step, we have to create the LVM components as seen below:

    # pvcreate /dev/sdb1
    Physical volume "/dev/sdb1" successfully created

    ]# vgcreate vg_xfs /dev/sdb1
    Volume group “vg_xfs” successfully created

    # lvcreate -L +6G -n xfs_db vg_xfs
    Logical volume “xfs_db” created

  8. Now, we must format the LVM Partition as XFS File System with the following command:

    # mkfs.xfs /dev/vg_xfs/xfs_db

  9. Then, create a directory, xfs_test under /root. Now, we have to mount it as seen below:

    # mkdir /root/xfs_test
    # mount /dev/vg_xfs/xfs_db /root/xfs_test/
    # df -hT /root/xfs_test
    # mount | grep /dev/mapper/vg_xfs-xfs_db

    If we want to permanently mount the filesystem, our experts recommend adding the entry to /etc/fstab file.

  10. Next, we must verify that the Volume group has free space available with this command:

    # vgs vg_xfs

    Based on the output of the above command we can extend the file system with the lvextend command with “-r” option.

    Alternatively, if XFS is not based on LVM , we have to use xfs_growsfs command as seen below :

    # xfs_growfs -D

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

In summary, our Support Techs demonstrated how to extend XFS filesystem with LVM in few easy steps.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.