Create and Extend XFS filesystem based on LVM

Channel: Linux
Abstract: option [[email protected] ~]# lvextend -L +3G /dev/vg_xfs/xfs_db -r As we can see above that the size of[[email protected] ~]# mkfs.xfs /dev/vg_xfs/xf

XFS is a File system which is designed for high performance ,scalability and Capacity point of view. It is generally used where large amount data to be stored / used on the File system. Some of the awesome freeze features of xfs are xfs_freeze, snapshot, xfs_unfreeze. One of the limitation of XFS is that we can not shrink or reduce this file system.

XFS is the default file system on CentOS 7 and RHEL 7. In this post we will discuss how to create and extend xfs file system based on LVM in CentOS 7. I am assuming that a new disk is assigned to Linux box and i am going to perform below steps on CentOS 7.

Step:1 Create a partition using fdisk

In the below example i have created 10GB partition on /dev/sdb and set 「8e」 as toggle id.

Step:2 Create LVM components : pvcreate, vgcreate and lvcreate.
[[email protected] ~]# pvcreate /dev/sdb1
 Physical volume "/dev/sdb1" successfully created
[[email protected] ~]#

[[email protected] ~]# vgcreate vg_xfs /dev/sdb1
 Volume group "vg_xfs" successfully created
[[email protected] ~]#

[[email protected] ~]# lvcreate -L +6G -n xfs_db vg_xfs
 Logical volume "xfs_db" created
[[email protected] ~]#
Step:3 Create XFS file system on lvm parition 「/dev/vg_xfs/xfs_db」
[[email protected] ~]# mkfs.xfs /dev/vg_xfs/xfs_db

Step:4 Mount the xfs file system

Create a directory named as xfs_test under /root and mount it using mount command.

For the permanent mounting , use /etc/fstab file.

Step:5 Extend the size of xfs file system

Check the whether free space is available in Volume group (vg_xfs) or not using below command :

[[email protected] ~]# vgs vg_xfs 
 VG #PV #LV #SN Attr VSize VFree
 vg_xfs 1 1 0 wz--n- 10.00g 4.00g
[[email protected] ~]#

So we will extend the file system by 3GB using lvextend command with 「-r」 option

[[email protected] ~]# lvextend -L +3G /dev/vg_xfs/xfs_db -r

As we can see above that the size of 「/dev/vg_xfs/xfs_db」 has been extended from 6 GB to 9GB

Note : If xfs is not based on LVM , the use the xfs_growsfs command as shown below :

[[email protected] ~]# xfs_growfs <Mount_Point> -D <Size>

The 「-D size」 option extend the file system to the specified size (expressed in file system blocks). Without the -D size option, xfs_growfs will extend the file system to the maximum size supported by the device.

Read Also: How to Setup Disk Quota on XFS File System in Linux Servers

Ref From: linuxtechi

Related articles