April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

CENTOS , FEDORA , RHEL 7 XFS FILE SYSTEM

XFS File System

What is XFS?

XFS is a highly scalable, high-performance file journalling file system which was originally designed at Silicon Graphics, Inc in 1993. Originally XFS was used on Silicon Graphics Inc’s own operating system Irix, however, it was later ported to the Linux kernel in 2001. Today XFS is supported by most Linux distributions and has now become the default filesystem on RHEL (Red Hat Enterprise Linux), Oracle Linux 7, CentOS 7 and many other distributions. Originally XFS was created to support extremely large filesystems with sizes of up to 16 exabytes and file sizes of up to 8 exabytes.

XFS supports metadata journalling allowing for quicker recovery after a system crash. The XFS file system can also be de-fragmented and enlarged while mounted and active. The XFS file system can not be reduced in size !

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 a an XFS file system are not guaranteed to be on-disk unless the program issues an fsync() call afterwards.

The XFS file system also supports the following:

Extended attributes (xattr), which allows the system to associate several additional name/value pairs per file.
Quota journalling, which avoids the need for lengthy quota consistency checks after a crash.
Project/directory quotas, allowing quota restrictions over a directory tree.
Subsecond timestamps

Creating a XFS File System

To create a XFS file system, you can use the command mkfs.xfs /dev/device.

When using mkfs.xfs on a block device containing an existing file system, you should use the -f option to force an overwrite of that file system.

Below is an example of the mkfs.xfs command being issued on a CentOS 7 server. Once the command has run successfully,

we issued the mount command. In this example, we are using a mount point of “xfs_test”.

This was created by issuing the command “mkdir /xfs_test”. (see output below)

fdisk -l /dev/sdb

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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
Disk label type: dos
Disk identifier: 0xf478ffab

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496   83  Linux

Disk /dev/mapper/centos-swap: 4294 MB, 4294967296 bytes, 8388608 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

Disk /dev/mapper/centos-root: 38.1 GB, 38126223360 bytes, 74465280 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

[root@centos7server ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=1310656 blks
=                       sectsz=512   attr=2, projid32bit=1
=                       crc=0
data     =                       bsize=4096   blocks=5242624, 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

mkdir /xfs_test

[root@centos7server ~]# mkdir /xfs_test
[root@centos7server ~]# mount /dev/sdb1 /xfs_test
[root@centos7server ~]# df -TH
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        39G  1.1G   38G   3% /
devtmpfs                devtmpfs  3.0G     0  3.0G   0% /dev
tmpfs                   tmpfs     3.0G     0  3.0G   0% /dev/shm
tmpfs                   tmpfs     3.0G  9.0M  3.0G   1% /run
tmpfs                   tmpfs     3.0G     0  3.0G   0% /sys/fs/cgroup
/dev/sda1               xfs       521M  147M  374M  29% /boot
/dev/sdb1               xfs        22G   34M   22G   1% /xfs_test

Using LVM (Logical Volume Manager) to add space to an XFS file system

Generally to increase space you would use LVM (Logical Volume Manager. In the following example we will create a partition with a type of “8e” which denotes LVM. We will create a PV with the pvcreate command, create a VolumeGroup and define a LV. Next we will generate an XFS filesystem on the Logical Volume. For more information regarding LVM, follow the LVM link: Introduction to LVM

An overview of the basic process involved can be seen below:

Create a Partition using fdisk

In this example, we are going to create a partition using the disk partitioning tool “fdisk”. The commands used to create the partition can be seen in the output below:

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

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n
Partition type:
p   primary (0 primary, 0 extended, 4 free)
e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition ‘Linux’ to ‘Linux LVM’

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos7server ~]#

Create Logical Volume Manager Components: PV, VG and LV

Our next step is to create a Physical Volume comprising of the /dev/sdb1 partition.
Next we then create a Volume Group called “vg01” and finally we create a Logical Volume that will use all available space within our Volume Group.
The commands issued can be seen in the output below:

[root@centos7server ~]# pvcreate /dev/sdb1
WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n] y
Wiping xfs signature on /dev/sdb1.
Physical volume “/dev/sdb1” successfully created
[root@centos7server ~]# vgcreate vg01 /dev/sdb1
Volume group “vg01” successfully created
[root@centos7server ~]# lvcreate -n lv01 -l 100%VG vg01
Logical volume “lv01” created
[root@centos7server ~]#
[root@centos7server ~]# pvs
PV         VG     Fmt  Attr PSize  PFree
/dev/sda2  centos lvm2 a–  39.51g    0
/dev/sdb1  vg01   lvm2 a–  20.00g    0
[root@centos7server ~]# vgs
VG     #PV #LV #SN Attr   VSize  VFree
centos   1   2   0 wz–n- 39.51g    0
vg01     1   1   0 wz–n- 20.00g    0
[root@centos7server ~]# lvs
LV   VG     Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
root centos -wi-ao—- 35.51g
swap centos -wi-ao—-  4.00g
lv01 vg01   -wi-a—– 20.00g
[root@centos7server ~]#

