Series of the tutorial to learn LVM commands. In this part of the tutorial, learn how to create volume groups, and see details of it (vgcreate, vgdisplay, vgscan).
Today we are starting with part two of the LVM command tutorial series. Other series posts can be found here :
- Part 1 : Physical Volume (pvcreate, pvdisplay)
- Part 1 : Physical Volume (pvchange, pvmove)
- Part 2 : Volume group (vgcreate, vgdisplay, vgscan)
- Part 2 : Volume group (vgextend, vgreduce, vgexport, vgimport)
- Part 2 : Volume group (vgcfgbackup, vgcfgrestore, vgchange)
- Part 2 : Volume group (vgremove, vgsync)
- Part 3 : Logical volume
- Part 4 : Conclusion
This is the first post of part two which will be taking care of volume group activities. In the following writeup, we are going to see commands on how to create a volume group, how to view details of the volume group and how to scan volume groups to build new
As we all know volume group i.e. VG is a collection if PV. Refer to LVM legends for better understanding. VG creation is the next necessary step after PV creation to use disk space in mount points. Since in Unix everything is a file, to manage VG, the kernel creates
/dev/vgname/group file. This file represents VG in the kernel. Let us see how to create VG from a bunch of available PV. Post Mar 2008 releases of HPUX creates group file automatically with
vgcreate command. But we will see here how to make one.
First, create a directory with the desired name of your VG for example. let’s say
testvg is our VG name. After that using
mknod command creates a special group file. In command, you need to supply major and minor numbers.
# mkdir /dev/testvg # mknod /dev/testvg/group c major 0xminor
major number: 64 for version 1.0 VG and 128 for version 2.0 VG
minor number: Its hexadecimal number. 0xnn0000 for v1.0 and 0x0000 for v2.0 where nn/nnn is unique number.
Now that special file is generated go-ahead to create VG
# vgcreate /dev/testvg /dev/disk/disk3 /dev/disk/disk4 Volume group "/dev/testvg" has been successfully created. Volume Group configuration for /dev/testvg has been saved in /etc/lvmconf/testvg.conf
vgcreate can be run with a single PV argument too. This command has several options as below :
- -V 1.0 To decide version.
- -s PE_size Size of PE to be used in MB. Default is 4MB
- -e max_PE Max PE per PV. Default is 1016
- -l max_lv Max number of LV per VG. Default is 255
- -p max_pv Max number of PV per VG. Default is 255
- -S vg_size Max future size of VG. Only in v2.0.
The above options can be supplied to command with proper values but it’s not mandatory. If not supplied then their respective values will be taken into consideration while creating VG. Changes in parameters with these options can be seen in
vgdisplay output which you can see incoming section.
vgdisplay is used to view VG details.
vgdisplay command can be run with
-v option to get more detailed output. If run without
-v option then it will show output like below but PV details portion won’t be there.
# vgdisplay -v vg_new --- Volume groups --- VG Name /dev/testvg VG Write Access read/write VG Status available Max LV 255 Cur LV 0 Open LV 0 Max PV 16 Cur PV 2 Act PV 2 Max PE per PV 6000 VGDA 2 PE Size (Mbytes) 32 Total PE 26 Alloc PE 0 Free PE 26 Total PVG 0 Total Spare PVs 0 Total Spare PVs in use 0 --- Physical volumes --- PV Name /dev/disk/disk3 PV Status available Total PE 10 Free PE 10 Autoswitch On PV Name /dev/disk/disk4 PV Status available Total PE 10 Free PE 10 Autoswitch On
In the above output, you can see PE Size (Mbytes), Max PE per PV, Max LV, Max PV fields which can be altered with options
-p arguments in
vgcreate command we saw above. The above output is pretty self-explanatory. It also shows PV details which are part of this VG.
This command used for scanning all available PVs to get information on VG and related LV’s and rebuild
/etc/lvmtab file. This command used the below options :
-aScan all available PV paths.
-BWrite all persistent and legacy paths to
-fvg_name Force to update entries of existing VG in
/etc/lvmtabwith updated info, if any
-kAvoid probing disks. Build file from kernel known structure.
-NPopulate the file with persistent DSF names
-pPreview mode only. It won’t update lvmtab file
-vverbose mode. Prints messages in the console.
# vgscan -v /dev/vg00 /dev/disk/disk1_p2 /dev/disk/disk2_p2 Scan of Physical Volumes Complete.
Normally we use
vgscan -v only. After this command, you can verify the timestamp of
/etc/lvmtab file to verify it’s been updated.
This concludes the first 3 commands of VG. In the next post, we will see how to extend the volume group, how to reduce the volume group and how to export/import volume groups.