Extend EXT2/3/4 and XFS root partition without LVM

Category : Linux/ Unix

Looking for steps to grow your KVM VM/Container’s partition after extending root OS size or extending ext2/3/4 and XFS root partition without LVM at runtime. Steps to extend root partition without LVM are quite easy and can be followed without going into many technical details. This guide will also help system admins who have increased the KVM Container root OS size from the Host node but inside Container the partition size remains the same. Steps will work on most Debian/Ubuntu and CentOS based systems.

Requirements

  • Root access to the System/VM/Container.
  • Extended root OS Size (for KVM VM/Containers only)

Procedure

  1. Log in to the root user of the System/VM/Container after root OS Size is increased.
  2. Check the partition details of the system using lsblk and fdisk -lcommands as the image below.
    lsblk
  3. It can be seen the OS partition size vda is 160GB in total but the vda1 system root / the total size is 80GB currently. More details can be seen using df -h the command.
    df -h
  4. To extend the partition we need to install cloud utils package and use growpartthe command to increase the partition. The growpart is a Linux command-line tool used to extend a partition in a partition table to fill available space. Use the following command to install cloud utilspackage.
    On Ubuntu / Debian system:
    sudo apt -y install cloud-guest-utils gdiskFor CentOS System:
    sudo yum -y install cloud-utils-growpart gdisk
    install cloud utils package
  5. Use growpart to extend the partition vda1.
    growpart /dev/vda 1
    extend root partition without lvm
    Here /dev/vda is the main OS Partition and 1 is sub-partition number 1 which means we are extending /dev/vda1 partition using the above command.
  6. Now check the partitions details using lsblkcommand. It should show sub-partition number 1 extended to 160GB.
    lsblk
  7. Now, check what type of partition your system is using with the help of df -Thcommand. In our case, our system is using ext4 partition.
    check partition type
  8. Now, we need to resize / partition to fill all space in /dev/vda1 partition using the resize2fsfor ext partition command as below.
    resize2fs /dev/vda1
    extend root partition without lvm and resize2fs
    If your filesystem is XFS, it can be grown while mounted using the xfs_growfs command as below.
    xfs_growfs -d /dev/vda1
  9.  Confirm the new size using df -h, lsblkand fdisk -lcommands. You can see now vda1 partition is 160GB in total size.
    df -h final check

And it’s done, you have now learnt how to extend an ext2/3/4 or XFS root partition on Linux without LVM.

If you are managing OpenVZ Servers, then you can find the following Guide useful with some useful commands.

OpenVZ useful commands