Monday, April 6, 2015

[Quick Information]: Create and Extend XFS filesystem based on LVM

Create and Extend XFS filesystem based on LVM

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_freezesnapshot,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.
fdisk_partition

Step:2 Create LVM components : pvcreate , vgcreate and lvcreate.

[root@linuxtechi ~]# pvcreate /dev/sdb1
 Physical volume "/dev/sdb1" successfully created
[root@linuxtechi ~]#

[root@linuxtechi ~]# vgcreate vg_xfs /dev/sdb1
 Volume group "vg_xfs" successfully created
[root@linuxtechi ~]#

[root@linuxtechi ~]# lvcreate -L +6G -n xfs_db vg_xfs
 Logical volume "xfs_db" created
[root@linuxtechi ~]#

Step:3 Create XFS file system on lvm parition “/dev/vg_xfs/xfs_db”

[root@linuxtechi ~]# mkfs.xfs /dev/vg_xfs/xfs_db
create_xfs_filesystem

Step:4 Mount the xfs file system.

Create a directory named as xfs_test under /root and mount it using mount command.
mount_xfs_file_system
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 :
[root@linuxtechi ~]# vgs vg_xfs 
 VG #PV #LV #SN Attr VSize VFree
 vg_xfs 1 1 0 wz--n- 10.00g 4.00g
[root@linuxtechi ~]#
So we will extend the file system by 3GB using lvextend command with “-r” option
[root@linuxtechi ~]# lvextend -L +3G /dev/vg_xfs/xfs_db -r
lvextend_xfs
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 :
[root@linuxtechi ~]# 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.

No comments: