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.
- Root access to the System/VM/Container.
- Extended root OS Size (for KVM VM/Containers only)
- Log in to the root user of the System/VM/Container after root OS Size is increased.
- Check the partition details of the system using
fdisk -lcommands as the image below.
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.
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
On Ubuntu / Debian system:
sudo apt -y install cloud-guest-utils gdiskFor CentOS System:
sudo yum -y install cloud-utils-growpart gdisk
growpart to extend the partition
growpart /dev/vda 1
/dev/vdais the main OS Partition and
1is sub-partition number 1 which means we are extending
/dev/vda1partition using the above command.
- Now check the partitions details using
lsblkcommand. It should show sub-partition number 1 extended to 160GB.
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.
Now, we need to resize
/ partition to fill all space in
/dev/vda1 partition using the
resize2fsfor ext partition command as below.
- If your filesystem is XFS, it can be grown while mounted using the
xfs_growfscommand as below.
xfs_growfs -d /dev/vda1
- Confirm the new size using
fdisk -lcommands. You can see now vda1 partition is 160GB in total size.
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.