3. Volume Group Administration

  Logical Volume Manager

< 2 LVM Logical Volumes | Commands | 4 Thin Provisioning >

15. Overview of PV Administration

Commands

Create a Physical Volume: pvcreate

pvcreate /dev/sda1

List available Block devices: lvmdiskscan

lvmdiskscan

Display Physical Volumes: pvdisplay

Displays information about a PV

pvdisplay /dev/sda1

List Physical Volumes: pvs & pvscan

pvs
pvscan

Prevent/Allow Allocation of a Physical Volume: pvchange

Prevent (n) or Allow (y) anyone from/to using the PV in a Logical Volume

# Prevent Usage
pvchange -x n /dev/sda1
# Allow Usage
pvchange -x y /dev/sda1

Resize a Physical Volume: pvresize

This probably works best with virtual disks.  Use after the drive itself has been modified to add additional space.

pvresize

Remove a Physical Volume: pvremove

Will remove the device from pvs (pvscan?) lists. (Removes label information from the drive metadata)

* Must be first removed from any volume groups prior to running this command.  See vgreduce below.

pvremove /dev/sda1

Remove a disk from a Volume Group: vgreduce

vgreduce /dev/VOL-GROUP /dev/sdb1

 

16. Volume Group Creation with Options

vgcreate Options

Switch Description
-s Size of extents (Default 4MB)
-p Maximum Physical Volumes
-l Maximum Logical Volumes
Switch Description

 

17. Adding, Removing, Displaying  & Scanning Physical Volumes to a Volume Group

Add a PV to a Volume Group: vgextend

vgextend VOL-GROUP /dev/sdc1

Display Volume Group Information: vgs & vgdisplay

vgs
vgdisplay

Scan disks for Volume Groups: vgscan

  • Running this command might take some time
vgscan

Remove a PV from a Volume Group: vgreduce

  • Must first remove any Logical Volumes that might be using the PV
rgreduce VOL-GROUP /dev/sdc1

Activate / Deactivate a Volume Group: pvchange

See above also

Switch Description
-a y Activate the Volume Group
-a n Deactivate the Group
Prevents mounting of its LVs
-x y Allow Allocation of Logical Volumes
-x n Disallow Allocation of Logical Volumes

 

18. Changing the Parameters of a Volume Group

https://www.udemy.com/course/a-complete-guide-on-linux-lvm/learn/lecture/13062220#overview

Stopped taking notes here 🙁

 

22. Moving a VG from one server to another

https://www.udemy.com/course/a-complete-guide-on-linux-lvm/learn/lecture/13062286#overview

Move VOL-GROUP (sdc1, sdd1, sde1) From Server1 to Server2

  • Make the disks visible on Server2
  • Server1: Make the VOL-GROUP inactive
    • pvchange -x n
  • Server1: vgexport VOL-GROUP
  • Server2: vgscan
  • Server2: vgimport

23. vgexport & vgimport

Lab: Migrate a single disk /sdg1 vol group.

Server1: Create the PV, VG, LV, add files and export

# create the volume group (VG)
pvcreate /dev/sdg1
vgcreate /dev/VG /dev/sdg1

# create 2 logical volumes
lvcreate -L 100G -n LV1 /dev/VG
lvcreate -L 100G -n LV2 /dev/VG

# format LV1
mkfs -t ext4 /dev/VG/LV1

# mount LV1
mkdir /mnt/mylv1
mount /dev/VG/LV1 /mnt/mylv1

# create some test files
cd /mnt/mylv1
touch test1 test2 test3
ll

# Attempt to deactivate the VG
vgchange -a n /dev/VG
  Logical volume /VG/LV1 contains a filesystem in use.
  Can't deactivate volume group "VG" with 1 open logical volume(s)

# unmount the LV, deactivate and export
umount /mnt/mylv1
vgchange -a n /dev/VG
vgexport /dev/VG
# pvscan for this VG will show it is in an exported state
pvscan
  PV /dev/sdg1  is in exported VG VG (500 GiB / 400 GiB free)
# get the UUID of the disk
vgdisplay -v VG
  ...
  PV NAME   /dev/sdg1
  PV UUID   gobblty-gook-lots-o-stuff-here-long-name

Move the drives to Server2

# Verify the PV is available
fdisk -l
pvscan
 PV /dev/sdd1 is in exported VG VG (500 GiB / 400 GiB free)
# note: ^ the disk id has changed from /sdg1 to sdd1

#import the volume group and activate
import /dev/VG
  Volume group "VG" successfully imported
vgchange -x y /dev/VG
  2 logical volume(s) in volume group "VG" now active
vgdisplay -v VG
  ...
  PV NAME /dev/sdd1
  PV UUID gobblty-gook-lots-o-stuff-here-long-name

# mount the logical volume
mkdir /mnt/mynewlv1
mount /dev/VG/LV /mnt/mynewlv1

# test
cd /mnt/mynewlv1
ll
  test1
  test2
  test3

 

24. LVM Mirroring

https://www.udemy.com/course/a-complete-guide-on-linux-lvm/learn/lecture/13062332#overview

Requires minimum 2 drives.  Data is copied to multiple drives at the same time.

  • Uses 2x as much drive space.
  • -m1 = 1 mirror copy (total spaced used = 2x -L)
  • -m2 = 2 mirror copies (total space used = 3x -L)
lvcreate --type mirror -L50G -m1 -n LV VG

25. LV Extension

How to extend (increase the size) of an existing, formatted Logical Volume

  • Verify there is enough space in the VG
  • Extend the LV’s size
  • Extend the LV’s file system
# Check the size of the LV's Volume Group to make sure enough free space is available.# find the LVs VG
lvdisplay VG# show the used space of the VGs
vgs# extend the size of the LV
lvextend -L +SIZE /dev/VG/LV# Now resize the filesystem to match the size of the disk
resize2fs /dev/VG/LV

 

LEAVE A COMMENT