How to extend XFS root partition in Linux

Time:2022-7-31

In some cases, the / partition is out of disk space in Linux. Even compressing and deleting old log files is useless, so in this case, we have no choice but to expand / file system. In this article, we will demonstrate how to extend XFS root partitions in Linux systems that are not LVM logical volumes.
First, we must expand additional space to the system disk, and then use growpart and XFS_ The growfs command extends the root partition (or file system).

This article uses vmware workstation, and the installed operating system is centos8 with 20GB disk space/ The root partition size is 17GB.

Check / partition size
Run DF -th / view the size of the current root partition:

[[email protected] ~]# df -Th /
Filesystem Type Size Used Avail Use% Mounted on
/dev/nvme0n1p2 xfs 17G 1.6G 16G 10% /
Verify the size of the operating system disk using the lsblk and fdisk commands:

[[email protected] ~]# lsblk /dev/nvme0n1
[[email protected] ~]# fdisk -l /dev/nvme0n1
How to extend XFS root partition in Linux how to extend XFS root partition in Linux
The above output shows that the size of the OS disk is 17 GB.

Disk expansion of installation system
Increase the size of the operating system disk. I changed the size of the operating system disk from 20 GB to 40 Gb.
https://www.admin5.com/articl…
https://www.donews.com/news/d…
https://www.donews.com/news/d…
VMware Workstation is used in this article. You need to shut down the operating system and then perform disk expansion.

Before partition expansion, it was 20GB.
How to extend XFS root partition in Linux how to extend XFS root partition in Linux
Next, expand the system disk to 40Gb.
How to extend XFS root partition in Linux how to extend XFS root partition in Linux
As you can see, the expansion has been completed. The next step is to start the system.
How to extend XFS root partition in Linux how to extend XFS root partition in Linux

Extended root partition based on XFS file system
To extend the root partition, we need to use growpart and XFS_ Growfs command. We need to install this command:

[[email protected] ~]# yum -y install cloud-utils-growpart gdisk
After the expansion is completed, next, check the disk capacity:
How to extend XFS root partition in Linux how to extend XFS root partition in Linux
The above output confirms that the disk size of the operating system is now 40 Gb. Now let’s use the following command to expand the root partition.

Run the growpart command on the second partition of the /dev/sda disk (we use 2 as the partition number because our / partition is on the second partition of the disk).

[[email protected] ~]# growpart /dev/nvme0n1 2
CHANGED: partition=2 start=1026048 old: size=35651584 end=36677632 new: size=82859999 end=83886047
How to extend XFS root partition in Linux how to extend XFS root partition in Linux
Check:
How to extend XFS root partition in Linux how to extend XFS root partition in Linux
Note that if you want to use the growpart command to expand / partition, there must be no other partitions behind the partition, otherwise you cannot expand. The following information will be prompted:
How to extend XFS root partition in Linux how to extend XFS root partition in Linux
If there is a swap partition under the / partition, you can only delete the swap partition, and then execute growpart to expand the / root partition.

Use DF -th to check whether the / partition has been expanded:

[[email protected] ~]# df -hT /
Filesystem Type Size Used Avail Use% Mounted on
/dev/nvme0n1p2 xfs 17G 1.7G 16G 10% /
How to extend XFS root partition in Linux how to extend XFS root partition in Linux
It is found that the partition has not been expanded. XFS is needed next_ Growfs command to expand XFS partition:

[[email protected] ~]# xfs_growfs /
meta-data=/dev/nvme0n1p2 isize=512 agcount=4, agsize=1114112 blks

     =                       sectsz=512   attr=2, projid32bit=1
     =                       crc=1        finobt=1, sparse=1, rmapbt=0
     =                       reflink=1

data = bsize=4096 blocks=4456448, 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 4456448 to 10357499
How to extend XFS root partition in Linux how to extend XFS root partition in Linux
Let’s use DF -th to check whether the / partition has been expanded:

[[email protected] ~]# df -hT /
Filesystem Type Size Used Avail Use% Mounted on
/dev/nvme0n1p2 xfs 40G 1.8G 38G 5% /
summary
Growpart and XFS are used in this article_ Growfs command to expand the disk and XFS partition.