[root@centos7server ~]# mkfs.xfs /dev/vg01/lv01
meta-data=/dev/vg01/lv01         isize=256    agcount=4, agsize=1310464 blks
=                       sectsz=512   attr=2, projid32bit=1
=                       crc=0
data     =                       bsize=4096   blocks=5241856, 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
[root@centos7server ~]#

[root@centos7server ~]# mount /dev/vg01/lv01 /xfs_test
[root@centos7server ~]# df -TH
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        39G  1.1G   38G   3% /
devtmpfs                devtmpfs  3.0G     0  3.0G   0% /dev
tmpfs                   tmpfs     3.0G     0  3.0G   0% /dev/shm
tmpfs                   tmpfs     3.0G  9.0M  3.0G   1% /run
tmpfs                   tmpfs     3.0G     0  3.0G   0% /sys/fs/cgroup
/dev/sda1               xfs       521M  147M  374M  29% /boot
/dev/mapper/vg01-lv01   xfs        22G   34M   22G   1% /xfs_test

Attaching a new Disk for /dev/sdc

Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 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

[root@centos7server ~]# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x3ea192fa.

Command (m for help): n
Partition type:
p   primary (0 primary, 0 extended, 4 free)
e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos7server ~]# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help):
Command (m for help):
Command (m for help): p

Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 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
Disk label type: dos
Disk identifier: 0x3ea192fa

Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    41943039    20970496   83  Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition ‘Linux’ to ‘Linux LVM’

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Create a new Physical Volume

