LVM – Logical Volume Manager Architecture

I. LVM ARCHITECTURE

LVM is a tool for logical volume management which includes allocating disks, striping, mirroring and resizing logical volumes. With LVM, a hard drive or set of hard drives is allocated to one or more physical volumes. LVM physical volumes can be placed on other block devices which might span two or more disks.

  • The physical volumes are combined into logical volume group
  • The logical volume group can be divided into logical volumes, which are assigned mount points, such as /home and / and file system types, such as ext2 or ext3.
  • When “partitions” reach their full capacity, free space from the volume group can be added to the logical volume to increase the size of the partition.
  • When a new hard drive is added to the system, it can be added to the volume group, and partitions that are logical volumes can be increased in size.

The LVM architecture as below figure:



NOTE: LVM doesn’t know about disks, it know about physical volumes (PVs). If a PV is offline, logical volume that depend on it go offline as well. That is why you use RAID under the PV (software or hardware)

II. LVM  DEPLOYMENT – EXAMPLE

We have 2 disks and need to combine them into a logical volume as below figure:

1. Use the lsblk command to view your available disk devices and their mount points (if applicable) to help you determine the correct device name to use

[root@myDB ~]# lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 8G 0 disk

ââsda1 8:1 0 500M 0 part /boot

ââsda2 8:2 0 7.5G 0 part

ââvg_mydb-lv_root (dm-0) 253:0 0 6.7G 0 lvm /

ââvg_mydb-lv_swap (dm-1) 253:1 0 816M 0 lvm [SWAP]

sdb 8:16 0 9G 0 disk

sdc 8:32 0 9G 0 disk

 

2. Create physical volume on /dev/sdb and /dev/sdb

[root@myDB ~]# pvcreate /dev/sdb

[root@myDB ~]# pvcreate /dev/sdc

[root@myDB ~]# pvdisplay

--- Physical volume ---

PV Name /dev/sdb

VG Name vol-group

PV Size 9.00 GiB / not usable 4.00 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 2303

Free PE 0

Allocated PE 2303

PV UUID g5WgxB-12al-s5kF-WfMZ-GaBX-ffAC-4c5lBu

--- Physical volume ---

PV Name /dev/sdc

VG Name vol-group

PV Size 9.00 GiB / not usable 4.00 MiB

Allocatable yes

PE Size 4.00 MiB

Total PE 2303

Free PE 254

Allocated PE 2049

PV UUID z4fLMZ-e3Zx-d5L5-bate-IG3c-EexY-z8bSdV

 

3. Create logical volume group named “vol-group” using 2 physical volumes

[root@myDB ~]# vgcreate vol-group /dev/sdb /dev/sdc

[root@myDB ~]# vgdisplay

--- Volume group ---

VG Name vol-group

System ID

Format lvm2

Metadata Areas 2

Metadata Sequence No 2

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 1

Open LV 1

Max PV 0

Cur PV 2

Act PV 2

VG Size 17.99 GiB

PE Size 4.00 MiB

Total PE 4606

Alloc PE / Size 4352 / 17.00 GiB

Free PE / Size 254 / 1016.00 MiB

VG UUID z2LOVg-wZ9T-KT5c-G2eM-8Dwm-2bJU-lI8HTr

 

4. Create logical volume 18 G named “DATA” on logical volume group named “vol-group

[root@myDB ~]# lvcreate -L 18G -n DATA vol-group

[root@myDB ~]# lvscan

ACTIVE '/dev/vol-group/DATA' [17.00 GiB] inherit

 

5. Create filesystem for logical volume “DATA”

[root@myDB ~]# mkfs -t ext4 /dev/vol-group/DATA

[root@myDB ~]# mkdir /mnt/DATA

[root@myDB ~]# mount /dev/vol-group/DATA /mnt/DATA

[root@myDB ~]# df -h /mnt/DATA

 

6. Modify /etc/fstab to enable automatically mount when the system boots

[root@myDB ~]# vi /etc/fstab

#Put this into the end of the file

/dev/vol-group/DATA     /mnt/DATA     ext4     rw,noatime     0 0

II. LVM TROUBLESHOOTING

Remove bad disk from group: vgreduce –removemissing —force name_of_group

Add a new physical volumes to existing group: vgextend name_of_group name_of_device

About Terri

System Administrator @Netpower Datacenter

Posted on 25.09.2015, in Linux, Technical Articles and tagged , , . Bookmark the permalink. 1 Comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: