How to Extend XFS Root Partition without LVM in Linux

There are some situations where / or root partition is running out of disk space in Linux. Even compressing and deleting old log files did not help, so in such cases we are left with no option but to extend / filesystem. In this article, we will demonstrate how to extend xfs based root partition without lvm in a Linux system.

If we talk about the logical steps, first we have to add additional space to OS disk and then use growpart and xfs_growfs commands to extend the root partition (or filesystem).

I am assuming we have a Linux based Virtual Machine running either on KVM hypervisor or VMware or VirtualBox. In this machine, we have 10 GB XFS based / root partition and want to extend it till 20 GB.

Let’s dive into the actual steps,

Step 1) Verify the root partition size

Login to the Linux machine and run below df command to view current size of root partition,

$ df -Th /
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sda2      xfs    10G  9.1G  991M  91% /
$

Verify the size of OS disk using lsblk and fdisk commands

$ lsblk /dev/sda
$ sudo fdisk -l /dev/sda

View-OS-Disk-Size-Linux

Above output shows that size of OS disk is 12 GB. We have two partitions as /boot & /.

Step 2) Increase the size of OS disk  

Increase the size of OS disk, in my case I will change OS disk size from 12 GB to 22 GB as I want to extend / partition by 10 GB.

Depending on the environment, one must perform this action. In my case I have a VM running inside a VirtualBox, so first stop it and extend the disk size as shown,

OS-Disk-Size-VirtualBox

Change the size and set it as 22 GB

Change-OS-Disk-VirtualBox

Click on apply and then start the virtual machine.

Step 3) Extend root partition based on xfs filesystem

To extend root partition we need growpart and xfs_growfs commands or utilities. But these are not available in the default installation, so let’s first install these using the following command,

$ sudo apt install cloud-guest-utils gdisk -y         // For Ubuntu & Debian
$ sudo dnf install cloud-utils-growpart gdisk -y     // For RHEL 8 / CentOS 8
$ sudo yum install cloud-utils-growpart gdisk -y    // For RHEL 7 / CentOS 7

Once above packages are installed, view OS disk size with lsblk and fdisk commands,

Updated-OS-Disk-size-linux

Above output confirms that OS disk size is now 22 GB, now let’s extend root partition using following commands,

Run growpart command on 2nd partition of /dev/sda disk (we have used 2 as partition number because our root partition is 2nd on the disk).

$ sudo growpart /dev/sda 2

Note: growpart command will rewrite the partition table so that partition takes all the space.

Verify the lsblk output for / partition,

$ lsblk

lsblk-command-output-after-growpart

Now run xfs_growfs command to extend the root filesystem,

$ sudo xfs_growfs /

Extend-XFS-Root-Partition-Linux

Verify the size of / file system using df -Th command,

[sysops@linuxtechi ~]$ df -Th /
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sda2      xfs    20G  9.2G   11G  46% /
[sysops@linuxtechi ~]$

Perfect above output shows that / partition has been extended to 20 GB. That’s all from this article. I hope you have found it informative. Please do share your feedback and comments in the below comments section.

Leave a Comment

Your email address will not be published. Required fields are marked *