Linux Disk Management with LVM

  • By Megha Thorat
  • August 3, 2021
  • Linux

Logical Volume Management:

LVM is a method of manage storage devices and space logically (virtually) rather than physically, it gives more flexibility than the conventional partitioning system to manage volumes.

Today storage technology plays a very important role in any type of computing device. On a storage device, total system performance is dependent because it required storing all important data. So many storage devices are available in the market but to store large databases use a hard disk. Hard disk available in PATA (Parallel Advanced Technology Attachment), SATA (Serial Advanced Technology Attachment), SSD (Solid State Drive)

Today PATA has become the very old type of storage device, SSD is one of the best but it is not available in a higher size to store large databases of servers. So SSD is regularly used to store large databases of servers.

To manage SATA storage devices various mechanisms are available in each type of OS. In RHEL servers one of the most popular technology available that is LVM.

 

For Free Demo classes Call:7798058777
Registration Link: Click Here!

Why LVM:

Conventional storage device work on magnetic storage media which have a platter, read-write head, motor, etc. if we format this type of devices multiple times then it directly affect on hard disk life.

LVM is a method of manage storage devices and space logically or virtually rather than physically partitioning, it gives more flexibility than the conventional partitioning system to manage volumes.

 

LVM is a very flexible and helpful technology for system administrators to manage storage devices.

 

LVM provides the following features:

  1. Convert physical disk into a logical disk.
  2. Easy way to create removes partition any time.
  3. We can extend or shrink partition any time.
  4. It mange the disk virtually so it does not affect on hard disk storage mechanism.
  5. We can combine multiple hard disks into one partition.
  6. At the time of resizing LVM downtime is very low so increase the availability of data.

 

LVM Management: 

To manage LVM first need to understand the following 3 steps:

  1. Physical Volume (PV)
  2. Volume Group (VG)
  3. Logical Volume (LV)

For creating and use logical partition we need to go through the above three steps.

  • Physical Volume (PV) :

Physical Volume generally creates from the physical Partition of the hard disk.

 

  • Volume Group (VG):

The volume group is creating from one or more physical volumes. In short, we can say VG is a collection of physical volume. VG takes space from the physical volume and stores it in the format of Physical Extend (PE), by default 1 PE size is 4 MB.

Eg.

If we create VG from the 100 MB PV then VG divides that 100 MB space into 25 (fix size storage segment) parts that are called Physical Extend (PE).


For Free Demo classes Call:7798058777
Registration Link: Click Here!

  • Logical Volume (LV):

Logical Volume creates from the volume group. LV is an actual partition that we can use like a physical partition or format, mount, and store database, but it is the total virtual mechanism to manage partitions.

Steps for LVM Management:

First, create a physical partition from the available hard disk. In the following scenario, we assume we have /dev/sdb hard disk.

Step I: create a physical partition

 

For show available hard disk list:

# fdisk   -l

 

For Create Physical Partition from available physical hard disk.

# fdisk      /dev/sdb

 

Create new partition

: n ( Press Enter – for creating partition )

: p ( Press Enter – for default Primary partition )

: 1 ( Press Enter – for default First partition )

: ( Press Enter – for default First Sector value )

: +5G     ( Press Enter – to create 5 GB disk partition )

: t ( Press Enter – for change partition type )

: 1 ( Press Enter – for select partition )

: 82 ( Press Enter – for set LVM id to created partition )

: p ( Press Enter – for verify created partition )

: w ( Press Enter – for write partition table )

 

For show partition list of /dev/sdb

# fdisk   -l   /dev/sdb

 

Step II: Create Physical Volume (PV)

Step 1 : For create PV

# pvcreate /dev/sdb1

 

Step 2 :  For Display PV

# pvdisplay        /dev/sdb1 

 

For Free Demo classes Call:7798058777
Registration Link: Click Here!

Step III: Create Volume Group (VG)

 

Step 1: For Create Volume Group default PE size

# vgcreate engineering /dev/sdb1

 

Step 2: For display volume group

 # vgdisplay         engineering

 

OR

 

For Create VG with Specific PE (physical Extends) Size

# vgcreate -s    8    engineering       /dev/sdb1

 

Step IV: Create Logical Volume (LV)

 

Step1: For Create LV with Specific PE (physical Extends) Size 

# lvcreate -l    100      –n    /dev/engineering/comp

 

OR

 

Step 2: For Create LV with Specific MB Size 

# lvcreate -L    100      –n     /dev/engineering/comp

 

Step 3: For display LV

# lvdisplay /dev/engineering/comp

 

Step V: Create a file system on LV Partition

 

Step 1: For create file system on LV comp

# mkfs.ext4      /dev/engineering/comp

 

Step 2: For permanent mount partition

# mkdir     /comp1

# vim       /etc/fstab 

/dev/engineering/comp     /comp1    ext4     defaults     0 0 

: wq 

 

# mount    -a

# mount

# df      -h 

 

Step VI: Resize VG

 

For resize, VG create PV and then extend VG

Step 1: For extend VG

# vgextend engineering     /dev/sdb2 

For Free Demo classes Call:7798058777
Registration Link: Click Here!

Step 2: For reduce VG

# vgreduce engineering    /dev/sdb2 

 

Step VII: Resize LV

 

Step 1: For extend LV with 100 MB 

# lvextend     -L   +200   /dev/engineering/comp

# lvdisplay /dev/engineering/comp

 

Step 2: For reduce LV with 50 MB

# lvreduce     -L   -200    /dev/engineering/comp 

# lvdisplay /dev/engineering/comp

 

OR 

 

Step 1: For extend LV with Number of PE

# lvextend     -l   +50   /dev/engineering/comp

# lvdisplay /dev/engineering/comp

 

Step 2: For reduce LV with Number of PE 

# lvreduce     -L   -50    /dev/engineering/comp 

# lvdisplay /dev/engineering/comp

 

Step VIII: Remove LV, VG, PV

 

Step 1: Remove Permanent Mounting Record

# vim /etc/fstab 

Delete permanent mounting record line.

:wq  (write & quit)

 

Step 2: For unmounting mounted directory

# umount    /comp1

 

Step 3: For Remove LV

# lvremove     /dev/engineering/comp

# lvdisplay      /dev/engineering/comp

 

Step 4: For Remove VG

# vgremove     engineering

# vgdisplay       engineering

For Free Demo classes Call:7798058777
Registration Link: Click Here!

Step 5: For Remove PV

# pvremove     /dev/sdb1

# pvdisplay      /dev/sdb1

 

Step 6: For Remove Partition

# fdisk     /dev/sdb 

:d ( Press Enter – for delete partition )

:1 ( Press Enter – for select partition number to delete )

:p ( Press Enter – for show partition )

:w ( Press Enter – for write changes partition table )

 

Step 7: For Display Partition List

 

# fdisk    -l        /dev/sdb 

 

In this article we create physical volume from physical partition, create a volume group from physical volume and logical volume from the volume group, mount LV’s as per the required file system or directory. LVM very flexible management system without this technology we got very limited options for manages disk storage space. So it’s a very popular, Flexible, and powerful technology Linux operating system to manage disk space.  Technology in Linux operating system to manage disk space.

 

Author:

Dahatonde, Abhihjeet

| SevenMentor Pvt Ltd.

Call the Trainer and Book your free demo Class for now!!!

© Copyright 2021 | Sevenmentor Pvt Ltd.

Submit Comment

Your email address will not be published.

*
*