Disk Extend EXT2/3/4 and XFS root partition without LVM
Disk Extend EXT2/3/4 and XFS root partition without LVM
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
- 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
lsblk
andfdisk -l
commands as the image below.
- It can be seen the OS partition size
vda
is 160GB in total but thevda1
system root/
the total size is 80GB currently. More details can be seen usingdf -h
the command.
- To extend the partition we need to install
cloud utils
package and usegrowpartthe
command to increase the partition. Thegrowpart
is a Linux command-line tool used to extend a partition in a partition table to fill available space. Use the following command to installcloud utils
package.
On Ubuntu / Debian system:
sudo apt -y install cloud-guest-utils gdisk
For CentOS System:
sudo yum -y install cloud-utils-growpart gdisk
- Use
growpart
to extend the partitionvda1
.
growpart /dev/vda 1
Here/dev/vda
is the main OS Partition and1
is sub-partition number 1 which means we are extending/dev/vda1
partition using the above command. - Now check the partitions details using
lsblk
command. 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 -Th
command. In our case, our system is using ext4 partition.
- Now, we need to resize
/
partition to fill all space in/dev/vda1
partition using theresize2fs
for ext partition command as below.
resize2fs /dev/vda1
If your filesystem is XFS, it can be grown while mounted using thexfs_growfs
command as below.
xfs_growfs -d /dev/vda1
- Confirm the new size using
df -h
,lsblk
andfdisk -l
commands. 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.