Shadow

How to resize the root partition in centos?

How to resize or extend the root partition in centos?

All the Linux file systems are stored in the root partition. Sometimes we feel the provided storage is enough for the system but eventually, we need more storage at the root. So, In this post, I will share the steps to resize or extend the root partition. This method is also applied to RHEL.

When we extend the storage in the system. We need to find out that how much free storage we have left.

# parted
(parted) print free

show free space

There is a 10.7GB free space/storage. we will add this free storage to the root partition. Press q to exit.

Next step, we need to run fdisk tool or command to manage disk or volumes. Run fdisk /dev/sda to access the disk management. press p to print or show the details of the disk.

fdisk print the details

In the picture above, we can see the current details of the disk. Please note the start block, id, and system type of the /dev/sda2 which is a root partition. The start block is 2099200, id is 8e and the system is Linux LVM.

Press d to delete the partition and select the partition which we want to delete. 2 is the partition number we will delete in this demo.

Delete partition

press or select n to create a new partition. select the partition primary or extended. we have selected the p (primary) in this demo. And select partition number 2 which we have deleted.
Select the first sector, we are continuing with the default value because the default value and pretended value in the upper step are the same. So, just press the enter.
The tricky part is to select the Last Sector. We can see the total blocks of the last sector in default value. it means if we continue with the default value it will assign all the free space or storage to the created partition. But if we want to save some free storage for other options we can define the specific size by defining the K, M, G where K=Kilobyte, M=Megabype, and G= GigaByte. For example: if our requirement is to increase 5GB only in the root, we can define 5GB so that the rest of the free storage we can use for other options.

Create new partition

In this demo, I have selected the default value. The root partition will grow or increase by 10.7GB.

We can see that the new partition id and the system are different from the original.

Check new partition type

Press or select the t to change the id and system. 2 is the partition number. Hex code is 8e.

Change the partition type

The partition id and system are converted to the original state. press p to print the details.
Now we need to write the changes we have been made. press w. Partition changes have been saved but there is an error which says that the system is busy. so, reboot the system.

Write the changes

after rebooting the system. we need to run a few resize commands and the final message is data block changed.

#pvresize /dev/sda2
#lvresize /dev/mapper/centos-root /dev/sda2
#xfx_growfs /dev/mapper/centos-root

pvresize, lvresize and sfx_growfs

In the final step, we will check and verify that the root partition has been increased using parted command again parted and print free.

Verify the partition increse

The root partition is changed or increased from 42.9GB to 53.7GB.

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *