[Storage Disk] Use parted and xfs_growfs to resize XFS disk partition size

Resize XFS disk partition size

XFS is a high-performance journaling file system created by Silicon Graphics, Inc. XFS is particularly proficient at parallel IO due to its allocation group based design. This enables extreme scalability of IO threads, filesystem bandwidth, file and filesystem size when spanning multiple storage devices.

GNU Parted is a program for creating and manipulating partition tables.

This article describe how to use parted and xfs_growfs to resize XFS disk partition size dynamically.

Prerequites

Before resizing the disk partition or file system, please backup the data on that disk.

Run

There are two options to resize disk partition.

Option1. Run parted with disk partition

Use lsblk to check disk partition.

1
2
3
4
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1T 0 disk
└─sda1 8:1 0 10G 0 part /

Use parted to resize /dev/sda1 disk partition to 300 GB.

1
2
3
4
5
# parted /dev/sda resizepart 1
Warning: Partition /dev/sda1 is being used. Are you sure you want to continue?
Yes/No? Yes
End? [10.7GB]? 300000
Information: You may need to update /etc/fstab.

Use xfs_growfs to growth filesystem on /dev/sda1.

1
2
3
4
5
6
7
8
9
10
11
12
[root@centos ~]# xfs_growfs /
meta-data=/dev/sda1 isize=512 agcount=4, agsize=655296 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=2621184, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
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
data blocks changed from 2621184 to 73241931

Use df- m to check disk partition.

1
2
3
4
5
6
7
[root@centos ~]# df -m
Filesystem 1M-blocks Used Available Use% Mounted on
devtmpfs 3973 0 3973 0% /dev
tmpfs 3986 0 3986 0% /dev/shm
tmpfs 3986 34 3952 1% /run
tmpfs 3986 0 3986 0% /sys/fs/cgroup
/dev/sda1 286092 10508 275584 4% /

Option2. Run parted without disk partition

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[root@centos ~]# parted
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 1100GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
1 1049kB 10.7GB 10.7GB primary xfs boot

(parted) help
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
resizepart NUMBER END resize partition NUMBER
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright information of GNU Parted
(parted) resizepart 1
Warning: Partition /dev/sda1 is being used. Are you sure you want to continue?
Yes/No? Yes
End? [10.7GB]? 300000
(parted) quit
Information: You may need to update /etc/fstab.

Use df- m to check disk partition.

1
2
3
4
5
6
7
8
[root@centos ~]# df -m
Filesystem 1M-blocks Used Available Use% Mounted on
devtmpfs 3973 0 3973 0% /dev
tmpfs 3986 0 3986 0% /dev/shm
tmpfs 3986 17 3970 1% /run
tmpfs 3986 0 3986 0% /sys/fs/cgroup
/dev/sda1 10229 3234 6996 32% /
tmpfs 798 0 798 0% /run/user/1000

Use xfs_growfs to growth filesystem on /dev/sda1.

1
2
3
4
5
6
7
8
9
10
11
12
[root@centos ~]# xfs_growfs /
meta-data=/dev/sda1 isize=512 agcount=4, agsize=655296 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=2621184, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
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
data blocks changed from 2621184 to 73241931

Use df- m to check disk partition.

1
2
3
4
5
6
7
8
[root@centos ~]# df -m
Filesystem 1M-blocks Used Available Use% Mounted on
devtmpfs 3973 0 3973 0% /dev
tmpfs 3986 0 3986 0% /dev/shm
tmpfs 3986 17 3970 1% /run
tmpfs 3986 0 3986 0% /sys/fs/cgroup
/dev/sda1 286092 5164 280928 2% /
tmpfs 798 0 798 0% /run/user/1000

References

[1] start [Wiki] - https://xfs.wiki.kernel.org/

[2] XFS - ArchWiki - https://wiki.archlinux.org/title/XFS

[3] Parted User’s Manual - https://www.gnu.org/software/parted/manual/parted.html

[4] xfs_growfs(8): expand XFS filesystem - Linux man page - https://linux.die.net/man/8/xfs_growfs