Thursday, March 31, 2016

XFS file system









XFS is the default file system in RHEL 7 . This file system allows to create files up to 500TB where in RHEL 6 (ext4) it is limited up to 50TB.

XFS brings the following benefits

  • ability to manage up to 500TB file systems with files up to 50TB in size,
  • best performance for most workloads (especially with high speed storage and larger number of cores),
  • less CPU usage than most of the other file systems 
  • the most robust at large scale (has been run at hundred plus TB sizes for many years),
  • the most common file system in multiple key upstream communities: most common base for ceph, gluster and openstack more broadly,
  • pioneered most of the techniques now in Ext4 for performance (like delayed allocation --where blocks will be allocated as late after the files are fully written in disk),
  • no file system check at boot time,
  • CRC checksum on all metadata blocks.
Also one more important thing is we cannot shrink the XFS file system,we can only extent it

XFS basic management 

 In our case we have 2 GB iscsi partition in the server and same need to be configured as xfs along with lvm

1. Check the disk 
[root@redhat7-test ~]# fdisk -l

...........................................................output is omitted .............

Disk /dev/sdb: 2153 MB, 2153398272 bytes, 4205856 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

2. Format the disk as usual (follow the same procedure as normal disk in linux)

[root@redhat7-test ~]# fdisk  /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
...................................................................................

[root@redhat7-test ~]# fdisk -l

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4205855     2101904   8e  Linux LVM

3. Create the physical volume 

[root@redhat7-test ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created

4. Extent the volume group 

[root@redhat7-test ~]# vgextend rhel /dev/sdb1
  Volume group "rhel" successfully extended

5. Create the lvm 

[root@redhat7-test ~]# lvcreate -L 1G -n xfslv rhel
  Logical volume "xfslv" created.

6. Now we have to create the xfs file system using below command 

[root@redhat7-test ~]# mkfs.xfs /dev/rhel/xfslv
meta-data=/dev/rhel/xfslv        isize=256    agcount=4, agsize=65536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=262144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

7. Mount the xfs file system 

[root@redhat7-test ~]# mount /dev/rhel/xfslv /xfs/

[root@redhat7-test ~]# df -h
Filesystem              Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root    14G  802M   14G   6% /
devtmpfs                488M     0  488M   0% /dev
tmpfs                   497M     0  497M   0% /dev/shm
tmpfs                   497M  6.6M  491M   2% /run
tmpfs                   497M     0  497M   0% /sys/fs/cgroup
/dev/sda1               4.7G  125M  4.6G   3% /boot
/dev/mapper/rhel-xfslv 1014M   33M  982M   4% /xfs

8. To increase the xfs file system 

[root@redhat7-test ~]# lvextend --size +50M /dev/rhel/xfslv
  Rounding size to boundary between physical extents: 52.00 MiB
  Size of logical volume rhel/xfslv changed from 1.00 GiB (256 extents) to 1.05 GiB (269 extents).
  Logical volume xfslv successfully resized


[root@redhat7-test ~]# xfs_growfs /xfs/
meta-data=/dev/mapper/rhel-xfslv isize=256    agcount=4, agsize=65536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=262144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 262144 to 275456

XFS Advanced Management 

Repairing XFS file system 

Suppose if we observed some issue in the file system and need to be repaired we can use below command 

[root@redhat7-test ~]# xfs_repair /dev/rhel/xfslv
Phase 1 - find and verify superblock...
Phase 2 - using internal log
        - zero log...
        - scan filesystem freespace and inode maps...
        - found root inode chunk
Phase 3 - for each AG...
        - scan and clear agi unlinked lists...
        - process known inodes and perform inode discovery...
        - agno = 0
        - agno = 1
        - agno = 2
        - agno = 3
        - agno = 4
        - process newly discovered inodes...
Phase 4 - check for duplicate blocks...
        - setting up duplicate extent list...
        - check for inodes claiming duplicate blocks...
        - agno = 0
        - agno = 1
        - agno = 2
        - agno = 3
        - agno = 4
Phase 5 - rebuild AG headers and trees...
        - reset superblock...
Phase 6 - check inode connectivity...
        - resetting contents of realtime bitmap and summary inodes
        - traversing filesystem ...
        - traversal finished ...
        - moving disconnected inodes to lost+found ...
Phase 7 - verify and correct link counts...
done

Also the other option is called "Force Log Zeroing" which will be used as a last option if nothing works out . This option has no guaranty and chances for a data corruption . Before setting the label don't forget to unmount the file system

[root@redhat7-test ~]# umount /xfs/
[root@redhat7-test ~]# xfs_admin -L "testlabel" /dev/mapper/rhel-xfslv
writing all SBs
new label = "testlabel"

To read the label use below command

[root@redhat7-test ~]# xfs_admin -l /dev/mapper/rhel-xfslv
label = "testlabel"


XFS Backup Management

 We can take the backup of the xfs file system using xfsdump command . This will not be available in RHEL as default and we have to install it manually

[root@redhat7-test ~]# xfsdump -F -f /root/dump.xfs /xfs
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.4 (dump format 3.0)
xfsdump: WARNING: no session label specified
xfsdump: level 0 dump of redhat7-test:/xfs
xfsdump: dump date: Fri Apr  1 02:27:51 2016
xfsdump: session id: 204db9c4-c7b6-456b-88c4-a428509c340b
xfsdump: session label: ""
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 20800 bytes
xfsdump: /var/lib/xfsdump/inventory created
xfsdump: WARNING: no media label specified
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 21016 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /root/dump.xfs OK (success)
xfsdump: Dump Status: SUCCESS


We can see the dump file inside the /root directory 

[root@redhat7-test ~]# ls -lrt
total 28
-rw-------. 1 root root  1428 Jan 20  2015 anaconda-ks.cfg
drwxr-xr-x. 2 root root    20 Jul 14  2015 python
-rw-r--r--. 1 root root 21016 Apr  1 02:27 dump.xfs


Also below is the restore command from the dump.xfs file

[root@redhat7-test ~]# xfsrestore -f /root/dump.xfs /xfs/
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.4 (dump format 3.0) - type ^C for status and control
xfsrestore: searching media for dump
xfsrestore: examining media file 0
xfsrestore: dump description:
xfsrestore: hostname: redhat7-test
xfsrestore: mount point: /xfs
xfsrestore: volume: /dev/mapper/rhel-xfslv
xfsrestore: session time: Fri Apr  1 02:27:51 2016
xfsrestore: level: 0
xfsrestore: session label: ""
xfsrestore: media label: ""
xfsrestore: file system id: af5e3fab-bab6-416a-8d3e-02c64fdba19a
xfsrestore: session id: 204db9c4-c7b6-456b-88c4-a428509c340b
xfsrestore: media id: 3385959f-0ce5-4bd0-a16d-d883460556d0
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 1 directories and 0 entries processed
xfsrestore: directory post-processing
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore:   stream 0 /root/dump.xfs OK (success)
xfsrestore: Restore Status: SUCCESS


So these are the details about XFS file system . 

Thank you for reading this blog and post your valuable comments below 






  













No comments:

Post a Comment