Tag Archives: how to create volume group

LVM commands tutorial : Part 2 : Volume group (vgcreate, vgdisplay, vgscan)

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 :

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 /etc/lvmtab file.

Command: vgcreate

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.

Command: vgdisplay

Same as pvdisplay command, 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 -s, -e, -l, -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.

Command: vgscan

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 :

  • -a Scan all available PV paths.
  • -B Write all persistent and legacy paths to /etc/lvmtab file
  • -f vg_name Force to update entries of existing VG in /etc/lvmtab with updated info, if any
  • -k Avoid probing disks. Build file from kernel known structure.
  • -N Populate the file with persistent DSF names
  • -p Preview mode only. It won’t update lvmtab file
  • -v verbose 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.