Home » Linux » How To » How to create LVM

How to create LVM

What is LVM ?

Full form of LVM is Logical Volume Management,  which includes allocating disks, striping, mirroring and resizing logical volumes.
Single primary disk can be devided into multiple logical drive also multiple disk pool can be devided into multiple logical group.

Source : https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s1-lvm-intro-whatis.html

Its divide into logical partition


Now you can be confused that why RAID ?

Difference between RAID and LVM

 1.  RAID is used for redundancy.  LVM is a way in which you partition the hard disk logically and it contains its own advantages.
 2.  A RAID device is a physical grouping of disk devices in order to create a logical presentation of one device to an Operating System for redundancy or performance or a combination of the two.  LVM is a logical layer that that can be anipulated in order to create and, or expand a logical presentation of a disk device to an Operating System.
 3.  RAID is a way to create a redundant or striped block device with redundancy using other physical block devices.  LVM usually sits on top of RAID blocks or even standard block devices to accomplish the same result as a partitioning, however it is much more flexible than partitions. You can create multiple volumes crossing multiple physical devices, remove physical devices without loosing data, resize the volumes, create snapshots, etc
 4.  RAID is either a software or a hardware technique to create data storage redundancy across multiple block devices based on required RAID levels.  LVM is a software tool to manage large pool of storage devices making them appear as a single manageable pool of storage resource. LVM can be used to manage a large pool of what we call Just-a-bunch-of-Disk (JBOD) presenting them as a single logical volume and thereby create various partitions for software RAID.
 5.  RAID is NOT any kind of Data backup solution. Its a solution to prevent one of the SPOFs (Single Point of Failure) i.e. DISK failure. By configuring RAID you are just providing an emergency substitute for the Primary disk. It NEVER means that you have configured DATA backup.  LVM is a disk management approach that allows us to create, extend, reduce, delete or resize the volume groups or logical volumes.


Now you should have clear idea abou LMV & RAID, basically you are working with physical disk its is RAID when your are working with disk partition it is LVM

Now lets start how to create LVM

Get available physical disk attached to the system

#df -h
[root@bivas ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda 15G 12G 2.7G 81% /
none 1.0G 4.0K 1.0G 1% /dev
none 1.0G 0 1.0G 0% /dev/shm

Change the partition Type to LVM using fdisk command

Partition type to be set is 8e

Disk /dev/sda: 300.0 GB, 299966445568 bytes
255 heads, 63 sectors/track, 36468 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a1981
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 36469 292422656 8e Linux LVM

#1 Creating Physical Volume

Now we prepare our new partitions for LVM:

# pvcreate /dev/sda1 /dev/sdb1
Physical volume ”/dev/sda1″ successfully created
Physical volume ”/dev/sdb1″ successfully created

Now type the command pvdisplay to view our physical volumes

server1:~# pvdisplay
 — NEW Physical volume —
 PV Name /dev/sda1
 VG Name
 PV Size 23.29 GB
 Allocatable NO
 PE Size (KByte) 0
 Total PE 0
 Free PE 0
 Allocated PE 0
 PV UUID G8lu2L-Hij1-NVde-sOKc-OoVI-fadg-Jd1vyU
— NEW Physical volume —
 PV Name /dev/sdb1
 VG Name
 PV Size 23.29 GB
 Allocatable NO
 PE Size (KByte) 0
 Total PE 0
 Free PE 0
 Allocated PE 0
 PV UUID 40GJyh-IbsI-pzhn-TDRq-PQ3l-3ut0-AVSE4B

#2 Creating Volume Group

# vgcreate VolGroup /dev/sda1 /dev/sdb1
Volume group ”VolGroup” successfully created
server1:~# vgdisplay
— Volume group —
 VG Name VolGroup
 System ID
 Format lvm2
 Metadata Areas 4
 Metadata Sequence No 1
 VG Access read/write
 VG Status resizable
 Cur LV 0
 Open LV 0
 Max PV 0
 Cur PV 4
 Act PV 4
 VG Size 93.14 GB
 PE Size 4.00 MB
 Total PE 23844
 Alloc PE / Size 0 / 0
 Free PE / Size 23844 / 93.14 GB

#3 Creating Logical Volumes

# lvcreate –name <name> –size 5G VolGroup
#lv create -n media –size 1G VolGroup

Logical volume “media” created

Now this logical volume can be formatted, created file system and mounted

# mkfs.ext3 /dev/VolGroup/media
# mount /dev/VolGroup/media /test
server1:~# lvdisplay
 --- Logical volume ---
 LV Name /dev/VolGroup/media
 VG Name fileserver
 LV UUID 280Mup-H9aa-sn0S-AXH3-04cP-V6p9-lfoGgJ
 LV Write Access read/write
 LV Status available
 # open 0
 LV Size 40.00 GB
 Current LE 10240
 Segments 2
 Allocation inherit
 Read ahead sectors 0
 Block device 253:0

Further all volumes can be verified wtih below command

# pvscan
# vgscan
# lvscan

To remove volumes

# lvremove <devicename>
# vgremove <grounpname>
# pvremove <volumename>

Check Also

Password less SSH authentication

Password less SSH authentication is one of the best security practices to avoid any password …

Leave a Reply

Your email address will not be published. Required fields are marked *