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.
Scenario 1 - Extend storage using existing disk
In this scenario, we have unused partition on existing storage and we want to use it to extend another LVM partition.
First, we will use vgdisplay command to see if the detail of our Volume Groups (next we call it VG).
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
The /dev/vg_devmachine/data has 24.41 GB. Let say we want to add 10 GB more to /data partition.
# lvextend +10G /dev/vg_devmachine/data
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. Use resize2fs command. This command is used to resize ext2/ext3/ext4 file system online.
# resize2fs /dev/vg_devmachine/data
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.
Now to check it, run vgdisplay -v again, and highlight the /dev/vg_devmachine/data.
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.
Scenario 2 - Extend storage to another disk
In this scenario, we have add 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.
Recognize the disk
A new storage is usually has not been partitioned. There are some partition tools in the internet such as fdisk and parted. In this article, we will use fdisk because fdisk is available in most Linux distribution.
Create a partition on /dev/sdb disk
# fdisk /dev/sdb
Press ‘n’ to create new partition.
Let us say, we wan to create 2 new partitions. Press ‘p’ and 1 to create new primary partition. Put the size as 50G.
Once it is finished, commit the change by pressing ‘w’ button.
Now if we do fdisk -l, we will see /dev/sdb1 and /dev/sdb2 partition appear.
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.
# pvcreate /dev/sdb1 /dev/sdb2
If you find no error, you can check the result using pvscan command.
We now see two empty PV appear. Empty means that the PV’s is not belong to any Volume Group.
Extend the Volume Group (VG)
We have already a VG called vg_devmachine. It’s capasitiy 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
Check it via vgdisplay. You will see that vg_devmachine size is increasing.
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.
To add more 30G into /home partition, we need to extend the partition:
# lvextend -L+30G /dev/vg_devmachine/home
Then we need to activate the change:
# resize2fs /dev/vg_devmachine/home
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 can see more about LVM configuration in this article.