We will see how to Increasing LVM in xfs filesystem in this post.
LVM is playing important role in Linux/Unix OS and it will help to increase/ reduce filesystem size in Linux/Unix OS.
We are going to see how to increase a filesystem in Linux/Unix especially in RHEL7 OS.
We can increase the filesystem in online and we no need to unmount the filesystem for this operation.
Steps to be followed in increasing filesystems:
First we need to check whether the free space available in the VG. if the required space available in the VG then will go head and extend simply using from step 4 to 6.
If there is no free space in VG, Follow the below steps.
- Create a filesystem and change the filesystem type from “Linux” to “Linux LVM”(8e is the id/Hex code for Linux LVM filesystem type)
- Create physical volume for that created filesystem.
- Extend the Volume Group by adding the the created PV in this VG. now you will get free/unused space in your VG. Use “vgs” command to check that.
- Now extend/increase the size of logical volume using “lvextend” command.
- Than run “xfs_growfs” command to shrink the filesystem
- Finally check the mount point size using “df -h <mountpoint>” and logical volume size using “lvs” command. Both size should be same after extending the filesystem as well.
In our case we are going to create a fileystem in existing physical disk unused space and than will create PV, vgextend and lvextend likewise.
Using below command will check the free spcae in our physical disk
[root@localhost ~]# df -h /dev/sdb Filesystem Size Used Avail Use% Mounted on devtmpfs 1.4G 0 1.4G 0% /dev
we have nearby 2GB space in existing disk.
Use below commands to create a filesystem:
[root@localhost ~]# fdisk /dev/sdb
use “n” key to create new partition and provide the required details to create it.
Use “t” key to change the filesystem type from “Linux” to “Linux LVM”
Below command will help us to check whether the filesystem created perfectly and change filesystem type. Here “/dev/sdb2” is theone which we created and changed filesystemtype.
Click here to know how to create a filesystem/partition in linux/unix
[root@localhost ~]# fdisk -l /dev/sdb Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x1f51ec05 Device Boot Start End Blocks Id System /dev/sdb1 2048 12584959 6291456 8e Linux LVM /dev/sdb2 12584960 16777215 2096128 8e Linux LVM
Now create physical volume using below command:
[root@localhost ~]# pvcreate /dev/sdb2 Physical volume "/dev/sdb2" successfully created.
As next step we need to extend the VG by adding the created PV in our VG.
Before that check the size and free size of our VG like below.
[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree newvg 2 2 0 wz--n- 11.50g 516.00m
Extend the newvg using below command:
And check the VG size and free space after extending the VG.
[root@localhost ~]# vgextend newvg /dev/sdb2 Volume group "newvg" successfully extended [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree newvg 3 2 0 wz--n- 13.50g 2.50g
Now we have 2.5GB free space. SO, we are going to use this free spave to extend the LV.
Use lvs command to check avilabe LV’s and find the LV name which we are going to extend now.
[root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lv1 newvg -wi-ao---- 4.00g lv2 newvg -wi-a----- 7.00g
Here we are going to extend lv1
Use below command to extend the LV1:
[root@localhost ~]# lvextend -L +2G /dev/newvg/lv1 Size of logical volume newvg/lv1 changed from 4.00 GiB (1024 extents) to 6.00 GiB (1536 extents). Logical volume newvg/lv1 successfully resized.
And shrink the filesystem using below command:
[root@localhost ~]# xfs_growfs /dev/newvg/lv1
Finally check the mountpoint size and lv1 size using below command. Both should be same after extending the size.
[root@localhost ~]# df -h /lvolume1 Filesystem Size Used Avail Use% Mounted on /dev/mapper/newvg-lv1 6.0G 33M 6.0G 1% /lvolume1
[root@localhost ~]# lvs /dev/newvg/lv1 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lv1 newvg -wi-ao---- 6.00g
size replicating in both check.
Successfully we extend the LV size.
Hi, google lead me here, keep up good work.