Ubuntu Logical Volume Management Review

1 Objectives

Review the LVM configuration of our Linux server post install

2 Logical Volume Management host Information

2.1 Review the Physical Volume

$ sudo -s
# pvs

Example output. Your host may look a bit different:

root@host1:~# pvs
  PV         VG     Fmt  Attr PSize    PFree   
  /dev/sda2  ganeti lvm2 a--  <255.50g <192.50g
# pvscan
root@host1:~# pvscan
  PV /dev/sda2   VG ganeti          lvm2 [<255.50 GiB / <192.50 GiB free]
  Total: 1 [<255.50 GiB] / in use: 1 [<255.50 GiB] / in no VG: 0 [0   ]
# pvdisplay

Some sample output. Your host may differ somewhat:

  --- Physical volume ---
  PV Name               /dev/nvme0n1p2
  VG Name               ganeti
  PV Size               237.97 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              60920
  Free PE               55800
  Allocated PE          5120
  PV UUID               HQFfVZ-OgxW-7Qdv-tDno-iQGb-h9c1-ddjANV

2.2 Review the Volume Group

# vgs

And, sample output:

root@host1:~# vgs
  VG     #PV #LV #SN Attr   VSize    VFree   
  ganeti   1   4   0 wz--n- <255.50g <192.50g
# vgscan
root@host1:~# vgscan
  Reading volume groups from cache.
  Found volume group "ganeti" using metadata type lvm2
# vgdisplay

Sample output:

  --- Volume group ---
  VG Name               ganeti
  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               <237.97 GiB
  PE Size               4.00 MiB
  Total PE              60920
  Alloc PE / Size       5120 / 20.00 GiB
  Free  PE / Size       55800 / <217.97 GiB
  VG UUID               kpdINs-8pwO-efdB-L5ZE-Azef-hb9x-WIGbD5

2.3 Review the Logical Volumes

# lvs

And, sample output:

root@host8:~# lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root ganeti -wi-ao---- 10.00g                                                    
  var  ganeti -wi-ao---- 10.00g   
# lvscan
root@host8:~# lvscan
  ACTIVE            '/dev/ganeti/root' [10.00 GiB] inherit
  ACTIVE            '/dev/ganeti/var' [10.00 GiB] inherit
# lvdisplay

Sample output:

  --- Logical volume ---
  LV Path                /dev/ganeti/root
  LV Name                root
  VG Name                ganeti
  LV UUID                qfhbhE-xwci-HfqR-leJN-tbC0-ZGTZ-cfWK3J
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2021-10-23 06:17:32 +0000
  LV Status              available
  # open                 1
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/ganeti/var
  LV Name                var
  VG Name                ganeti
  LV UUID                l6WpYZ-pzxr-giF9-Jrb1-yU2M-1zKc-eZ1XBb
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2021-10-23 06:17:33 +0000
  LV Status              available
  # open                 1
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

As you can see this is quite a bit of information. Include where the actual logical volume resides in your filesystem (/dev/ganet/).

2.4 Review Available LVM Commands

Feel free to explore the various Logical Volume Management commands available to you. In Linux if you start a command and the press the left TAB key twice quickly it will autocomplete with all available commands in your path that start with the letters you have typed. For instance:

Physical Volume

# pv    : double left tab to see all commands starting with "pv" on your host
...
pvchange   pvck       pvcreate   pvdisplay  pvmove     pvremove   pvresize   pvs        pvscan

Volume Group

# vg    : double left tab to see all commands starting with "vg" on your host
...
vgcfgbackup    vgck           vgdisplay      vgimport       vgmknodes      vgrename       vgsplit
vgcfgrestore   vgconvert      vgexport       vgimportclone  vgreduce       vgs            
vgchange       vgcreate       vgextend       vgmerge        vgremove       vgscan 

Logical Volumes*

# lv    : double left tab to see all commands starting with "lv" on your host
...
lvchange     lvdisplay    lvmconf      lvmdump      lvmsadc      lvremove     lvs          
lvconvert    lvextend     lvmconfig    lvmetad      lvmsar       lvrename     lvscan       
lvcreate     lvm          lvmdiskscan  lvmpolld     lvreduce     lvresize  

Obtain More Information

And, now, if you were interested in knowing what a command does you can simply type:

# man <command>

So, if, for instance, you wanted to see what all the options there are available and what they do for the lvscan command you could type:

# man lvscan

And, most commands let you see a short-form help screen if you type:

# <command> --help

So, in the case of lvscan that would be:

# lvscan --help

this will scroll off your screen, so you need to use a pipe to redirect the output to a pager command like less. Try doing:

# lvscan --help | less

You can press the SPACE BAR to move forward. You can press “b” to go back and “q” to exit from the command output.