How to resize ext2 / 3/4 and XFS root partitions without using LVM

This guide will show you how to expand or resize the ext2 / 3/4 and XFS file systems at runtime without using LVM. This may be the root partition with an ext2 / 3/4 or XFS file system but no LVM configured. In previous tutorials, we looked at how to extend the root file system using LVM on Linux.

Resize ext2 / ext3 / ext4 / XFS root partition at runtime

Step 1: Check the current root disk capacity

In this demo, I have a CentOS 7 VM with the following partitioning scheme.

$ lsblk  NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT sr0     11:0    1 1024M  0 rom   vda    253:0    0   10G  0 disk  └─vda1 253:1    0   10G  0 part /

As you can see from the output, the root file system is on the / dev / vda1 partition and there is no LVM.

Step 2: Expand the operating system root disk

I expanded the root block device to 30GB. I use KVM virtualization technology, so this guide applies to me:

How to expand / increase KVM virtual machine (VM) disk size

$ sudo virsh domblklist centos7 
 Target   Source
-------------------------------------------------
 vda      /var/lib/libvirt/images/centos7.qcow2
 sda      -

$ sudo fdisk -l /var/lib/libvirt/images/centos7.qcow2
Disk /var/lib/libvirt/images/centos7.qcow2: 10 GiB, 10739318784 bytes, 20975232 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

$ sudo qemu-img resize /var/lib/libvirt/images/centos7.qcow2 +20G
Image resized.

If you are using another virtualization platform, see its documentation for information on how to extend the OS virtual disk.

Step 3: Expand the VM partition

Start the VM and ssh as a user with sudo privileges. The first thing to do is to confirm the size of the new disk.

$ lsblk  NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT sr0     11:0    1 1024M  0 rom   vda    253:0    0   30G  0 disk  └─vda1 253:1    0   10G  0 part /

We can see that the disk has increased from 20GB to 20GB and from 10GB to 30GB. The next step is to extend the partition (Partition 1), Using the maximum size provided by the disk as an example.

Install cloud tools

For those newcomers growing upThis is a Linux command line tool for expanding partitions in a partition table to fill available space. This command is provided by the cloud utils package.

On Ubuntu / Debian systems, run

sudo apt -y install cloud-guest-utils

For CentOS server, run

sudo yum -y install cloud-utils-growpart

You can view the help page in the following ways -h argument

# growpart -h
growpart disk partition
   rewrite partition table so that partition takes up all the space it can
   options:
    -h | --help       print Usage and exit
         --fudge F    if part could be resized, but change would be
                      less than 'F' bytes, do not resize (default: 1048576)
    -N | --dry-run    only report what would be done, show new 'sfdisk -d'
    -v | --verbose    increase verbosity / debug
    -u | --update  R update the the kernel partition table info after growing
                      this requires kernel support and 'partx --update'
                      R is one of:
                       - 'auto'  : [default] update partition if possible
                       - 'force' : try despite sanity checks (fail on failure)
                       - 'off'   : do not attempt
                       - 'on'    : fail if sanity checks indicate no support

   Example:
    - growpart /dev/sda 1
      Resize partition 1 on /dev/sd

Now use growpart to extend the partition.

$ sudo growpart /dev/vda 1CHANGED: partition=1 start=2048 old: size=20969472 end=20971520 new: size=62912479,end=62914527

This will resize partition 1 on / dev / vda.

Verify the changes.

$ lsblk  NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT sr0     11:0    1 1024M  0 rom   vda    253:0    0   30G  0 disk  └─vda1 253:1    0   30G  0 part /

Step 4: Resize the “/” partition to fill all the space

The final step is to resize the file system to continuously expand to fill additional space

For ext4 file system, use resize2fs

$ sudo resize2fs /dev/vda1resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/vda1 is mounted on /; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 4 The filesystem on /dev/vda1 is now 7864059 blocks long.

If your file system is XFS, you can expand it when mounted using the xfs_growfs command:

sudo xfs_growfs /

Confirm new size with df -h

$ df -hT | grep /dev/vda/dev/vda1      ext4       30G  1.2G   27G   5% /

Congratulations! You have successfully resized the ext2 / 3/4 or XFS root partition on Linux without LVM. See related articles below.

How to extend EBS boot disk on AWS without restarting the instance

How to extend the root file system with LVM on Linux

How to expand / increase KVM virtual machine (VM) disk size

Using qemu-img in Linux

Sidebar