Expand XFS Filesystem


Had to expand a XFS filesystem this morning.

It’s really simple to expand a mounted XFS filestem, just run xfs_growfs /file/system/name,
that command will expand the filesystem to use all available space in the logical volume.
You are using LVM aren’t you?

Expanding a filesystem where there is no free space in the logical volume requires either the addition of a new disk or expanding the size of an existing disk.
Obviously, the latter is only possible if you are using some form of virtualisation.

Adding a new disk

Create partition on new disk

I prefer to use cfdisk instead of fdisk, cfdisk is interactive and I find the prompts are easier to follow than fdisk.

# cfdisk /dev/sdc

    Select Free Space
    New partition
    Primary
    Accept default (the whole partition size)
    Type
        8E (Linux LVM)
    Write
        yes (write partition table)
    Quit

Initialise disk partition

If pvcreate can’t find the new partition …

# pvcreate /dev/sdc1
  Device /dev/sdc1 not found (or ignored by filtering).

… try running partprobe

# partprobe -s
/dev/sda: msdos partitions 1 2
/dev/sdb: msdos partitions 1
/dev/sdc: msdos partitions 1

pvcreate should then succeed.

# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created

Add disk partition to a volume group

Where VG_SDT1 is the name of our volume group.
Use vgdisplay or vgs abbreviated information) to get volume group details.

# vgextend VG_SDT1 /dev/sdc1
  Volume group "VG_SDT1" successfully extended

If, by some misadventure, you add the partition to the wrong volume group it can be removed by running vgreduce, as long as none of the space has been used!

# vgreduce VG_SDT1 /dev/sdc1
  Removed "/dev/sdn2" from volume group "VG_MD0026_SDT1"

Extend existing logical volume onto new disk partition

Use lvdisplay or lvs (abbreviated information) to get logical volume details.

# lvextend /dev/VG_SDT1/LogVol00 /dev/sdc1
  Size of logical volume VG_SDT1/LogVol00 changed from 50.00 GiB (12800 extents) to 114.00 GiB (29183 extents).
  Logical volume LogVol00 successfully resized

By default lvextend will add all of the partition space to the volume group.
If you only want to save a bit of space for future growth then specify the size, e.g. to add 10GB to logical volume:

# lvextend -L +10G /dev/VG_SAP/LogVol00 /dev/sdc1
  Size of logical volume VG_SAP/LogVol00 changed from 16.00 GiB (4096 extents) to 26.00 GiB (6656 extents).
  Logical volume LogVol00 successfully resized.

Extend XFS filesystem

Default is for xfs_growfs to use all available free space.

Can use -D option to specify new size (in disk blocks) where block size is likely to be 4K.

Calculation to find number of blocks is: ( desired_size_in_gb * 1gb ) / 4kb
for example: (112*1GB)/4KB = 26214400

xfs_growfs -D 26214400 /db2/SID/sapdata1
Comment on this article using form below. Requires email login only for authentication. HTML forbidden, Markdown only.