How To Extend LVM Partition Online In Linux

Posted on : March 20, 2011 , Last Updated on : May 17, 2017 By
| Reply More

For some reasons, sometimes we need to extend our storage. If you are using LVM on your Linux, here are some tips to extend your LVM partition online. We are using Oracle Linux 6.5 and RHEL 3 & RHEL 4. Please note, that all this command must be run using root privileges.

1. Scenario 1: Extend storage using existing disk

In this scenario, we have an unused partition on existing storage and we want to use it to extend another LVM partition.

a. Check volume groups details

First, we will use vgdisplay command to see the detail of our Volume Groups (next we call it VG).

# vgdisplay

Show Volume Group detail

We can see that there is 49.21 GB Free Size.

To see the more detail of our VG, we can use add -v parameter to vgdisplay command.

# vgdisplay -v

VG more detail

b. Extend storage

The /dev/vg_devmachine/data has 24.41 GB. Let say we want to add 10 GB more to /data partition. To extend a logical volume you simply tell the lvextend command how much you want to increase the size (+10 below) with -L parameter.

# lvextend -L+10G /dev/vg_devmachine/data

Extend LVM

Note for RHEL 3 Only: We need to unmount the partition before activate the change.

# unmount /dev/VolGroup00/LogVol00

For this example, we can unmount /data partition by typing:

# unmount /dev/vg_devmachine/data

Then we need to activate the change. We will use resize2fs command. This command is used to resize ext2/ext3/ext4 file system online.

# resize2fs /dev/vg_devmachine/data

Note: On RHEL 4 you can use ext2online command to resize the partition.

# ext2online /dev/mapper/vg_devmachine-data

But on RHEL 5 above, the command is replaced by resize2fs command.

Activate the change

Now to check it, run vgdisplay -v again, and highlight the /dev/vg_devmachine/data.

New VG display after extend

We now see that the LV size grow into 34.41 GB.

If you are using RHEL 3, don't forget to mount your partition again.

2. Scenario 2: Extend storage to another disk

In this scenario, we have added new storage which is /dev/sdb with 100 GB capacity into Linux system. Then, we want to use it to extend existing LVM partition. The command to extend LVM partition to another disk remains the same. But when we add more physical storage into the system, then we need to make the OS (Linux) know more about it.

a. Create a physical partition

When we add a new disk, we need it to be recognized by the system to make some operations.  There are some partition tools on the internet such as fdisk and parted. In this article, we will use fdisk because it is available in most Linux distribution. The first thing to do is to create a new partition

# fdisk /dev/sdb

Create new partition

Press n to create new partition.

Create new partition

Let us say, we want to create 2 new partitions. Press p and 1 to create new primary partition. Put the size as 50G.

Repeat the operation for the second partition. press p and 2 to create the second primary partition. For the size (at question Last cylinder ...), you don't need to enter a value, it will consider the rest of space as the example below

Specify the size

Once it is finished, commit the change by pressing w button.

Commit the change

Now if we do fdisk -l, we will see /dev/sdb1 and /dev/sdb2 partition appear.

New partition appear

b. Create Physical Volume (PV) as the base of LVM

After we finish creating physical partition, the next step is to create Physical Volume (PV). PV is used as the host of LVM. A physical disk is divided into one or more physical volumes (PV)

# pvcreate /dev/sdb1 /dev/sdb2

Create PV

If you find no error, you can check the result using pvscan command.

# pvscan

Scan available PV

We now see two empty PV appear. Empty means that the PV’s does not belong to any Volume Group.

c. Extend the Volume Group (VG)

Logical volume groups (VG) are created by combining one or more PV. We have already a VG called vg_devmachine. Its capacity is 95.11 GB and 39.21 GB of free space. To extend vg_devmachine, we can use vgextend command.

# vgextend vg_devmachine /dev/sdb1

Extend Volume Group

Check it via vgdisplay. You will see that vg_devmachine size is increasing.

d. Extend the LVM partition

Now in this stage, we will use the same command at the previous one. Let say we want to extend /home partition. Adding it more 30 GB.

Again we check it using lvdisplay command first to see the current capacity.

# lvdisplay

Display LV for /home

To add more 30G into /home partition, we need to extend the partition:

# lvextend -L+30G /dev/vg_devmachine/home

Extend /home partition

Then we need to activate the change so it will take effect:

# resize2fs /dev/vg_devmachine/home

Activate the change

Conclusion

Using LVM partition, it gives you the flexibility about your storage. When your current partition is running out of space, you can easily resize the partition on-the-fly. You notice that we didn't need to unmount the partition to extend. It is an advantage of LVM partition but if the physical disk has a problem, it will affect the volume groups and all the LVM partitions created. You can see more about LVM configuration in this article.

Filed Under : HOWTOS, LINUX HOWTO, LVM

Tagged With :

Free Linux Ebook to Download

Leave a Reply

All comments are subject to moderation.