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 volumes, with the exception of the /boot/ partition. The /boot/ partition cannot be on a logical volume group because the boot loader cannot read it. If the root (/) partition is on a logical volume, create a separate /boot/ partition which is not a part of a volume group.
Steps to setup LVM :-
[Note : We need Multiple Harddisk's to Setup LVM, In My case Hardisk's are "/dev/sdb", "/dev/sdc", "/dev/sdd"]
Steps :
a. Create Partition's for LVM in all Harddisk's.
Steps for create Partition :
- fdisk /dev/sdb ---> "fdisk" is the command to create a partition & "/dev/sdb" is the SCSI Harddisk Syntax in Linux.
- Type "n" ---> for New Partition.
- Type "p" ---> To create a Primary Partition.
- +2G ---> To Assign size of the partition [Note "G for GB" & "M for MB"], Here we can mention +2048M in place +2G.
- t ---> to Change the Partition ID for LVM i.e. "8e"
- w ---> To save the partition table.
[Note : In Linux we need to restart the system after creating the partition to take effect but we can run below command to skip restart.]
partprobe /dev/sdb ---> Command to take effect of newly created partition without restart the system.
Structure of LVM :
b. Create Physical Volumes using 'pvcreate'
pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd1 ---> To create Physical Volume
pvdisplay ---> To display the created Physical Volume details.
c. Create Volume Groups using 'vgcreate'
vgcreate volgroup001 /dev/sdb1 /dev/sdc1 /dev/sdd1
Where :
volgroup001 ---> Name of the Volume Group
vgdisplay ---> To display the created Volume Group details.
d. Create one or more Logical Volumes
lvdisplay ---> To display the created Logical Volume details.
e. Create File system on logical volume(s)
Structure of LVM :
b. Create Physical Volumes using 'pvcreate'
pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd1 ---> To create Physical Volume
pvdisplay ---> To display the created Physical Volume details.
c. Create Volume Groups using 'vgcreate'
vgcreate volgroup001 /dev/sdb1 /dev/sdc1 /dev/sdd1
Where :
volgroup001 ---> Name of the Volume Group
vgdisplay ---> To display the created Volume Group details.
d. Create one or more Logical Volumes
- lvcreate -L 10GB -n logvol001 volgroup001
- lvcreate -L 10GB -n logvol002 volgroup001
lvdisplay ---> To display the created Logical Volume details.
e. Create File system on logical volume(s)
- mke2fs -j /dev/volgroup001/logvol001
- mke2fs -j /dev/volgroup001/logvol002
f. Mount logical volume (Temporary Mounting)
- mkdir /lvm1
- mount /dev/volgroup001/logvol001 /lvm1
- mkdir /lvm2
- mount /dev/volgroup001/logvol002 /lvm
g. Mount in /etc/fstab
Steps :
a. nano /etc/fstab then enter the below lines in "fstab" file
/dev/volgroup001/logvol001 /lvm1 ext3 defaults 0 0
/dev/volgroup001/logvol002 /lvm2 ext3 defaults 0 0
After creation of LVM we have to reactive the Volume Group otherwise when we restart the Server we loose all the configured LVM
# vgchange -a y volgroup001
Where volgroup001 is name of Volume Group
Extend Logocal Volume
Rename Logical Volume
Resize Logical Volume
Remove Logical Volume
LVM gui Command ---> system-config-lvm
Steps :
a. nano /etc/fstab then enter the below lines in "fstab" file
/dev/volgroup001/logvol001 /lvm1 ext3 defaults 0 0
/dev/volgroup001/logvol002 /lvm2 ext3 defaults 0 0
After creation of LVM we have to reactive the Volume Group otherwise when we restart the Server we loose all the configured LVM
# vgchange -a y volgroup001
Where volgroup001 is name of Volume Group
Extend Logocal Volume
Rename Logical Volume
Resize Logical Volume
Remove Logical Volume
LVM gui Command ---> system-config-lvm