In my earlier post about LVM you have seen how we can create LVM volume and mount it on linux server. Once you create mount point it’s started acquiring space depending upon usage from the users. In this case we need to extend linux mount point so that larger space can be given to mount point. LVM gives this flexibility to extend linux mount point.
One of the advantages of working with LVM is that you can resize volumes if you’re out of disk space. If you are extending a logical volume, you will first extend the volume itself, and then you can extend the file system that is on it.
There are two cases to extend linux mount point as follows:
Case 1: Extending a logical volume if there are still unallocated extents in the volume group.
Case 2 : Extending a logical volume if there are no longer any unallocated extents in the volume group. When this occurs, you’ll need to extend the volume group first.
We will take this two cases for extend linux mount point one by one. Let’s say you have mount point “/data” and you want to extend this mount point.
[root@rhel1 ~]# df -h /data Filesystem Size Used Avail Use% Mounted on /dev/mapper/myvg-lvol0 504M 17M 462M 4% /data [root@rhel1 ~]#
In the above example /data mount point resides in “myvg” volume group.
Case 1: Volume group with unallocated extents.
Step 1 ➡ Check for Free PV’s in Volume group
In this case first check if you have any free extents or not for “myvg” volume group using below command:
[root@rhel1 ~]# vgs VG #PV #LV #SN Attr VSize VFree myvg 1 1 0 wz--n- 1016.00m 504.00m vg_rhel1 1 2 0 wz--n- 19.51g 0 [root@rhel1 ~]#
You can see that there is 504 mb space that can be used to extend linux mount point “/data” since its unallocated. You also can confirm the same using below command.
[root@rhel1 ~]# vgdisplay -v myvg|grep -i "Free PE" Free PE / Size 126 / 504.00 MiB [root@rhel1 ~]#
Step 2 ➡ Extend the logical volume.
let’s extend linux mount point “/data” using this free PE space.
[root@rhel1 ~]# lvextend -l +100%FREE /dev/myvg/lvol0 Extending logical volume lvol0 to 1016.00 MiB Logical volume lvol0 successfully resized
In the above example we have used all the free space using option “-l +100%FREE” however you can use -L to specify size in MB.
[read more=”Read more” less=”Read less”]
for example below command will add another 400 Mb space to lvol.
lvextend -L +400 /dev/myvg/lvol0
Step 3 ➡ Extend the mount point.
Only extending lvol does not adds space to mount point you need to use below “resize2fs” command to extend linux mount point “/data”.
[root@rhel1 ~]# resize2fs /dev/myvg/lvol0 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/myvg/lvol0 is mounted on /data; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/myvg/lvol0 to 260096 (4k) blocks. The filesystem on /dev/myvg/lvol0 is now 260096 blocks long.
Step 4 ➡ Recheck size of Mount point.
Now if you check /data mount point using df -h command our mount point is extended as below:
[root@rhel1 ~]# df -h /data Filesystem Size Used Avail Use% Mounted on /dev/mapper/myvg-lvol0 1000M 17M 933M 2% /data [root@rhel1 ~]#
Case 2: volume group with no unallocated extents.
Let’s say you don’t have free PE in the volume group can be confirmed using below command.
[root@rhel1 ~]# vgs VG #PV #LV #SN Attr VSize VFree myvg 1 1 0 wz--n- 1016.00m 0 vg_rhel1 1 2 0 wz--n- 19.51g 0 [root@rhel1 ~]# [root@rhel1 ~]# vgdisplay -v myvg|grep -i "Free PE" Finding volume group "myvg" Free PE / Size 0 / 0 [root@rhel1 ~]#
In the above case you need to add new PV to myvg volume group to extend linux mount point “/data”. Assume that you have got new PV “/dev/sdd” that can be added under myvg volume group ,then follow below set of commands.
Step 1 ➡ Format the New Disk
fdisk /dev/sdd
- To Create new partition Press n.
- Choose primary partition use p.
- Choose which number of partition to be selected to create the primary partition.
- Press 1 if any other disk available.
- Change the type using t.
- Type 8e to change the partition type to Linux LVM.
- Use p to print the create partition.
- Press w to write the changes.
You can see logs below:
[root@rhel1 ~]# fdisk /dev/sdd Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x0d235f3b. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-261, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-261, default 261): Using default value 261 Command (m for help): t Selected partition 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): p Disk /dev/sdd: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0d235f3b Device Boot Start End Blocks Id System /dev/sdd1 1 261 2096451 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@rhel1 ~]#
Step 2 ➡ Use pvcreate command for create lvm data structure on it.
[root@rhel1 ~]# pvcreate /dev/sdd1 Writing physical volume data to disk "/dev/sdd1" Physical volume "/dev/sdd1" successfully created [root@rhel1 ~]#
Step 3➡ Extend myvg volume group.
[root@rhel1 ~]# vgextend /dev/myvg /dev/sdd1 Volume group "myvg" successfully extended [root@rhel1 ~]#
Now you can able to see free unallocated PE’s inside myvg volume group.
[root@rhel1 ~]# vgs VG #PV #LV #SN Attr VSize VFree myvg 2 1 0 wz--n- 2.99g 2.00g vg_rhel1 1 2 0 wz--n- 19.51g 0 [root@rhel1 ~]# vgdisplay -v myvg|grep -i "Free PE" Finding volume group "myvg" Free PE / Size 511 / 2.00 GiB [root@rhel1 ~]#
Now simply follow steps given in case 1 as below:
Step 4 ➡ Extend the logical volume.
Lets say current size of “/data” is 1000M and you want to add another 1 GB space to it then give below command.
[root@rhel1 ~]# lvextend -L +1024 /dev/myvg/lvol0 Extending logical volume lvol0 to 1.99 GiB Logical volume lvol0 successfully resized [root@rhel1 ~]#
Step 5 ➡ Extend the mount point.
use resize2fs to extend linux mount point “/data” .
[root@rhel1 ~]# resize2fs /dev/myvg/lvol0 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/myvg/lvol0 is mounted on /data; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/myvg/lvol0 to 522240 (4k) blocks. The filesystem on /dev/myvg/lvol0 is now 522240 blocks long. [root@rhel1 ~]#
Step 6 ➡ Recheck size of Mount point.
Now just recheck our “/data” mount point is extended by 1gb space.
[root@rhel1 ~]# df -h /data Filesystem Size Used Avail Use% Mounted on /dev/mapper/myvg-lvol0 2.0G 17M 1.9G 1% /data [root@rhel1 ~]#
[/read]
Leave a Reply