vgcreate vgchange vgconvert vgreduce vgextend vgmerge vgsplit vgrename and vgremove linux command


If you are a linux user or a linux system admin or you are working in a production environment then you have to know about the software disk management and all the methods to provide flexblibity in storage management.In storage management you must have indepth knowledge of lvm.But before lvm you must have sound knowledge of volume group.
This is a detail tutorial on linux volume group.Everything we mentioned here in this article will be directly or indirectly related with Linux Volume Group.We will learn how to manage Storage Device concerned with volume group using command line.vgcreate vgremove vgchange vgconvert vgreduce vgextend vgmerge vgsplit and vgrename are those linux command on which we are going to discuss in detail inside this tutorial.
First we need to create Physical Volumes that will be used to create Volume Group.
[root@localhost ~]# pvcreate /dev/hda{6,7,8} Physical volume "/dev/hda6" successfully created Physical volume "/dev/hda7" successfully created Physical volume "/dev/hda8" successfully created
To check whether physical Volumes have been created or not use pvscan command.
[root@localhost ~]# pvscan PV /dev/hda6 lvm2 [482.83 MB] PV /dev/hda7 lvm2 [862.84 MB] PV /dev/hda8 lvm2 [1.13 GB] Total: 3 [2.44 GB] / in use: 0 [0 ] / in no VG: 3 [2.44 GB]
Then we create Volume Group named vg00.
[root@localhost ~]# vgcreate vg00 /dev/hda{6,7,8} Volume group "vg00" successfully created
[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree vg00 3 0 0 wz--n- 2.43G 2.43G
[root@localhost ~]# pvscan PV /dev/hda6 VG vg00 lvm2 [480.00 MB / 480.00 MB free] PV /dev/hda7 VG vg00 lvm2 [860.00 MB / 860.00 MB free] PV /dev/hda8 VG vg00 lvm2 [1.12 GB / 1.12 GB free] Total: 3 [2.43 GB] / in use: 3 [2.43 GB] / in no VG: 0 [0 ]
[root@localhost ~]# vgdisplay --- Volume group --- VG Name vg00 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 2.43 GB PE Size 4.00 MB Total PE 623 Alloc PE / Size 0 / 0 Free PE / Size 623 / 2.43 GB VG UUID 7rDn7R-vnAv-aFQv-XlrP-CDha-h2tz-sNptkj
Learn how to limit maximum number logical volumes of volume group using "vgchange command"
[root@localhost ~]# vgchange -l 110 /dev/vg00 Volume group "vg00" successfully changed
Now using vgdisplay command you can check the maximum number of logical volumes allowed in this group. just see "MAX LV 110" in below output.
[root@localhost ~]# vgdisplay --- Volume group --- VG Name vg00 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 110 Cur LV 0 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 2.43 GB PE Size 4.00 MB Total PE 623 Alloc PE / Size 0 / 0 Free PE / Size 623 / 2.43 GB VG UUID 7rDn7R-vnAv-aFQv-XlrP-CDha-h2tz-sNptkj
How to remove a physical Volume from a Volume Group using "vgreduce " command.
[root@localhost ~]# pvscan PV /dev/hda6 VG vg00 lvm2 [480.00 MB / 480.00 MB free] PV /dev/hda7 VG vg00 lvm2 [860.00 MB / 860.00 MB free] PV /dev/hda8 VG vg00 lvm2 [1.12 GB / 1.12 GB free] Total: 3 [2.43 GB] / in use: 3 [2.43 GB] / in no VG: 0 [0 ]
Now I am going to remove "/dev/hda6" physical Volume from Volume Group vg00 here.
[root@localhost ~]# vgreduce vg00 /dev/hda6 Removed "/dev/hda6" from volume group "vg00"
Now you can check whether physical volume /dev/hda6 has been removed or not by using pvscan command.
[root@localhost ~]# pvscan PV /dev/hda7 VG vg00 lvm2 [860.00 MB / 860.00 MB free] PV /dev/hda8 VG vg00 lvm2 [1.12 GB / 1.12 GB free] PV /dev/hda6 lvm2 [482.83 MB] Total: 3 [2.44 GB] / in use: 2 [1.96 GB] / in no VG: 1 [482.83 MB]
Now you can very clearly see that Physical Volume /dev/hda6 is now not the part of Volume Group vg00.
How to add a physical volume to a Volume Group using "vgextend" command.
Now I want to add a new physical Volume /dev/hda9 to my existing volume group vg00.
Lets have a look of your volume group detail before adding any new physical volume.
[root@localhost ~]# pvscan PV /dev/hda7 VG vg00 lvm2 [860.00 MB / 860.00 MB free] PV /dev/hda8 VG vg00 lvm2 [1.12 GB / 1.12 GB free] PV /dev/hda6 lvm2 [482.83 MB] PV /dev/hda9 lvm2 [964.81 MB] Total: 4 [3.38 GB] / in use: 2 [1.96 GB] / in no VG: 2 [1.41 GB]
[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree vg00 2 0 0 wz--n- 1.96G 1.96G
Now I am going to add new physical Volume /dev/hda9 to volume group vg00.
[root@localhost ~]# vgextend vg00 /dev/hda9 Volume group "vg00" successfully extended
Now Check Volume Group details after adding new physical volume to it.
[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree vg00 3 0 0 wz--n- 2.91G 2.91G
How to split a physical volume of a volume group using "vgsplit" command.
before splitting volume group vg00 lets have a look about volume group.
[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree vg00 3 0 0 wz--n- 2.91G 2.91G
[root@localhost ~]# pvscan PV /dev/hda7 VG vg00 lvm2 [860.00 MB / 860.00 MB free] PV /dev/hda8 VG vg00 lvm2 [1.12 GB / 1.12 GB free] PV /dev/hda9 VG vg00 lvm2 [964.00 MB / 964.00 MB free] PV /dev/hda6 lvm2 [482.83 MB] Total: 4 [3.38 GB] / in use: 3 [2.91 GB] / in no VG: 1 [482.83 MB]
Now you can clearly see we have only one volume group present here named vg00 of size 2.91GB. Now i am going to splitt this volume group vg00 using vgsplit command.
[root@localhost ~]# vgsplit vg00 vg11 /dev/hda7 New volume group "vg11" successfully split from "vg00"
Now see the volume group detail after splitting volume group to confirm your successful splitting.
[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree vg00 2 0 0 wz--n- 2.07G 2.07G vg11 1 0 0 wz--n- 860.00M 860.00M
Now you can clearly see there are two volume groups now vg00 and vg11.
[root@localhost ~]# pvscan PV /dev/hda8 VG vg00 lvm2 [1.12 GB / 1.12 GB free] PV /dev/hda9 VG vg00 lvm2 [964.00 MB / 964.00 MB free] PV /dev/hda7 VG vg11 lvm2 [860.00 MB / 860.00 MB free] PV /dev/hda6 lvm2 [482.83 MB] Total: 4 [3.38 GB] / in use: 3 [2.91 GB] / in no VG: 1 [482.83 MB]
You can clearly see that two volume group vg00 and vg11 where vg00 consist of /dev/hda8 and /dev/hda9 and vg11 consist of /dev/hda7.
NOTE: It is not possible to split logical volumes between volume groups.vgsplit only moves complete physical volume.
Now question arises that what to do when we want to move a part of physical volume?
Answer is very simple, just use pvmove command if you want to move a part of physical volume.
How to combine two volume group using vgmerge "command".
In above pvscan output you can clearly see there are two volume group now "vg00" and "vg11".Now what i want to do is to combine or you can say merge these two volume groups together.So lets see how we can combine or merge these two volume groups using "vgmerge" command.
[root@localhost ~]# vgmerge -v vg00 vg11 Checking for volume group "vg00" Checking for volume group "vg11" Archiving volume group "vg11" metadata (seqno 2). Archiving volume group "vg00" metadata (seqno 5). Writing out updated volume group Creating volume group backup "/etc/lvm/backup/vg00" (seqno 6). Volume group "vg11" successfully merged into "vg00"
Now you can check volume group status or volume group information for your confirmation using vgs command or vgdisplay command or pvscan command.
[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree vg00 3 0 0 wz--n- 2.91G 2.91G [root@localhost ~]# pvscan PV /dev/hda8 VG vg00 lvm2 [1.12 GB / 1.12 GB free] PV /dev/hda9 VG vg00 lvm2 [964.00 MB / 964.00 MB free] PV /dev/hda7 VG vg00 lvm2 [860.00 MB / 860.00 MB free] PV /dev/hda6 lvm2 [482.83 MB] Total: 4 [3.38 GB] / in use: 3 [2.91 GB] / in no VG: 1 [482.83 MB]
How to rename a volume group using "vgrename" command.
Now here i am going to show you how to rename a volume group using vgrename command.
For example i am going to rename volume group vg00 to shivangi.
[root@localhost ~]# vgrename /dev/vg00 /dev/shivangi Volume group "vg00" successfully renamed to "shivangi"
For your confirmation check volume group info using vgs or pvscan command.
[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree shivangi 3 0 0 wz--n- 2.91G 2.91G
[root@localhost ~]# pvscan PV /dev/hda8 VG shivangi lvm2 [1.12 GB / 1.12 GB free] PV /dev/hda9 VG shivangi lvm2 [964.00 MB / 964.00 MB free] PV /dev/hda7 VG shivangi lvm2 [860.00 MB / 860.00 MB free] PV /dev/hda6 lvm2 [482.83 MB] Total: 4 [3.38 GB] / in use: 3 [2.91 GB] / in no VG: 1 [482.83 MB]
How to convert lvm1 to lvm2 using "vgconvert"
[root@localhost ~]# vgconvert -M2 shivangi Volume group "shivangi" already uses format lvm2
since i am already using lvm version 2 thats why you can see the above output.
Now How to convert lvm2 to lvm1.
How to Degrade LVM Version.
[root@localhost ~]# vgconvert -M1 shivangi Volume group shivangi successfully converted
For confirmation you can check it using pvscan command.
[root@localhost ~]# pvscan PV /dev/hda7 VG shivangi lvm1 [860.00 MB / 860.00 MB free] PV /dev/hda8 VG shivangi lvm1 [1.12 GB / 1.12 GB free] PV /dev/hda9 VG shivangi lvm1 [964.00 MB / 964.00 MB free] PV /dev/hda6 lvm2 [482.83 MB] Total: 4 [3.38 GB] / in use: 3 [2.91 GB] / in no VG: 1 [482.83 MB]
So now you can clearly see here lvm version is 1 showing as lvm1.
You can also convert lvm version 1 back to lvm version 2 using vgconvert command.
[root@localhost ~]# vgconvert -M2 shivangi Volume group shivangi successfully converted
For confirmation check it again using pvscan.
[root@localhost ~]# pvscan PV /dev/hda7 VG shivangi lvm2 [860.00 MB / 860.00 MB free] PV /dev/hda8 VG shivangi lvm2 [1.12 GB / 1.12 GB free] PV /dev/hda9 VG shivangi lvm2 [964.00 MB / 964.00 MB free] PV /dev/hda6 lvm2 [482.83 MB] Total: 4 [3.38 GB] / in use: 3 [2.91 GB] / in no VG: 1 [482.83 MB]
Hence you can see it is converted back to lvm version2.
You can also read our article:
The Advance Guide To LVM Part-1.
How to Create RAID on LOOP DEVICES and LVM over RAID.
Comments
vgsplit without loosing the data
Hi,
If I do the 'vgsplit', will I loose all the data saved in the LVs created on the VG (to which I have splitted) ?
My scenario:
pv1 -| |- lv00 -> mounted on /backup1 (and contains data)
| - vg00 - |
pv2 -| |- lv01 -> mounted on /backup2 (and contains data)
Now i want to split the VG so that LV00 and LV01 could have a separate PV and VG such as:
pv1 -> vg00 -> lv00
pv2 -> vg01 -> lv01
I was able to split the VG00 but then I was not able mount the LV00, LV01 and I also lost the data.
any way to achieve this ?
nice write up
Very Helpful
Add new comment