LVM Technology

Introduction

LVM, or Logical Volume Management, is a storage device management technology that gives users the power to pool and abstract the physical layout of component storage devices for flexible administration. Utilizing the device mapper Linux kernel framework, the current iteration, LVM2, can be used to gather existing storage devices into groups and allocate logical units from the combined space as needed.

The main advantages of LVM are increased abstraction, flexibility, and control. Logical volumes can have meaningful names like “databases” or “root-backup”. Volumes can also be resized dynamically as space requirements change, and migrated between physical devices within the pool on a running system or exported. LVM also offers advanced features like snapshotting, striping, and mirroring.

In this guide, you’ll learn how LVM works and practice basic commands to get up and running quickly on a bare metal machine.

 

LVM Architecture and Terminology

Before diving into LVM administrative commands, it is important to have a basic understanding of how LVM organizes storage devices and some of the terminology it employs.

 

LVM Storage Management Structures

LVM functions by layering abstractions on top of physical storage devices. The basic layers that LVM uses, starting with the most primitive, are:

  • Physical Volumes: The LVM utility prefix for physical volumes is PV.. This physicallyl blocks devices or other disk-like devices (for example, other devices created by device mapper, like RAID arrays) and are used by LVM as the raw building material for higher levels of abstraction. Physical volumes are regular storage devices. LVM writes a header to the device to allocate it for management.

  • Volume Groups: The LVM utility prefix for volume groups is VG.. LVM combines physical volumes into storage pools known as volume groups. Volume groups abstract the characteristics of the underlying devices and function as a unified logical device with combined storage capacity of the component physical volumes.

  • Logical Volumes: The LVM utility prefix for logical volumes is LV generic LVM utilities might begin with LVM. A volume group can be sliced up into any number of logical volumes. Logical volumes are functionally equivalent to partitions on a physical disk, but with much more flexibility. Logical volumes are the primary component that users and applications will interact with.

LVM can be used to combine physical volumes into volume groups to unify the storage space available on a system. Afterwards, administrators can segment the volume group into arbitrary logical volumes, which act as flexible partitions.

What is LVM Simple Way ?

LVM (Logical Volume Manager) allows you to manage disk space flexibly by abstracting physical storage into logical volumes. You can resize, combine, and manage volumes more easily than with traditional partitions.

  1. Basic LVM Workflow Overview

Step

Task

Command

1

Create physical volume (PV)

pvcreate /dev/sdX

2

Create volume group (VG)

vgcreate my_vg /dev/sdX

3

Create logical volume (LV)

lvcreate -L 10G -n my_lv my_vg

4

Format LV with a file system

mkfs.ext4 /dev/my_vg/my_lv

5

Mount the LV

mount /dev/my_vg/my_lv /mnt

  1. Physical Volume (PV) Commands

Command

Description

pvcreate /dev/sdX

Initialize a physical volume

pvdisplay

Show detailed info about PVs

pvs

Show a summary of all PVs

pvscan

Scan all disks for PVs

pvremove /dev/sdX

Remove a physical volume (wipe LVM data)

  1. Volume Group (VG) Commands

Command

Description

vgcreate my_vg /dev/sdX

Create a volume group

vgextend my_vg /dev/sdY

Add PV to VG

vgreduce my_vg /dev/sdY

Remove PV from VG

vgs

Show summary of all VGs

vgdisplay

Detailed info about VGs

vgremove my_vg

Remove a VG

vgchange -a y

Activate all volume groups

vgchange -a n

Deactivate all volume groups

  1. Logical Volume (LV) Commands

Command

Description

lvcreate -L 10G -n my_lv my_vg

Create a logical volume

lvextend -L +5G /dev/my_vg/my_lv

Extend a logical volume

lvresize -L 15G /dev/my_vg/my_lv

Resize LV to specific size

lvreduce -L 8G /dev/my_vg/my_lv

Reduce LV size ( careful!)

lvremove /dev/my_vg/my_lv

Remove an LV

lvdisplay

Detailed info about LVs

lvs

Show summary of all LVs

lvscan

Scan for logical volumes

 

6. Resizing File Systems with LVM

⚠️ Always backup before resizing!

 Extend Logical Volume and File System:

				
					sudo lvextend -L +5G /dev/my_vg/my_lv sudo resize2fs /dev/my_vg/my_lv # For ext4
				
			
  1. Removing LVM Components

Task

Command

Unmount the LV

umount /mnt

Remove LV

lvremove /dev/my_vg/my_lv

Remove VG

vgremove my_vg

Remove PV

pvremove /dev/sdX

 

  1. Useful Monitoring and Status Commands

Command

Description

lsblk

Lists all block devices (including LVMs)

df -h

Disk space usage (mounted volumes)

mount

Check mounted file systems

blkid

Display block device UUIDs and types

lvs, vgs, pvs

Show LVM components in summary

 

 

LVM PPT Slide

				
					Commnd Start
.............

1.sudo fdisk -l : find new drive
or lsblk or df -h

2.sudo pvscan

3.sudo fdisk /dev/sdb
n
p
1
[enter]
[enter]
t
8e
w
				
			
				
					 pvcreate /dev/sdb1 <create a LVM physical volume on the partition we just created>
				
			
				
					Vg Create Commnd
