LVM quickly explained:
In computer storage, logical volume management or LVM provides a method of allocating space on mass-storage devices that is more flexible than conventional partitioning schemes. In particular, a volume manager can concatenate, stripe together or otherwise combine partitions into larger virtual ones that administrators can re-size or move, potentially without interrupting system use.
As seen in the LVM design scheme, Physical Volumes (PV) are the bottom layer of LVM. The second layer are Volume Groups (VG) and the final, third layer are Logical Volumes (LV). In Part 1 (LVM – Physical Volume Management on CentOS 6) we learned how to manage PV’s and already prepared PV’s to be added to Volume Groups (VG’s). This example is continuation of Part 1 (LVM – Physical Volume Management on CentOS 6).
Here is the basic design scheme:
Volume Group Management is a part 2/3 of LVM Management on CentOS 6!
- Part 1 – LVM – Physical Volume Management on CentOS 6
- Part 2 – LVM – Volume Group Management on CentOS 6
- Part 3 – LVM – Logical Volume Management on CentOS 6
In this post we will learn how to create, delete, extend, reduce, rename, merge, split and change Volume Groups (VG). We will learn how to prepare Volume Groups for Logical Volumes.
Let’s start our Volume Group Management on CentOS 6 guide!
For this example we have 3 additional hard drives:/dev/sdb (1GB), /dev/sdc (2GB) and /dev/sdd (3GB). /dev/sda2 is a pre-existing PV on my system that holds the system root and swap partition.
1. Displaying Volume Groups
We can display all Volume Groups (VG’s) on the system with the “vgdisplay” command:
[root@foo ~]# vgdisplay --- Volume group --- VG Name vg_foo System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 14.51 GiB PE Size 4.00 MiB Total PE 3714 Alloc PE / Size 3714 / 14.51 GiB Free PE / Size 0 / 0 VG UUID 3n3nzs-dzHK-rApY-EApz-Zz2H-JQVP-TlcYfF
We can also display Volume Groups with “vgscan” or “vgs” commands, but as we see the output is a bit different – in following example i will be using “vgdisplay“, because it gives me the most info:
[root@foo ~]# vgscan Reading all physical volumes. This may take a while... Found volume group "vg_foo" using metadata type lvm2
[root@foo ~]# vgs VG #PV #LV #SN Attr VSize VFree vg_foo 1 2 0 wz--n- 14.51g 0
We see there is currently only one existing Volume Group present. This VG is called vg_foo and is the VG, that holds the system root and swap partition. With the “vgdisplay” command we se additional info – VG size, PE size, Total PE,… This is the Physical Extent. A number of Physical Extents builds the Physical Volume.
2. Adding a Physical Volume to Volume Groups
We add PV’s to Volume Groups (VG’s) using “vgcreate name /dev/harddisk” command. It is very simple, no additional parameters are needed. Let’s see an example of creating a new VG called “geekpeek” and add /dev/sdb and /dev/sdc PV’s to it:
[root@foo ~]# vgcreate geekpeek /dev/sdb /dev/sdc Volume group "geekpeek" successfully created
[root@foo ~]# vgdisplay --- Volume group --- VG Name geekpeek System ID Format lvm2 Metadata Areas 2 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 2 Act PV 2 VG Size 2.99 GiB PE Size 4.00 MiB Total PE 766 Alloc PE / Size 0 / 0 Free PE / Size 766 / 2.99 GiB VG UUID oj2GS6-l5aE-6WNv-QPJy-r1pC-ahSQ-EzFiKc
--- Volume group --- VG Name vg_foo System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 14.51 GiB PE Size 4.00 MiB Total PE 3714 Alloc PE / Size 3714 / 14.51 GiB Free PE / Size 0 / 0 VG UUID 3n3nzs-dzHK-rApY-EApz-Zz2H-JQVP-TlcYfF
We can see that VG was successfully created. We can also see the full state of the “geekpeek” VG – VG size, Total PE, PE size, …
3. Extending Volume Groups
We can extend a Volume Group with “vgextend” command. The simple syntax is “vgextend name /dev/harddisk“. By extending VG you add PV’s to it and extend VG’s size. In our example we will extend VG called “geekpeek” from 2.99GB to 5.99GB by adding /dev/sdd PV:
[root@foo ~]# vgextend geekpeek /dev/sdd Volume group "geekpeek" successfully extended
[root@foo ~]# vgdisplay --- Volume group --- VG Name geekpeek System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 2 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 5.99 GiB PE Size 4.00 MiB Total PE 1533 Alloc PE / Size 0 / 0 Free PE / Size 1533 / 5.99 GiB VG UUID oj2GS6-l5aE-6WNv-QPJy-r1pC-ahSQ-EzFiKc
--- Volume group --- VG Name vg_foo System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 14.51 GiB PE Size 4.00 MiB Total PE 3714 Alloc PE / Size 3714 / 14.51 GiB Free PE / Size 0 / 0 VG UUID 3n3nzs-dzHK-rApY-EApz-Zz2H-JQVP-TlcYfF
4. Reducing Volume Groups
We can reduce a Volume Group with “vgreduce” command. The simple syntax is “vgreduce name /dev/harddisk“. By reducing VG you remove PV’s from it and reduce VG’s size. In our example we will reduce VG called “geekpeek” from 5.99GB to 2.99GB by removing /dev/sdd PV:
[root@foo ~]# vgreduce geekpeek /dev/sdd Removed "/dev/sdd" from volume group "geekpeek"
[root@foo ~]# vgdisplay --- Volume group --- VG Name geekpeek System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 2.99 GiB PE Size 4.00 MiB Total PE 766 Alloc PE / Size 0 / 0 Free PE / Size 766 / 2.99 GiB VG UUID i339tr-lqNb-OKra-1FE2-UZ82-A1TI-t8w7BT
--- Volume group --- VG Name vg_foo System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 14.51 GiB PE Size 4.00 MiB Total PE 3714 Alloc PE / Size 3714 / 14.51 GiB Free PE / Size 0 / 0 VG UUID 3n3nzs-dzHK-rApY-EApz-Zz2H-JQVP-TlcYfF
5. Splitting Volume Groups
We can split Volume Group with “vgsplit” command. The simple syntax is “vgsplit name newname /dev/harddisk“. By splitting VG you remove PV’s from it and reduce VG’s size. In our example we will split VG called “geekpeek” and create a new VG called “splitgeek“:
[root@foo ~]# vgsplit geekpeek splitgeek /dev/sdd New volume group "splitgeek" successfully split from "geekpeek"
[root@foo ~]# vgdisplay --- Volume group --- VG Name splitgeek System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 3.00 GiB PE Size 4.00 MiB Total PE 767 Alloc PE / Size 0 / 0 Free PE / Size 767 / 3.00 GiB VG UUID 1ZvPM3-3jgO-0t1e-r4I1-Sxw2-vhUM-clGQLg
--- Volume group --- VG Name geekpeek System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 2.99 GiB PE Size 4.00 MiB Total PE 766 Alloc PE / Size 0 / 0 Free PE / Size 766 / 2.99 GiB VG UUID oj2GS6-l5aE-6WNv-QPJy-r1pC-ahSQ-EzFiKc
--- Volume group --- VG Name vg_foo System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 14.51 GiB PE Size 4.00 MiB Total PE 3714 Alloc PE / Size 3714 / 14.51 GiB Free PE / Size 0 / 0 VG UUID 3n3nzs-dzHK-rApY-EApz-Zz2H-JQVP-TlcYfF
6. Merging Volume Groups
In the next step we will merge the split Volume Groups (VG’s) back together. We can merge VG’s with “vgmerge” command. The simple syntax is “vgmerge name1 name2“:
[root@foo ~]# vgmerge geekpeek splitgeek Volume group "splitgeek" successfully merged into "geekpeek"
[root@foo ~]# vgdisplay --- Volume group --- VG Name geekpeek System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 4 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 5.99 GiB PE Size 4.00 MiB Total PE 1533 Alloc PE / Size 0 / 0 Free PE / Size 1533 / 5.99 GiB VG UUID oj2GS6-l5aE-6WNv-QPJy-r1pC-ahSQ-EzFiKc
--- Volume group --- VG Name vg_foo System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 14.51 GiB PE Size 4.00 MiB Total PE 3714 Alloc PE / Size 3714 / 14.51 GiB Free PE / Size 0 / 0 VG UUID 3n3nzs-dzHK-rApY-EApz-Zz2H-JQVP-TlcYfF
7. Changing Volume Groups
We can change Volume Group parameters with “vgchange” command. The simple syntax is “vgchange name -parameter value“. By changing VG’s you can change VG’s parameters – check “vgchange –help” for more info. In our example we will change PE size of our VG called “geekpeek“:
[root@foo ~]# vgchange geekpeek -s 2048KB Volume group "geekpeek" successfully changed
[root@foo ~]# vgdisplay --- Volume group --- VG Name geekpeek System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 8 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 5.99 GiB PE Size 2.00 MiB Total PE 3066 Alloc PE / Size 0 / 0 Free PE / Size 3066 / 5.99 GiB VG UUID oj2GS6-l5aE-6WNv-QPJy-r1pC-ahSQ-EzFiKc
--- Volume group --- VG Name vg_foo System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 14.51 GiB PE Size 4.00 MiB Total PE 3714 Alloc PE / Size 3714 / 14.51 GiB Free PE / Size 0 / 0 VG UUID 3n3nzs-dzHK-rApY-EApz-Zz2H-JQVP-TlcYfF
We can see that we have successfully changed Total PE size of VG from 4.00MBiB to 2.00MiB.
8. Remaning Volume Groups
We can rename Volume Group with “vgrename” command. The simple syntax is “vgrename name1 name2“. In our example we will rename our VG called “geekpeek” to “renamegeek“:
[root@foo ~]# vgrename geekpeek renamegeek Volume group "geekpeek" successfully renamed to "renamegeek"
[root@foo ~]# vgdisplay --- Volume group --- VG Name renamegeek System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 9 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 5.99 GiB PE Size 2.00 MiB Total PE 3066 Alloc PE / Size 0 / 0 Free PE / Size 3066 / 5.99 GiB VG UUID oj2GS6-l5aE-6WNv-QPJy-r1pC-ahSQ-EzFiKc
--- Volume group --- VG Name vg_foo System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 14.51 GiB PE Size 4.00 MiB Total PE 3714 Alloc PE / Size 3714 / 14.51 GiB Free PE / Size 0 / 0 VG UUID 3n3nzs-dzHK-rApY-EApz-Zz2H-JQVP-TlcYfF
We can see that we have successfully renamed VG “geekpeek” to “renamegeek“.
9. Removing Volume Groups
We can remove Volume Groups (VG’s) with “vgremove” command. The simple syntax is “vgremove name“. In our example we will remove VG called “geekpeek“:
[root@foo ~]# vgremove geekpeek Volume group "geekpeek" successfully removed.
[root@foo ~]# vgdisplay
--- Volume group --- VG Name vg_foo System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 14.51 GiB PE Size 4.00 MiB Total PE 3714 Alloc PE / Size 3714 / 14.51 GiB Free PE / Size 0 / 0 VG UUID 3n3nzs-dzHK-rApY-EApz-Zz2H-JQVP-TlcYfF
Before you manage your Volume Groups make appropriate reconfiguration of the Logical Volumes! If not, you can loose or corrput your data!
2 Comments
Leave a Reply2 Pings & Trackbacks
Pingback: LVM - Physical Volume Management on CentOS 6 GeekPeek.Net
Pingback: LVM - Logical Volume Management on CentOS 6 GeekPeek.Net