Chapter 8. The XFS File System
XFS is a highly scalable, high-performance file system which was originally designed at Silicon Graphics, Inc. It was created to support extremely large filesystems (up to 16 exabytes), files (8 exabytes) and directory structures (tens of millions of entries).
-
Main Features
-
XFS supports metadata journaling, which facilitates quicker crash recovery. The XFS file system can also be defragmented and enlarged while mounted and active. In addition, Red Hat Enterprise Linux 6 supports backup and restore utilities specific to XFS.
Allocation Features
-
XFS features the following allocation schemes:
-
Extent-based allocation
-
Stripe-aware allocation policies
-
Delayed allocation
-
Space pre-allocation
Delayed allocation and other performance optimizations affect XFS the same way that they do ext4. Namely, a program's writes to an XFS file system are not guaranteed to be on-disk unless the program issues anfsync()
call afterwards.For more information on the implications of delayed allocation on a file system, refer to Allocation Features in Chapter 6, The Ext4 File System. The workaround for ensuring writes to disk applies to XFS as well.
Other XFS Features
-
-
The XFS file system also supports the following:
-
Extended attributes (
-
This allows the system to associate several additional name/value pairs per file.
Quota journaling
-
This avoids the need for lengthy quota consistency checks after a crash.
Project/directory quotas
-
This allows quota restrictions over a directory tree.
Subsecond timestamps
-
This allows timestamps to go to the subsecond.
xattr
) -
8.1. Creating an XFS File System
To create an XFS file system, use the
mkfs.xfs /dev/device
command. In general, the default options are optimal for common use.
When using
mkfs.xfs
on a block device containing an existing file system, use the
-f
option to force an overwrite of that file system.
Example 8.1. mkfs.xfs
command output
Below is a sample output of the
mkfs.xfs
command:
meta-data=/dev/device isize=256 agcount=4, agsize=3277258 blks = sectsz=512 attr=2 data = bsize=4096 blocks=13109032, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 log =internal log bsize=4096 blocks=6400, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
Note
After an XFS file system is created, its size cannot be reduced. However, it can still be enlarged using the
xfs_growfs
command (refer to
Section 8.4, “Increasing the Size of an XFS File System”).
For striped block devices (for example, RAID5 arrays), the stripe geometry can be specified at the time of file system creation. Using proper stripe geometry greatly enhances the performance of an XFS filesystem.
When creating filesystems on LVM or MD volumes,
mkfs.xfs
chooses an optimal geometry. This may also be true on some hardware RAIDs that export geometry information to the operating system.
To specify stripe geometry, use the following
mkfs.xfs
sub-options:
-
su=value
-
Specifies a stripe unit or RAID chunk size. The
value
must be specified in bytes, with an optionalk
,m
, org
suffix.
sw=value
-
Specifies the number of data disks in a RAID device, or the number of stripe units in the stripe.
The following example specifies a chunk size of 64k on a RAID device containing 4 stripe units:
# mkfs.xfs -d su=64k,sw=4 /dev/device
For more information about creating XFS file systems, refer to
man mkfs.xfs
.
8.2. Mounting an XFS File System
An XFS file system can be mounted with no extra options, for example:
# mount /dev/device /mount/point
XFS also supports several mount options to influence behavior.
XFS allocates inodes to reflect their on-disk location by default. However, because some 32-bit userspace applications are not compatible with inode numbers greater than 2
32, XFS will allocate all inodes in disk locations which result in 32-bit inode numbers. This can lead to decreased performance on very large filesystems (that is, larger than 2 terabytes), because inodes are skewed to the beginning of the block device, while data is skewed towards the end.
To address this, use the
inode64
mount option. This option configures XFS to allocate inodes and data across the entire file system, which can improve performance:
# mount -o inode64 /dev/device /mount/point
Write Barriers
By default, XFS uses write barriers to ensure file system integrity even when power is lost to a device with write caches enabled. For devices without write caches, or with battery-backed write caches, disable the barriers by using the
nobarrier
option:
# mount -o nobarrier /dev/device /mount/point
For more information about write barriers, refer to
Chapter 22, Write Barriers.
8.3. XFS Quota Management
The XFS quota subsystem manages limits on disk space (blocks) and file (inode) usage. XFS quotas control or report on usage of these items on a user, group, or directory or project level. Also, note that while user, group, and directory or project quotas are enabled independently, group and project quotas are mutually exclusive.
When managing on a per-directory or per-project basis, XFS manages the disk usage of directory hierarchies associated with a specific project. In doing so, XFS recognizes cross-organizational "group" boundaries between projects. This provides a level of control that is broader than what is available when managing quotas for users or groups.
XFS quotas are enabled at mount time, with specific mount options. Each mount option can also be specified as
noenforce
; this will allow usage reporting without enforcing any limits. Valid quota mount options are:
-
uquota
/uqnoenforce
- User quotas -
gquota
/gqnoenforce
- Group quotas -
pquota
/pqnoenforce
- Project quota
Once quotas are enabled, the
xfs_quota
tool can be used to set limits and report on disk usage. By default,
xfs_quota
is run interactively, and in
basic mode. Basic mode sub-commands simply report usage, and are available to all users. Basic
xfs_quota
sub-commands include:
-
quota username/userID
-
Show usage and limits for the given
username
or numericuserID
df
-
Shows free and used counts for blocks and inodes.
In contrast,
xfs_quota
also has an
expert mode. The sub-commands of this mode allow actual configuration of limits, and are available only to users with elevated privileges. To use expert mode sub-commands interactively, run
xfs_quota -x
. Expert mode sub-commands include:
-
report /path
-
Reports quota information for a specific file system.
limit
-
Modify quota limits.
For a complete list of sub-commands for either basic or expert mode, use the sub-command
help
.
All sub-commands can also be run directly from a command line using the
-c
option, with
-x
for expert sub-commands.
Example 8.2. Display a sample quota report
For example, to display a sample quota report for
/home
(on
/dev/blockdevice
), use the command
xfs_quota -cx 'report -h' /home
. This will display output similar to the following:
User quota on /home (/dev/blockdevice) Blocks User ID Used Soft Hard Warn/Grace ---------- --------------------------------- root 0 0 0 00 [------] testuser 103.4G 0 0 00 [------] ...
To set a soft and hard inode count limit of 500 and 700 respectively for user
john
(whose home directory is
/home/john
), use the following command:
# xfs_quota -x -c 'limit isoft=500 ihard=700 /home/john'
By default, the
limit
sub-command recognizes targets as users. When configuring the limits for a group, use the
-g
option (as in the previous example). Similarly, use
-p
for projects.
Soft and hard block limits can also be configured using
bsoft
or
bhard
instead of
isoft
or
ihard
.
Example 8.3. Set a soft and hard block limit
For example, to set a soft and hard block limit of 1000m and 1200m, respectively, to group
accounting
on the
/target/path
file system, use the following command:
# xfs_quota -x -c 'limit -g bsoft=1000m bhard=1200m accounting' /target/path
Important
While real-time blocks (
rtbhard
/
rtbsoft
) are described in
man xfs_quota
as valid units when setting quotas, the real-time sub-volume is not enabled in this release. As such, the
rtbhard
and
rtbsoft
options are not applicable.
Setting Project Limits
Before configuring limits for project-controlled directories, add them first to
/etc/projects
. Project names can be added to
/etc/projectid
to map project IDs to project names. Once a project is added to
/etc/projects
, initialize its project directory using the following command:
# xfs_quota -c 'project -s projectname'
Quotas for projects with initialized directories can then be configured, with:
# xfs_quota -x -c 'limit -p bsoft=1000m bhard=1200m projectname'
Generic quota configuration tools (
quota
,
repquota
, and
edquota
for example) may also be used to manipulate XFS quotas. However, these tools cannot be used with XFS project quotas.
For more information about setting XFS quotas, refer to
man xfs_quota
.
8.4. Increasing the Size of an XFS File System
An XFS file system may be grown while mounted using the
xfs_growfs
command:
# xfs_growfs /mount/point -D size
The
-D size
option grows the file system to the specified
size
(expressed in file system blocks). Without the
-D size
option,
xfs_growfs
will grow the file system to the maximum size supported by the device.
Before growing an XFS file system with
-D size
, ensure that the underlying block device is of an appropriate size to hold the file system later. Use the appropriate resizing methods for the affected block device.
Note
While XFS file systems can be grown while mounted, their size cannot be reduced at all.
For more information about growing a file system, refer to
man xfs_growfs
.
8.5. Repairing an XFS File System
To repair an XFS file system, use
xfs_repair
:
# xfs_repair /dev/device
The
xfs_repair
utility is highly scalable and is designed to repair even very large file systems with many inodes efficiently. Unlike other Linux file systems,
xfs_repair
does not run at boot time, even when an XFS file system was not cleanly unmounted. In the event of an unclean unmount,
xfs_repair
simply replays the log at mount time, ensuring a consistent file system.
Warning
The
xfs_repair
utility cannot repair an XFS file system with a dirty log. To clear the log, mount and unmount the XFS file system. If the log is corrupt and cannot be replayed, use the
-L
option ("force log zeroing") to clear the log, that is,
xfs_repair -L /dev/device
. Be aware that this may result in further corruption or data loss.
For more information about repairing an XFS file system, refer to
man xfs_repair
.
8.6. Suspending an XFS File System
To suspend or resume write activity to a file system, use
xfs_freeze
. Suspending write activity allows hardware-based device snapshots to be used to capture the file system in a consistent state.
Note
The
xfs_freeze
utility is provided by the
xfsprogs
package, which is only available on x86_64.
To suspend (that is, freeze) an XFS file system, use:
# xfs_freeze -f /mount/point
To unfreeze an XFS file system, use:
# xfs_freeze -u /mount/point
When taking an LVM snapshot, it is not necessary to use
xfs_freeze
to suspend the file system first. Rather, the LVM management tools will automatically suspend the XFS file system before taking the snapshot.
Note
The
xfs_freeze
utility can also be used to freeze or unfreeze an ext3, ext4, GFS2, XFS, and BTRFS, file system. The syntax for doing so is the same.
For more information about freezing and unfreezing an XFS file system, refer to
man xfs_freeze
.
8.7. Backup and Restoration of XFS File Systems
XFS file system backup and restoration involves two utilities:
xfsdump
and
xfsrestore
.
To backup or dump an XFS file system, use the
xfsdump
utility. Red Hat Enterprise Linux 6 supports backups to tape drives or regular file images, and also allows multiple dumps to be written to the same tape. The
xfsdump
utility also allows a dump to span multiple tapes, although only one dump can be written to a regular file. In addition,
xfsdump
supports incremental backups, and can exclude files from a backup using size, subtree, or inode flags to filter them.
In order to support incremental backups,
xfsdump
uses
dump levels to determine a base dump to which a specific dump is relative. The
-l
option specifies a dump level (
0-9). To perform a full backup, perform a
level 0 dump on the file system (that is,
/path/to/filesystem
), as in:
# xfsdump -l 0 -f /dev/device /path/to/filesystem
Note
The
-f
option specifies a destination for a backup. For example, the
/dev/st0
destination is normally used for tape drives. An
xfsdump
destination can be a tape drive, regular file, or remote tape device.
In contrast, an incremental backup will only dump files that changed since the last
level 0 dump. A
level 1 dump is the first incremental dump after a full dump; the next incremental dump would be
level 2, and so on, to a maximum of
level 9. So, to perform a
level 1 dump to a tape drive:
# xfsdump -l 1 -f /dev/st0 /path/to/filesystem
Conversely, the
xfsrestore
utility restores file systems from dumps produced by
xfsdump
. The
xfsrestore
utility has two modes: a default
simple mode, and a
cumulative mode. Specific dumps are identified by
session ID or
session label. As such, restoring a dump requires its corresponding session ID or label. To display the session ID and labels of all dumps (both full and incremental), use the
-I
option:
# xfsrestore -I
This will provide output similar to the following:
Example 8.4. Session ID and labels of all dumps
file system 0: fs id: 45e9af35-efd2-4244-87bc-4762e476cbab session 0: mount point: bear-05:/mnt/test device: bear-05:/dev/sdb2 time: Fri Feb 26 16:55:21 2010 session label: "my_dump_session_label" session id: b74a3586-e52e-4a4a-8775-c3334fa8ea2c level: 0 resumed: NO subtree: NO streams: 1 stream 0: pathname: /mnt/test2/backup 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: "my_dump_media_label" media id: 4a518062-2a8f-4f17-81fd-bb1eb2e3cb4f xfsrestore: Restore Status: SUCCESS
Simple Mode for xfsrestore
The
simple mode allows users to restore an entire file system from a
level 0 dump. After identifying a
level 0dump's session ID (that is,
session-ID
), restore it fully to
/path/to/destination
using:
# xfsrestore -f /dev/st0 -S session-ID /path/to/destination
Note
The
-f
option specifies the location of the dump, while the
-S
or
-L
option specifies which specific dump to restore. The
-S
option is used to specify a session ID, while the
-L
option is used for session labels. The
-I
option displays both session labels and IDs for each dump.
Cumulative Mode for xfsrestore
The
cumulative mode of
xfsrestore
allows file system restoration from a specific incremental backup, for example,
level 1 to
level 9. To restore a file system from an incremental backup, simply add the
-r
option:
# xfsrestore -f /dev/st0 -S session-ID -r /path/to/destination
Interactive Operation
The
xfsrestore
utility also allows specific files from a dump to be extracted, added, or deleted. To use
xfsrestore
interactively, use the
-i
option, as in:
xfsrestore -f /dev/st0 -i
The interactive dialogue will begin after
xfsrestore
finishes reading the specified device. Available commands in this dialogue include
cd
,
ls
,
add
,
delete
, and
extract
; for a complete list of commands, use
help
.
For more information about dumping and restoring XFS file systems, refer to
man xfsdump
and
man xfsrestore
.
8.8. Other XFS File System Utilities
Red Hat Enterprise Linux 6 also features other utilities for managing XFS file systems:
-
xfs_fsr
-
Used to defragment mounted XFS file systems. When invoked with no arguments,
xfs_fsr
defragments all regular files in all mounted XFS file systems. This utility also allows users to suspend a defragmentation at a specified time and resume from where it left off later.In addition,xfs_fsr
also allows the defragmentation of only one file, as inxfs_fsr /path/to/file
. Red Hat advises against periodically defragmenting an entire file system, as this is normally not warranted.
xfs_bmap
-
Prints the map of disk blocks used by files in an XFS filesystem. This map lists each extent used by a specified file, as well as regions in the file with no corresponding blocks (that is, holes).
xfs_info
-
Prints XFS file system information.
xfs_admin
-
Changes the parameters of an XFS file system. The
xfs_admin
utility can only modify parameters of unmounted devices or file systems.
xfs_copy
-
Copies the contents of an entire XFS file system to one or more targets in parallel.
The following utilities are also useful in debugging and analyzing XFS file systems:
-
xfs_metadump
-
Copies XFS file system metadata to a file. The
xfs_metadump
utility should only be used to copy unmounted, read-only, or frozen/suspended file systems; otherwise, generated dumps could be corrupted or inconsistent.
xfs_mdrestore
-
Restores an XFS metadump image (generated using
xfs_metadump
) to a file system image.
xfs_db
-
Debugs an XFS file system.
For more information about these utilities, refer to their respective
man
pages.