Ivan Tomica

How to enlarge (resize) partition and expand LVM pool on top of it

Day or two ago I encountered a customer that had their server partitioned in a way that there was around 250GB of non-allocated space on disk. There were two partitions (sda1 and sda2) that were set up as /boot and LVM pool containing / mount point respectively.

Naturally I’ve replicated that setup locally and simulated how to expand partition and LVM pool on top of it. All without loosing and data OFC.

Setup was somewhat like this:

Let’s fix this oddity! Since DOS label is on disk, we’ll use fdisk utility to manage partitions. First of, fire-up fdisk:

fdisk

Print partitions and remember parameters (note them aside, screenshot or for what I’m concerned fax them…):

p 

In our case we’ll select partition 2 and delete it:

2

After that print partition state again, you’ll see something like:

Create new partition that starts with same block as the old one did. Failing to do so can result in catastrophic data loss. Additionally, specifying partition that’s smaller than old one will also result in data loss, so please, BE CAREFUL!

n

Specify partition as primary:

p

Partition number:

2

First sector (use the one that you noted before deleting partition):

2099200

It should be default, but check, re-check and then check again.

To use whole disk in next step specify last sector available; it should be default so just press enter. You should now have following situation:

As you can see partition type is specified incorrectly, as it should be LVM (as it was before). To correct that:

t
Partition number: 2
Hex code: 8e

After everything is as it is supposed to be you can write new partitions with:

w

Reboot the system afterwards to re-sync partitions from the system side and to have all things clear.

OK, now that we’ve extended partition backing LVM pool we’ll proceed with extending it. First off, increase physical volume with:

pvresize /dev/vda2

It will by default extend volume to all available free space. After that’s done, extend LVM pool on top of that physical volume:

lvextend -l +100%FREE /dev/cl/root

Now you only need to extend filesystem on top of it. As server is using XFS this can be done with:

xfs_growfs /

Voila, this should be it. Your / mount point on LVM pool should be extended now.

Tagged in:, , , ,
About 
Sysadmin on the everlasting journey of learning. Always in search for an opportunity to prove myself and to learn something new. My addiction is learning and my main goal is to excel in every aspect of Linux/Unix system administration.

0 Comments

Leave a Reply

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