Extend Linux root partition online with LVM

Posted: March 4, 2019 in Uncategorized

Root partition extension online:
This article may help you when you have a situation of disk running out of space, especially a root partition online.
Note: Below are the steps we can follow, when we have the partitions which are created with LVM only.
Step 1: Check the current disk space or partitions with below command
# df -h

Step 2: Check the available devices or partitions with below command
# lsblk

Step 3 : Ensure the available/free space with below command
# pvdisplay

From the output, find the element Free PE. This value shows the available free space where we can use/extend it for root partition.
If you have free space then follow the next steps.

Step 4:   Check the device name with below command
# fdisk -l
You may find device name something like: /dev/sda

Step 5: Now create a new partition with below command
# fdisk /dev/sda
When you run the above command, it asks for different input parameters(param) that needs to supply in order to create a new partition by the system.
All bold letters are the input we need to enter.

Param 1 Need to create a new partition so enter the option:                          n 

Param 2: We need to have a primary partition (It asks for primary or extended – choose primary)- For that enter the option:                               p

Param 3: Primary device number – You would know this from lsblk command where it shows like sda1 sda2 if the partitions are already created and in use – Enter 2 or 3 depends on the next available device partitions –

Let say if you have only 1 partition is created already and the name of the partition is /dev/sda1, then for the next partition number that you must choose is 2:
So here in this case you option for param 3 is : 2

Param 4: Simply it prompts for acceptance – so just press enter

Param 5: No need to supply any input, simply just enter

Param 6: With the above steps and params input, it creates a partition. We can check the change/newly created partition from partition table and that can be printed by entering a param:   p

Param 7: From the above steps device is created as a normal Linux partition but we need to make it as LVM partition to extend it.
Input the param to make it as Linux LVM partition – to change the filesystem type :  t

Param 8: It asks for a partition number: Ensure to enter the new partition number that we supplied at param 3:  8e

Param 9: Now make changes/write to partition table for the newly created partition:    w

With all above steps we have created a new partition and that can be shown with below command.
# lsblk

Some times it may now show with the above command and there is a requirement of reboot the server to get the partition table.

But this is not recommended when there is no downtime and the server might be in a production cluster pool.

Step 5: Below command helps to show up the newly created device or partition which is ready use to extend the root partition.  This command helps to add or make changes to partition table without reboot.
# partx -v -a /dev/sda

Step 6: Now list the devices again with below command
# lsblk

Step 7: Check the free space and which ready to use with below command.
# pvdisplay

Step 8: Now create a physical volume with the newly created partition with below command
# pvcreate /dev/sda2

Step 9: Ensure the volume is created with the new partition
# pvdisplay

Step 10: Check the root volume group name with below command – This is needed to extend the root volume
# lvdisplay

Step 11: Now, need to extend the volume group from the physical volume created from Step 8.
# vgextend VolGroup /dev/sda3

Step 12: Check the LVM of root size (LV Size ) with below command
# lvdisplay

Step 13: Run below command to see the extend volume – Ensure free space – Free PE where we can use the Free PE to extend the LVM partition of root.
# vgdisplay

Output: From the output ensure the below parameter and use the free space PE value in extending the root partition

Example value would be as follows
Free PE / Size 15232 / 59.50 

In the above example use 15232 as a parameter/option to extend the partition.

Step 14: Now extend the logical volume with below command
# lvextend -l 15232  /dev/VolGroup/lv_root (+4482 a number displays at free space)

-l 15232 – We get this from Step 13
/dev/VolGroup/lv_root – We get this from step 13

Step 15: Resize the volume group with below command
# resize2fs /dev/VolGroup/lv_root

Step 16: Now check the newly available/free space of root partition with below command
# df -h

That’s all about extending a root partition online – without reboot the server.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s