Quantcast
Channel: LinOxide
Viewing all articles
Browse latest Browse all 1287

Create / Mount / Manage XFS Filesystem on Fedora 22

$
0
0

XFS is a 64-bit journaling filesystem that was created by Silicon Graphics, Inc (SGI) in the year 1993. It is a high performance and highly scalable filesystem and was ported to the Linux kernel in 2001. Since then, many Linux distributions support XFS and is even the default in some. The latest Fedora 22 server edition uses XFS filesystem by default.

XFS keeps track of the changes made to the filesystem in a log before committing to the main filesystem. As a result, crash recovery is faster and filesystem consistency is  guaranteed. It is possible to extend and defragment the filesystem even when it is actively mounted.

In this article, let us learn how to create , mount and use XFS on Fedora 22.

1) Creating and Mounting XFS

In all the examples that follow, I'm using a virtual device (/dev/xvdc) as my block device.

If XFS is not already installed, install it using the command:

#yum install xfsprogs

Create a new partition in the block device using fdisk and then use the mkfs.xfs command to make a filesystem on it.

#mkfs.xfs  <device>

Here is a sample output where my newly created partition was /dev/xvdc1:

[root@li1014-63 ~]# mkfs.xfs /dev/xvdc1
meta-data=/dev/xvdc1 isize=256 agcount=4, agsize=235008 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=940032, 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=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

You can use the '-f' option with mkfs if the device partition already had a filesystem on it and you want to over write it.   Now the XFS partition is ready to be mounted.

Mounting XFS is straight forward.

#mount <device>  <mount-point>

Here <mount-point> is a local mount point where the filesystem is mounted.

On very large filesystems (>2 TB), you can use 'inode64' option while mounting in order to improve the performance

[root@li1014-63 ~]# mount -o inode64 /dev/xvdc1 /test

Verify that the mounting was successful

[root@li1014-63 ~]# mount

/dev/xvdc1 on /test type xfs (rw,relatime,attr2,inode64,noquota)

If you want to retain the mounting across reboots, add the following line to /etc/fstab

/dev/xvdc1  /test   xfs          defaults     0 0

For devices with write caches, XFS uses write barriers for file system integrity during power losses. If our device does not have write caches, we can disable this option using  'nobarrier' at the time of mounting.

#mount -onobarrier

2) Quota management

Quota is a way of controlling the disk space usage. It warns the user when the alloted space is exceeded. XFS allows soft and hard limit enforcement.  They can be set at user , group and project levels but group and project quotas are mutually exclusive.  XFS quotas will have to be set at the time of mounting the filesystem. It is also possible to opt for only reporting of the filesystem usage without enforcing any limits, using  the 'noenforce' option.

To set the user quota, mount the xfs partition using 'uquota'

[root@li1014-63 ~]# mount /dev/xvdc1 -o uquota /test

Verify that the user quota is now enabled on the partition:

[root@li1014-63 ~]# mount

.....

/dev/xvdc1 on /test type xfs (rw,relatime,attr2,inode64,usrquota)

xfs_quota command is used for managing quotas on XFS filesystems.  Now, check the existence of quota limits on the mounted xfs partition:

[root@li1014-63 ~]# xfs_quota -x -c 'report -h' /test
User quota on /test (/dev/xvdc1)
Blocks
User ID Used Soft Hard Warn/Grace
---------- ---------------------------------
root         4K     0         0    00     [------]

We can set either soft and hard inode count limits(isoft, ihard) or soft and hard block limits(bsoft, bhard).

Inorder to set block soft limit for user 'bnp', I issue the following command:

[root@li1014-63 ~]# xfs_quota -xc 'limit bsoft=500m bnp' /test

Verify the newly imposed limits:

[root@li1014-63 ~]# xfs_quota -xc 'report' /test
User quota on /test (/dev/xvdc1)
Blocks
User ID            Used          Soft         Hard          Warn/Grace
---------- --------------------------------------------------
root                   4                        0         0                00 [--------]
bnp                   0            512000          0                00 [--------]

By default, the limits are set for users. If they are to be set for groups or projects then use the options '-g' and '-p' respectively.

Similarly, use gquota and pquota while mounting XFS to enable group and project quotas.

#mount -o gquota

#mount /dev/device -o pquota /mount/point

3) Filesystem expansion

One good feature of XFS is that it can be grown even when it is mounted.  For this, there should be enough space in the underlying device.  Using 'fdisk',  delete the existing partition and re-create it with the required size. We can then use 'xfs_growfs' command to grow the filesystem.

#xfs_growfs -D size

                                    OR

#xfs_growfs -d

Here '-D' option is used to increase the filesystem size to the specified size, where as '-d'  increases the size to the maximum size supported by the underlying device.  When '-D' option is used, size needs to be specified in terms of the number of blocks. To know the current size in terms of blocks, we can use the 'xfs_info' command.

[root@li1014-63 ~]# xfs_info /test
meta-data=/dev/xvdc1 isize=256 agcount=4, agsize=235008 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=940032, 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=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

Below is a sample output showing the usage of '-d' option.

[root@li1014-63 ~]# xfs_growfs -d /test
meta-data=/dev/xvdc1 isize=256 agcount=4, agsize=51200 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=204800, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=1605, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 204800 to 262144

Please note that the size of the XFS filesystem can not be reduced.

4) Filesystem repair

In order to fix issues, if any, with the XFS filesystem, use 'xfs_repair' command.  It is a very efficient tool which can repair even large filesystems having many inodes.  The mounted XFS partition/volume has to be first unmounted before running the utility.

#xfs_repair  <device>

Here is an example output of running xfs_repair on a clean system:

root@li1014-63 ~]# xfs_repair /dev/xvdc1

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
- agno = 5
- 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
- agno = 5
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

Please note that this tool does not run at boot time even if the filesystem partition was not cleanly unmounted.

5) Filesystem suspension

'xfs_freeze' utility is available in XFS to suspend (freeze) and resume I/O to the filesystem.

#xfs_freeze -f

Any attempts to access the filesystem will hang the command line untill it is resumed.

[root@li1014-63 ~]# xfs_freeze -f /test

You can unfreeze it using the '-u' option.

#xfs_freeze -u <mount-point>

[root@li1014-63 ~]# xfs_freeze -u /test

6) Backup and Restore

Taking a backup of the filesystem data and restoring it can be done using two utilities, namely 'xfsdump' and 'xfsrestore'.  These are not part of xfsprogs and need to be installed separately using "yum install xfsdump".

xfsdump supports incremental backups and it uses dump levels for it.  Dump levels help in determining the base level to which a particular dump belong to.  The option '-l' is used for specifying dump levels (0-9).  Specifying 0 with '-l' has the effect of performing a full backup on the entire filesystem.

#xfsdump-l -f

Here the dump destination can be a regular file or a tape drive.  A sample output of taking a full backup of the filesystem:

[root@li1014-63 ~]# xfsdump -l 0 -f /dev/xvdc1 /backup
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.4 (dump format 3.0) - type ^C for status and control

============================= dump label dialog ==============================

please enter label for this dump session (timeout in 300 sec)
-> FullBkup
session label entered: "FullBkup"

--------------------------------- end dialog ---------------------------------

xfsdump: level 0 dump of li1014-63:/backup
xfsdump: dump date: Wed Jun 17 05:50:00 2015
xfsdump: session id: bce65c00-cf52-4a79-902a-f9810f1cb78f
xfsdump: session label: "FullBkup"
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

============================= media label dialog =============================

please enter label for media in drive 0 (timeout in 300 sec)
-> Bkup1
media label entered: "Bkup1"

--------------------------------- end dialog ---------------------------------

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: 21 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /dev/xvdc1 OK (success)
xfsdump: Dump Status: SUCCESS

Incremental backup will take backup of files that have changed since the last level 0 dump.

On the other hand, xfsrestore as the name suggests will restore the filesystem from the dumps produced by xfsdump.  In order to restore the data, we need to pass the session ID to the xfsrestore command.  This session id can be obtained using the '-I' option