................

Create volume Group
....

vgcreate vgapps /dev/sdb1 /dev/sdb2
				
			
				
					Lv Create Commnd
.................

lvcreate -L 1G -n app1-lv vgapps

lvcreate -L  1G -n app2-lv vgapps

lvdisplay <Checking LV Create Or Not>
				
			
				
					Formating Commnd
.................

mkfs.ext4 /dev/vgapps/app1-lv
				
			
				
					Create a mount point and then mount the volume somewhere you can use it.

mkdir /mnt/app1
mount /dev/vgapps/app1-lv /mnt/app1
				
			

Checking All HDD Disk Space Commnd – df -th

HDD Add to Fstab Configuration

cat /etc/mtab 

Space Extend 

Add New HDD Disk  Then Follow Step 

fdisk /dev/sdc

n = create new partition
p = creates primary partition
1 = makes partition the first on the disk


t = change partition type
8e = changes to LVM partition type


p = view partition setup so we can review before writing changes to disk
w = write changes to disk

pvcreate /dev/sdbc <create a LVM physical volume on the partition we just created

				
					6 – vgextend vgapps /dev/sdc1

Extend Logical Volume

7 – lvextend -L +1G /dev/vgapps/app1-lv

8 – resize2fs /dev/vgapps/app1-lv
				
			
				
					How To Cheking Linux Ubantu Disk Status 
.......................................
lsblk
fdisk -l
df -hT
lsblk -f <Cheking Formating Partition >
mount -av <cheking Mounting>
				
			
				
					How to check hdd?
.................
sudo fdisk -l

How to check partition MBR/GPT?
gdisk /dev/sda
lsblk

 

 

How to create partition?
.........................
sudo fdisk /dev/sda
help- m
n
enter
enter
+20G
p- print
w-save
fdisk -l

 

 

How to format partition?
.........................
mkfs.ext4 /dev/sda
lsblk -f -chcek format or not partition


How to mount partiton?
......................
sudo mount /dev/sda /<mount folder>
check – sudo mount
lsblk
				
			
				
					How To Cheking Linux Ubantu LVM Status
......................................
pvdisplay
vgdisplay
lvdisplay
lvs
vgs
pvs
lvscan
pvscan
vgscan

 

How To Remove Linux Ubantu LVM
..............................
lvremove /dev/nextcloud/nextcloudlv

 

How to vgextended Commnd
........................

vgextend vgapps /dev/sdc1

 

Extend Logical Volume
.....................

 lvextend -L +1G /dev/vgapps/app1-lv

 resize2fs /dev/vgapps/app1-lv
				
			
				
					How To Cheking Linux Ubantu Disk Status?
.........................................
lsblk
fdisk -l
df -hT
lsblk -f                                              <Cheking Formating Partition >
mount -av                                             <cheking Mounting>


How To Create Linux Ubantu LVM?
...............................
Step#01 fdisk /dev/sdb                                        <Go To HDD >
Step#02 n, p, t, 8e, w                                        <New Partion Create>
Step#03 partprobe /dev/sdb                                    <Karnel Infom For New HDD Partition>
Step#04 pvcreate /dev/sdb1                                    <Create Pv>
Step#05 vgcreate nextcloud /dev/sdb1                          <Create VG>
Step#06 lvcreate -L 500G -n nextcloud nextcloudlv             <Create LV>
Step#07 mkfs.ext4 /dev/mapper/nextcloud-nextcloudlv           <Formating>
Step#08 mount /dev/mapper/nextcloud-nextcloudlv /var/www/html <Create Mount Point For Use Disk Space>
Step#09 df -hT                                                <For Checking Mount>
Step#10 cat/etc/mtab                                          <Copy Full Path nextcloud-nextcloudlv For Entry Fstab>
Step#11 nano /etc/fstab
Step#11 /dev/mapper/nextcloud-nextcloudlv /var/www/html ext4   errors=remount-ro 0 1 <Paste This Line Fstab Then Save>



How To Cheking Linux Ubantu LVM Status?
........................................
pvdisplay
vgdisplay
lvdisplay
lvs
vgs
pvs
lvscan
pvscan
vgscan



How To Remove Linux Ubantu LVM?
...............................
lvremove /dev/nextcloud/nextcloudlv
				
			
				
					Ubantu LVM Root Partion Extend
...............................

1.sudo fdisk -l : find new drive
or lsblk or df -h

2.sudo pvscan

3.sudo fdisk /dev/sdb
n
p
1
[enter]
[enter]
t
8e
w

5.lsblk and see /dev/sdb1 added
if /dev/sdb1 is not seen then reboot before continuing further

6.sudo pvcreate /dev/sdb1

7.sudo vgdisplay : look for VG Name value (ubuntu-vg, vg00 etc)

8.sudo vgextend ubuntu-vg /dev/sdb1

9.sudo pvscan

10.sudo lvdisplay : look for LV Path value

11.sudo lvextend /dev/ubuntu-vg/ubuntu-lv /dev/sdb1
OR
sudo lvextend -L +5G /dev/my_vg/my_lv sudo resize2fs /dev/my_vg/my_lv # For ext4


12.sudo resize2fs /dev/ubuntu-vg/ubuntu-lv

lsblk will now show your size increase