In this tutorial, we will teach you how to resize your hard disk partitions in Linux by introducing a very useful tool. You can easily resize all partitions with this utility. Whether this is a root partition or any other partition. No need to enter a rescue mode or reboot. this will also cover both ext4 and XFS filesystem root partition extending. This tool is called growpart and we are going to do a lot of things in this tutorial using this tool.
growpart command : #
growpart is a Linux command-line tool used to extend a partition in a partition table to fill available space. This command is provided by cloud utils package.
How to Install cloud utils package on the system #
On Ubuntu / Debian system, run the commands below to install growpart tool.
For CentOS server, run:
Help page can be viewed by passing -h argument
How to extend root filesystem using LVM on Linux #
- Create an LVM physical volume, volume group, and logical volume.
- Create an XFS and ext4 filesystem on the logical volumes
- Extend LVM logical volumes ( root and non-root filesystem)
1. Check the condition of the disk and its structure #
2: Extend your desired disk size (root partition or other) #
If you did not reboot your server after resizing the partition, rescan your SCSI devices as such.
First, check the name(s) of your SCSI devices.
0:0:0:0 1:0:0:0 2:0:0:0
Then rescan the scsi bus. Below you can replace the ‘0:0:0:0’ with the actual scsi bus name found with the previous command. Each colon is prefixed with a slash, which is what makes it look weird.
Now use growpart to extend your partition. In this example, we’re extending partition 2 in disk /dev/sda. (Replace 2 and /dev/sda with your correct values.)
CHANGED: partition=2 start=2099200 old: size=39843840 end=41943040 new: size=102758367 end=104857567
Confirm if the change was successful.
Step 3: Resize root logical volume to occupy all space #
Resize physical volume. (command: pvresize)
# pvresize /dev/sda2
Physical volume “/dev/sda2” changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
This extends the logical volume to use all available capacity in the volume group. With the + sign the value is added to the actual size of the logical volume.
Command options used:
- -l – extend or set the logical volume size in units of logical extents
- -r – Resize underlying filesystem together with the logical volume
Where size suffix are:
- M for megabytes
- G for gigabytes
- T for terabytes
- P for petabytes
- E for exabytes
Without the + sign the value is taken as an absolute one.
$ sudo lvextend -r -L +20G /dev/name-of-volume-group/root
So we have now:
and still 30G Free:
4: Update changes on the filesystem (If you didn’t use -r option in step 3) #
Your root filesystem will still show the old size.
/dev/mapper/rhel-root xfs 27G 1.9G 26G 8% /
Let’s make the filesystem report the actual size, including extended.
For ext4 filesystem
For xfs filesystem