#xfsrestore -I

[root@li1014-63 ~]# xfsrestore -I
file system 0:
fs id: 2e3d5f7c-1fde-4c2b-8a71-944e96d3c3a8
session 0:
mount point: li1014-63:/backup
device: li1014-63:/dev/xvdc2
time: Wed Jun 17 05:50:00 2015
session label: "FullBkup"
session id: bce65c00-cf52-4a79-902a-f9810f1cb78f
level: 0
resumed: NO
subtree: NO
streams: 1
stream 0:
pathname: /dev/xvdc1
start: ino 0 offset 0
end: ino 1 offset 0
interrupted: NO
media files: 1
media file 0:
mfile index: 0
mfile type: data
mfile size: 21016
mfile start: ino 0 offset 0
mfile end: ino 1 offset 0
media label: "Bkup1"
media id: ed00b8a7-42fd-4fa3-80a4-31d3a42f03e6
xfsrestore: Restore Status: SUCCESS

Now use the session ID and restore.

root@li1014-63 ~]# xfsrestore -f /dev/xvdc1 -S bce65c00-cf52-4a79-902a-f9810f1cb78f /backup
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.4 (dump format 3.0) - type ^C for status and control
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: examining media file 0
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 /dev/xvdc1 OK (success)
xfsrestore: Restore Status: SUCCESS

Use the '-r' option to restore the filesystem from an incremental backup.

#xfsrestore -f   -S -r

It is also possible to add, delete or extract files from a dump by using the xfsrestore interactively (-i)

#xfsrestore -f -i

A sample output showing the usage of interactive restore:

[root@li1014-63 ~]# xfsrestore -f /dev/xvdc1 -i
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: li1014-63
xfsrestore: mount point: /backup
xfsrestore: volume: /dev/xvdc2
xfsrestore: session time: Wed Jun 17 05:50:00 2015
xfsrestore: level: 0
xfsrestore: session label: "FullBkup"
xfsrestore: media label: "Bkup1"
xfsrestore: file system id: 2e3d5f7c-1fde-4c2b-8a71-944e96d3c3a8
xfsrestore: session id: bce65c00-cf52-4a79-902a-f9810f1cb78f
xfsrestore: media id: ed00b8a7-42fd-4fa3-80a4-31d3a42f03e6
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

========================== subtree selection dialog ==========================

the following commands are available:
pwd
ls [ <path> ]
cd [ <path> ]
add [ <path> ]
delete [ <path> ]
extract
quit
help

-> extract

--------------------------------- end dialog ---------------------------------

xfsrestore: restore complete: 8 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore: stream 0 /dev/xvdc1 OK (success)
xfsrestore: Restore Status: SUCCESS

Few more utilities

xfs_fsr

Defragments mounted XFS filesystem.  It is possible to defragment at the filesystem level or even at an individual file level

[root@li1014-63 backup]# xfs_fsr /test
/test start inode=0

Here /test is the mount point where the XFS filesystem is mounted.

Defragmenting specific file:

[root@li1014-63 /]# xfs_fsr /test/abc

xfs_bmp

Prints the disk block map used by files in the filesystem.

[root@li1014-63 /]# xfs_bmap /test/abc
/test/abc:
0: [0..7]: 88..95

xfs_info

Prints the XFS filesystem information

[root@li1014-63 /]# xfs_info /test
meta-data=/dev/xvdc1 isize=256 agcount=6, agsize=51200 blks
= sectsz=4096 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=1605, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

xfs_copy

Copies the content of an entire XFS filesystem to the target

xfs_db

Debugs an XFS filesystem

Conclusion

XFS is useful where we need to deal with large amount of data.  Its performance is good for heavy workloads. The fact that it has been deployed in Fedora 22 server as the default filesystem proves its maturity and performance.

The post Create / Mount / Manage XFS Filesystem on Fedora 22 appeared first on LinOxide.


Viewing all articles
Browse latest Browse all 1287

Trending Articles