How to grow a xfs filesystem?

Filesystems normally occupy all of the space on the device where they reside. You may have to increase it over the time, to do that, it is necessary to provide added space for it to occupy. Therefore there must be at least one spare new disk partition available. Adding the space is often done through the use of a logical volume manager.

Though xfs_growfs is most often used in conjunction with logical volumes. However, it can also be used on a regular  disk partition, for example if a partition has been enlarged while retaining the same starting block.

Here is an example:

/tmp resides on /dev/mapper/vg0-tmp, 512MB, need to increase it to 1024MB.

Step1: check the file system

# xfs_info /tmp
meta-data=/dev/mapper/vg0-tmp    isize=256    agcount=4, agsize=32768 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=131072, 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
realtime =none                   extsz=4096   blocks=0, rtextents=0

Step2: Increase the lv via lvm

Here is an article describe how to extend an Logical volume in LVM

Step3: xfs_growfs the /tmp/ file system

# xfs_info /tmp
meta-data=/dev/mapper/vg0-tmp    isize=256    agcount=4, agsize=32768 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=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=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 131072 to 262144

The important information to look for is marked in red. You are looking for an increase in size relating to data blocks. We can now issue the "df" command or xfs_info to verify that the xfs_growfs command was successful:

More examples:

'd' or 'D' option, specify how much a xfs filesystem should be grown

#xfs_growfs -d 262144 /tmp

The different between '-d' and '-D' is that '-d' option specifies that the data section is grown to the largest possible size, while '-D' grow data section to sepcified size.

'l' or 'L' option, specify how much a xfs filesystem log section should be grown

#xfs_growfs -l 1024 /tmp

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]

'n' option, no change, print the filesystem geometry

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.

xfs_info is equivalent to invoking xfs_growfs with the -n option

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.

Note:

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.