Next we create a new PV (Physical Volume using the device “/dev/sdc1”.

[root@centos7server ~]# pvcreate /dev/sdc1
Physical volume “/dev/sdc1” successfully created

Add the new Physical Volume to an existing Volume Group

Here we are adding our new space to the existing Volume Group “vg01”.
This extra space will be then available to our Logical Volume. The command to add the new partition to our Volume Group is “vgextend”.

Check PV and VG

If we now issue the “pvs” and vgs” commands again, we will now see the new additions:

[root@centos7server ~]# pvs
PV         VG     Fmt  Attr PSize  PFree
/dev/sda2  centos lvm2 a–  39.51g     0
/dev/sdb1  vg01   lvm2 a–  20.00g     0
/dev/sdc1  vg01   lvm2 a–  20.00g 20.00g
[root@centos7server ~]# vgs
VG     #PV #LV #SN Attr   VSize  VFree
centos   1   2   0 wz–n- 39.51g     0
vg01     2   1   0 wz–n- 39.99g 20.00g

From the above “pvs” command we can see that the new PV has been added with 508MB of space. The “vgs” command is now indicating that there are now two Physical Volumes associated with the Volume Group “vg01”.

Extend a Logical Volume

To extend the Logical Volume, we are going to use the “lvextend command. In the example below we are extending the Logical Volume by 500MB. The file system will be automatically resized because we are using the “-r” option.

[root@centos7server ~]# vgextend vg01 /dev/sdc1
Volume group “vg01” successfully extended

[root@centos7server ~]# lvextend /dev/vg01/lv01 -L +500M -r
Phase 1 – find and verify superblock…
Phase 2 – using internal log
– scan filesystem freespace and inode maps…
– found root inode chunk
Phase 3 – for each AG…
– scan (but don’t clear) agi unlinked lists…
– process known inodes and perform inode discovery…
– agno = 0
– agno = 1
– agno = 2
– agno = 3
– 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
No modify flag set, skipping phase 5
Phase 6 – check inode connectivity…
– traversing filesystem …
– traversal finished …
– moving disconnected inodes to lost+found …
Phase 7 – verify link counts…
No modify flag set, skipping filesystem flush and exiting.
Extending logical volume lv01 to 20.48 GiB
Logical volume lv01 successfully resized
meta-data=/dev/mapper/vg01-lv01  isize=256    agcount=4, agsize=1310464 blks
=                       sectsz=512   attr=2, projid32bit=1
=                       crc=0
data     =                       bsize=4096   blocks=5241856, 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 5241856 to 5369856

[root@centos7server ~]# lvextend /dev/vg01/lv01 -L +1000M -r
Extending logical volume lv01 to 21.95 GiB
Logical volume lv01 successfully resized
meta-data=/dev/mapper/vg01-lv01  isize=256    agcount=5, agsize=1310464 blks
=                       sectsz=512   attr=2, projid32bit=1
=                       crc=0
data     =                       bsize=4096   blocks=5497856, 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 5497856 to 5753856
[root@centos7server ~]# df -TH
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        39G  1.1G   38G   3% /
devtmpfs                devtmpfs  3.0G     0  3.0G   0% /dev
tmpfs                   tmpfs     3.0G     0  3.0G   0% /dev/shm
tmpfs                   tmpfs     3.0G  9.0M  3.0G   1% /run
tmpfs                   tmpfs     3.0G     0  3.0G   0% /sys/fs/cgroup
/dev/sda1               xfs       521M  147M  374M  29% /boot
/dev/mapper/vg01-lv01   xfs        24G   34M   24G   1% /xfs_test

[root@centos7server ~]# lvextend /dev/vg01/lv01 -L +1000M -r
Phase 1 – find and verify superblock…
Phase 2 – using internal log
– scan filesystem freespace and inode maps…
sb_fdblocks 5367272, counted 5751272
– found root inode chunk
Phase 3 – for each AG…
– scan (but don’t 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
No modify flag set, skipping phase 5
Phase 6 – check inode connectivity…
– traversing filesystem …
– traversal finished …
– moving disconnected inodes to lost+found …
Phase 7 – verify link counts…
No modify flag set, skipping filesystem flush and exiting.
Filesystem check failed.

[root@centos7server ~]# xfs_growfs /dev/vg01/lv01
xfs_growfs: /dev/vg01/lv01 is not a mounted XFS filesystem
[root@centos7server ~]# df -TH
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        39G  1.1G   38G   3% /
devtmpfs                devtmpfs  3.0G     0  3.0G   0% /dev
tmpfs                   tmpfs     3.0G     0  3.0G   0% /dev/shm
tmpfs                   tmpfs     3.0G  9.1M  3.0G   1% /run
tmpfs                   tmpfs     3.0G     0  3.0G   0% /sys/fs/cgroup
/dev/sda1               xfs       521M  147M  374M  29% /boot
[root@centos7server ~]# mount /dev/vg01/lv01 /xfs_test/
[root@centos7server ~]#
[root@centos7server ~]# xfs_growfs /dev/vg01/lv01
meta-data=/dev/mapper/vg01-lv01  isize=256    agcount=5, agsize=1310464 blks
=                       sectsz=512   attr=2, projid32bit=1
=                       crc=0
data     =                       bsize=4096   blocks=5753856, 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

[root@centos7server ~]# df -TH
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        39G  1.1G   38G   3% /
devtmpfs                devtmpfs  3.0G     0  3.0G   0% /dev
tmpfs                   tmpfs     3.0G     0  3.0G   0% /dev/shm
tmpfs                   tmpfs     3.0G  9.1M  3.0G   1% /run
tmpfs                   tmpfs     3.0G     0  3.0G   0% /sys/fs/cgroup
/dev/sda1               xfs       521M  147M  374M  29% /boot
/dev/mapper/vg01-lv01   xfs        24G   34M   24G   1% /xfs_test

[root@centos7server ~]# lvextend /dev/vg01/lv01 -L +1000M -r
Extending logical volume lv01 to 22.93 GiB
Logical volume lv01 successfully resized
meta-data=/dev/mapper/vg01-lv01  isize=256    agcount=5, agsize=1310464 blks
=                       sectsz=512   attr=2, projid32bit=1
=                       crc=0
data     =                       bsize=4096   blocks=5753856, 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 5753856 to 6009856
[root@centos7server ~]# xfs_growfs /dev/vg01/lv01
meta-data=/dev/mapper/vg01-lv01  isize=256    agcount=5, agsize=1310464 blks
=                       sectsz=512   attr=2, projid32bit=1
=                       crc=0
data     =                       bsize=4096   blocks=6009856, 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
[root@centos7server ~]# df -TH
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        39G  1.1G   38G   3% /
devtmpfs                devtmpfs  3.0G     0  3.0G   0% /dev
tmpfs                   tmpfs     3.0G     0  3.0G   0% /dev/shm
tmpfs                   tmpfs     3.0G  9.1M  3.0G   1% /run
tmpfs                   tmpfs     3.0G     0  3.0G   0% /sys/fs/cgroup
/dev/sda1               xfs       521M  147M  374M  29% /boot
/dev/mapper/vg01-lv01   xfs        25G   34M   25G   1% /xfs_test

We can now see from the above output that we have 2.5GB of space now available to our xfs file system.

Important: You can not reduce a XFS filesystem, if you try you will get the following message:

[root@centos7server ~]# lvreduce /dev/vg01/lv01 -L -500M -r
fsadm: Xfs filesystem shrinking is unsupported
fsadm failed: 1
Filesystem resize failed.
[root@centos7server ~]#

Method 2 for extending a XFS File System using the utility xfs_growfs

The following method allows you to extend the file system by using the “xfs_growfs” command. The xfs_growfs command is used to increase the size of a mounted XFS file system only if there is space on the underlying devices to accommodate the change. The xfs_growfs command does not require LVM to extend the file system as per the previous example.

The mount point argument that is passed is the pathname to the directory where the filesystem is mounted. The xfs filesystem must be mounted first before it can be grown. The contents of the file system are undisturbed, and the added space is then made available for additional file storage.

In the following example I am using a CentOS 7 server running in VirtualBox. Initially the disk used “/dev/sdb” is set to a size of 500MB. Our next step is to then create a XFS file system by issuing the “mkfs.xfs” command. The resulting file system can be seen after issuing the “df -hT” command. (The -h option displays a human readable format in MB, GB etc.. and the -T option displays the type of file system (XFS in this example).

After the file system was initially created, I then increased the size of the underlying disk by using the following VirtualBox command:

VBoxManage modifyhd “/home/mohan/VirtualBox VMs/CentOS_7/CentOS7_XFS_Test1.vdi” –resize 2048

An outline of the steps involved for this example are below:

Create xfs file system on a 500MB Disk

Create the xfs file system using the “mkfs.xfs” command:

[root@centos07a /]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=32000 blks
=                       sectsz=512   attr=2, projid32bit=1
=                       crc=0
data     =                       bsize=4096   blocks=128000, imaxpct=25
=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
=                       sectsz=512   sunit=0 blks, lazy-count=1
real-time =none                   extsz=4096   blocks=0, rtextents=0

Mount File System

Next we need to mount the file system using the mount command (syntax: mount /dev/device /mount_point)

[root@centos07a /]# mount /dev/sdb1 xfs_test/

Display XFS File System information

We can use the “df” command again to look at the size of our mounted xfs file system:

[root@centos07a /]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       6.7G  1.1G  5.7G  16% /
devtmpfs                devtmpfs  492M     0  492M   0% /dev
tmpfs                   tmpfs     498M     0  498M   0% /dev/shm
tmpfs                   tmpfs     498M  6.6M  491M   2% /run
tmpfs                   tmpfs     498M     0  498M   0% /sys/fs/cgroup
/dev/sda1               xfs       497M  100M  398M  20% /boot
/dev/sdb1               xfs       497M   26M  472M   6% /xfs_test

We can now see that our file system is mounted at mount point /xfs_test. You may wish to add your disk/filesystem into “/etc/fstab” so that it will be automatically mounted at system reboot. To do this, simply add a line similar to the one below into the file “/etc/fstab”.

Example /etc/fstab entry

/dev/sdb1               /xfs_test               xfs     defaults        0 0

Shutdown Partition and Increase underlying Disk size

As we are using Oracle’s VirtualBox software, we need to shutdown the partition first to increase the under lying disk. The shutdown command “shutdown -h now” can be used to cleanly shutdown your partition. Unfortunately, VirtualBox only allows the disk to be increased when it is not in use. The following command will be issued from the host computer. The “host” computer is the computer that is running the VirtualBox software.

VirtualBox – Increase Disk Size

The following command is issued to the host computer.

$ VBoxManage modifyhd “/home/mohan/VirtualBox VMs/CentOS_7/CentOS7_XFS_Test1.vdi” –resize 2048
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%

The above command has now resized the virtual disk “CentOS7_XFS_Test1.vdi” to a size of 2GB. Notice the double quotes around the path name. Double quotes are needed as there are spaces within the path name name. If you are unsure of the name of the Virtualdisk that you created originally for your partition, you can “right click” on the name of your VM in the VirtualBox manager and select the option to “Show in file manager”. Here you will see a list of all the virtual disks that have been allocated to your server.

Restart Server and Delete Original Partition

Once we have increased the under lying disk space, we will need to restart our server. Next we are going to use fdisk to delete our original partition and then recreate it again with more space. The disk in the example is known as “/dev/sdb”.

Below are the steps taken using fdisk to accomplish the above task.

[root@centos07a /]# umount /xfs_test

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

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 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
Disk label type: dos
Disk identifier: 0x340b4c69

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     1026047      512000   83  Linux

Command (m for help): d
Selected partition 1
Partition 1 is deleted

Command (m for help): n
Partition type:
p   primary (0 primary, 0 extended, 4 free)
e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-4194303, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303):
Using default value 4194303
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Remount xfs File System

Before we can increase a xfs file system, it needs to be mounted first.

[root@centos07a /]# mount /dev/sdb1 /xfs_test

We can issue the “df” command again to display our file system information.

[root@centos07a /]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       6.7G  1.1G  5.7G  16% /
devtmpfs                devtmpfs  492M     0  492M   0% /dev
tmpfs                   tmpfs     498M     0  498M   0% /dev/shm
tmpfs                   tmpfs     498M  6.6M  491M   2% /run
tmpfs                   tmpfs     498M     0  498M   0% /sys/fs/cgroup
/dev/sda1               xfs       497M  100M  398M  20% /boot
/dev/sdb1               xfs       497M   26M  472M   6% /xfs_test

From the above we can see that the file system on “xfs_test” is still indicating its original size.

Issue xfs_growfs against mount point

Next we are going to issue the “xfs_growfs” command:

[root@centos07a /]# xfs_growfs xfs_test/
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=32000 blks
=                       sectsz=512   attr=2, projid32bit=1
=                       crc=0
data     =                       bsize=4096   blocks=128000, imaxpct=25
=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=853, version=2
=                       sectsz=512   sunit=0 blks, lazy-count=1
real-time =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 128000 to 524032

The important information to look for when you issue this command can be found within the last line of the output. You are looking for an increase in size relating to data blocks. We can now issue the “df” command again to verify that the xfs_growfs command was successful:

[root@centos07a /]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       6.7G  1.1G  5.7G  16% /
devtmpfs                devtmpfs  492M     0  492M   0% /dev
tmpfs                   tmpfs     498M     0  498M   0% /dev/shm
tmpfs                   tmpfs     498M  6.6M  491M   2% /run
tmpfs                   tmpfs     498M     0  498M   0% /sys/fs/cgroup
/dev/sda1               xfs       497M  100M  398M  20% /boot
/dev/sdb1               xfs       2.0G   26M  2.0G   2% /xfs_test

This time we can see that the file system is now 2GB in size.

Overview of Options that can be passed to the xfs_growfs utility

SYNOPSIS
xfs_growfs  [  -dilnrx  ] [ -D size ] [ -e rtextsize ] [ -L size ] [ -m
maxpct ] [ -t mtab ] [ -R size ] mount-point
xfs_growfs -V

xfs_info [ -t mtab ] mount-point
xfs_info -V

Options that can be passed to the xfs_growfs utility

d | -D size

The “-d or -D” option is used to specify that the data section of the filesystem should be grown. If the “-D” size option is passed, then the data section is grown to the specified size. The “-d” option specifies that the data section is grown to the largest possible size. The size is specified in file system blocks.

-e

Allows the real-time extent size to be specified. This can also be specified with the mkfs.xfs command with the specified option of “-r extsize=nnnn”.

-l | -L size

Specifies that the log section of the filesystem should be grown, shrunk, or moved. If the -L size option is given, the log section is changed to be that size, if possible. The size is expressed in file system blocks. The size of an internal log must be smaller than the size of an allocation group (this value is printed at mkfs time). If neither -i nor -x is given with -l, the log continues to be internal or external as it was before. [NOTE: These options are not implemented]

-m

Specify a new value for the maximum percentage of space in the file system that can be allocated as inodes. In mkfs.xfs(8) this is specified with -i maxpct=nn.

-n

Specifies that no change to the filesystem is to be made. The file system geometry is printed, and argument checking is performed, but no growth occurs.

-r | -R size

Specifies that the real time section of the file system should be grown. If the -R size option is given, the real time section is grown to that size, otherwise the real time section is grown to the largest size possible with the -r option. The size is expressed in filesystem blocks. The filesystem does not need to have contained a real time section before the xfs_growfs operation.

-t

Specifies an alternate mount table file.

-V

Prints the version number and exits. The mount point argument is not required with -V.

Summary of resizing a XFS file system

Although both of the methods used allowed you to increase the size of the XFS file system. Neither of the methods allowed us to reduce the size. The most common method of resizing a file system is to use the LVM (Logical Volume Manager) approach. LVM gives you the advantage of being able to add additional disk easily to an existing Volume Group and then use the lvextend command to increase the size of your filesystem.

Overview of other xfs Utilities

Repairing a XFS File System with xfs_repair

Basic Syntax:

xfs_repair /dev/device

The xfs_repair utility is designed to repair file systems whether small or large very quickly. Unlike other file system repair tools, xfs_repair does not run at system boot time. xfs_repair replays its logs at mount time to ensure a consistent file system. If xfs_repair encounters a dirty log, then it will not be able to repair the file system. To rectify the file system, you will need to first clear the relevant log, mount and then unmount the xfs file system. You may use the option “-L” to force log zeroing if the log file is corrupt and can not be replayed successfully. The command to issue for zeroing the log is as follows:

xfs_repair -L /dev/device

For full details regarding the xfs_repair utility, please consult the relevant man pages: man xfs_repair

XFS Quota Management – xfs_quota

xfs_quota gives the administrator the ability to manage limits on disk space. XFS quotas can control or report usage on users, groups or directory project level. XFS quotas are enabled at mount time. You may specify the “noenforce” option which allows reporting of usage, however, it does not enforce any limits. For full details of XFS quotas see the relevant man page: man xfs_quota

Suspending a XFS File System with xfs_freeze

The command to suspend access or resume write activity to a xfs file system is “xfs_freeze”. Generally this option is used for suspending write activity thus allowing hardware based device snapshots to be used to capture the file system in a consistent state.

The xfs_freeze utility is provided by the package “xfsprogs”, note, this is only available to x86_64 architecture.

To freeze a XFS file system the basic syntax is:

xfs_freeze -f /mount/point

The -f flag requests that the specified XFS filesystem should be set to a state of frozen, immediately stopping any modifications from being made. When this option is selected, all ongoing transactions in the file system are allowed to complete. Any new write system calls are halted.

To unfreeze a XFS file system the basic syntax is:

xfs_freeze -u /mount/point

The -u flag is used to unfreeze the file system and allow operations to continue again. Any file system modifications that were blocked by the freeze option are unblocked and allowed to complete.

If you are taking a LVM snapshot, then it is not necessary to run the “xfs_freeze” utility as the LVM utility will automatically suspend the relevant xfs file system.

You can also use the “xfs_freeze” utility to freeze or unfreeze an ext3, ext4 and btrfs, file system.

xfs_copy

Copy the contents of a XFS file system. xfs_copy should only be used to copy unmounted file systems, read-only mounted file systems, or file systems that have been frozen with the xfs_freeze utility. The basic syntax of the utility is as follows:

xfs_copy [ -bd ] [ -L log ] source target1 [ target2 … ]

OPTIONS
-d     Create a duplicate (true clone) filesystem. This should be done
only if the new filesystem will be used as a replacement for the
original filesystem (such as in the case of disk replacement).

-b     The buffered option can be  used  to ensure direct IO is not
attempted to any of the target files. This is  useful  when  the
filesystem holding the target file does not support direct IO.

-L log Specifies  the  location  of  the log if the default location of
/var/tmp/xfs_copy.log.XXXXXX is not desired.

-V     Prints the version number and exits.

xfs_fsr – File System re-organizer for XFS

The “xfs_fsr” utility is used to defragment mounted XFS file systems. The reorganization algorithm operates on one file at a time, compacting or otherwise improving the layout of the file extents (contiguous blocks of file data). When invoked with out any arguments, xfs_fsr will defragment all regular files in all mounted xfs file systems. xfs_fsr uses the file “/etc/mtab” as its source of mounted file systems. The xfs_fsr utility also allows a user to suspend a defragmentation process at a specified time and then resume from where it last left off. The current position of the defragmentation process is stored in the file:

/var/tmp/.fsrlast_xfs

xfs_fsr can also be invoked to work with a single file:

xfs_fsr /path/to/file

When xfs_fsr is invoked, it will require sufficient free space to be available as each file is copied to a temporary location whilst it is processed. A warning message will be displayed if sufficient space is not available.

xfs_bmap

Prints the map of disk blocks used by files in an XFS filesystem. The map lists each extent used by the file, as well as regions in the file with no corresponding blocks.

Each line of the listing takes the following form: extent: [startoffset..endoffset]: startblock..endblock

[root@centos07a xfs_test]# xfs_bmap test.file
test.file:
0: [0..7]: 96..103

[root@centos07a xfs_test]# xfs_bmap -v test.file
test.file:
EXT: FILE-OFFSET      BLOCK-RANGE      AG AG-OFFSET        TOTAL
0: [0..7]:          96..103           0 (96..103)            8

For further information regarding this utility, please consult the relevant man page: man xfs_bmap

xfs_info

To view your XFS file system information, the command “xfs_info” can be issued:

[root@centos07a /]# xfs_info /dev/sdc1
meta-data=/dev/sdc1              isize=256    agcount=17, agsize=32704 blks
=                       sectsz=512   attr=2, projid32bit=1
=                       crc=0
data     =                       bsize=4096   blocks=524032, imaxpct=25
=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=853, version=2
=                       sectsz=512   sunit=0 blks, lazy-count=1
real-time =none                   extsz=4096   blocks=0, rtextents=0

xfs_admin

The xfs_admin command allows an administrator to changes parameters of a XFS file system. The xfs_admin utility can only modify parameters of unmounted devices/file systems. (Mounted devices can not be modified).

For a full list of parameters that can be changed, please consult the relevant man page: man xfs_admin
xfs_metadump

xfs_metadump is a debugging tool that 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. For a full list of available option please consult the relevant man page: man xfs_metadump

xfs_mdrestore

xfs_mdrestore is used to restore a XFS metadump image to a filesystem image. The source argument specifies the location of the metadump image and the target argument specifies the destination for the filesystem image. The target can be either a file or a device.

xfs_mdrestore [ -g ] source target

The “-g” parameter shows the restore progress on stdout.

xfs_db

A utility that can be used to debug a XFS file system. For further information, please consult the relevant man page: man xfs_db.

xfs_estimate

The xfs_estimate utility is used to estimate the amount of space that a xfs file system will take.

[root@centos07a xfs_test]# xfs_estimate /var/tmp
/var/tmp will take about 4.4 megabytes

[root@centos07a xfs_test]# xfs_estimate -v /var/tmp
directory                               bsize   blocks    megabytes    logsize
/var/tmp                                 4096     1138        4.4MB    4096000

xfs_estimate parameters:

[root@centos07a xfs_test]# xfs_estimate -h
Usage: xfs_estimate [opts] directory [directory …]
-b blocksize (fundamental filesystem blocksize)
-i logsize (internal log size)
-e logsize (external log size)
-v prints more verbose messages
-V prints version and exits
-h prints this usage message

Note:    blocksize may have ‘k’ appended to indicate x1024
logsize may also have ‘m’ appended to indicate (1024 x 1024)

xfs_mkfile

xfs_mkfile is used to create a xfs file. The file is padded with zeroes by default. The default size is in bytes, but it can be flagged as kilobytes, blocks, megabytes, or gigabytes with the k, b, m, or g suffixes respectively.

Syntax: xfs_mkfile [ -v ] [ -n ] [ -p ] size[k|b|m|g] filename

Options that can be passed:

-v     Verbose. Report the names and sizes of the created files.

-n     No bytes. Create a holey file – that is, do not write out any
data, just seek to the end of the file and write a block.

-p     Preallocate.  The file is preallocated, then overwritten with
zeroes, it is then truncated to the desired size.

-V     Prints the version number and exits.

xfs_io

xfs_io is a debugging tool similar to the utility xfs_db, but is aimed at examining the regular file I/O paths rather than the raw XFS volume itself. For a full list of all the parameters/options that can be passed, please consult the relevant man page: man xfs_io

xfs_logprint

xfs_logprint prints the log of a XFS file system. The device argument is the pathname of the partition or logical volume containing the filesystem. The device can be a regular file if the “-f” option is used. The contents of the file system remain undisturbed.

There are two major modes of operation in xfs_logprint:

One mode is better for filesystem operation debugging. It is called the transactional view and is enabled through the “-t” option. The transactional view prints only the portion of the log that pertains to recovery. In other words, it prints out complete transactions between the tail and the head. This view tries to display each transaction without regard to how they are split across log records.

The second mode starts printing out information from the beginning of the log. Some error blocks might print out in the beginning because the last log record usually overlaps the oldest log record. A message is printed when the physical end of the log is reached and when the logical end of the log is reached. A log record view is displayed one record at a time. Transactions that span log records may not be decoded fully.

Syntax: xfs_logprint [ options ] device

Options that can be passed:

-b     Extract and print buffer information. Only used in transactional
view.

-c     Attempt to continue when an error is detected.

-C filename
Copy  the log from the filesystem to the file filename.  The log
itself is not printed.

-d     Dump the log from front to end, printing where each  log  record
is located on disk.

-D     Do not decode anything; just print data.

-e     Exit  when  an error is found in the log. Normally, xfs_logprint
tries to continue and unwind from bad logs.  However,  sometimes
it  just  dies  in  bad  ways.   Using this option prevents core
dumps.

-f     Specifies that the filesystem image to be processed is stored in
a  regular  file at device (see the mkfs.xfs(8) -d file option).
This might happen if an image copy of a filesystem has been made
into an ordinary file with xfs_copy(8).

-l logdev
External  log  device.  Only  for those filesystems which use an
external log.

-i     Extract and print inode information. Only used in  transactional
view.

-q     Extract  and print quota information. Only used in transactional
view.

-n     Do not try and interpret log data;  just  interpret  log  header
information.

-o     Also  print  buffer  data in hex.  Normally, buffer data is just
decoded, so better information can be printed.
-s start-block
Override any notion of where to start printing.

-t     Print out the transactional view.

-v     Print “overwrite” data.

-V     Prints the version number and exits.

xfs_rtcp

xfs_rtcp copies a file to the real-time partition on a XFS file system. If there is more than one source and target, the final argument (the target) must be a directory which already exists.

Syntax: xfs_rtcp [ -e extsize ] [ -p ] source … target

Options that can be used:

OPTIONS
-e extsize
Sets the extent size of the destination real-time file.

-p     Use  if  the  size of the source file is not an even multiple of
the block size of the destination filesystem. When -p is  speci-
fied  xfs_rtcp  will pad the destination file to a size which is
an even multiple of the filesystem block size.  This  is  neces-
sary since the real-time file is created using direct I/O and the
minimum I/O is the filesystem block size.

-V     Prints the version number and exits.

xfs_ncheck

The utility xfs_ncheck is used to generate a list of inode numbers along with path names.

Syntax: xfs_ncheck [ -i ino ] … [ -f ] [ -s ] [ -l logdev ] device

Options:

-f       Specifies that the filesystem image to be processed is  stored
in a regular file at device (see the mkfs.xfs -d file option).
This might happen if an image copy of a  filesystem  has  been
made into an ordinary file.

-l logdev
Specifies  the  device  where  the  filesystem’s  external log
resides.  Only for those filesystems  which  use  an  external
log.  See  the  mkfs.xfs  -l option, and refer to xfs(5) for a
detailed description of the XFS log.

-s       Limits the report to special files and  files  with  setuserid
mode.   This  option may be used to detect violations of secu-
rity policy.

-i ino   Limits the report to only those files whose inode numbers fol-
low.   May  be  given  multiple times to select multiple inode
numbers.

-V       Prints the version number and exits.

xfsdump

xfsdump is a file system incremental dump utility that is used in conjunction with xfsrestore. xfsdump backs up files and their attributes in a xfs file system. The files can be dumped to storage media, a regular file, or to standard output. Various dump options allow the administrator to create a full dump or an incremental dump. You may also specify a path to limit the files that are dumped.

To use the xfsdump utility, you first have to install it. This can be easily achieved by issuing the following command:

yum install xfsdump

xfsrestore

xfsrestore restores filesystems from dumps produced by xfsdump. For a full list of all available parameters and options available to xfsdump and xfsrestore, please consult the relevant man pages

 

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>