LVM Configuration in Linux Redhat 6


LVM (Logical Volume Management) is a method of partitioning hard disk drives that provides more flexibility in managing Storage space than the traditional method of disk partitioning. The Linux version, Logical Volume Manager or LVM, has been a feature of the Linux kernel since about 1999, and was contributed (to the Linux kernel) by Sistina Software, Inc, a company that was later acquired by Redhat .

Learn How to perform It '

My Linux OS   - Redhat-6
Attached HDD  - 4 HardDrive

My LVM Configuration Structure




I have attached Four HDD at my system and One is my Boot HDD and fully consumed. Another three HDD i will use in LVM .
/dev/sda 20GB and consumed by My Redhat OS .
/dev/sdb 20GB and i create two partition from this /dev/sdb1-10Gb /dev/sdb2-10Gb
/dev/sdc 10Gb and i create a single partition from this /dev/sdc1-10Gb
/dev/sdd 15Gb and i also create a single partiton from this /dev/sdd1-15Gb

Do Partitioning .
fdisk /dev/sdb
1.Press n for create new partition
2.then press p for create primary partition .
3.Now give partition number like 1,2,3 We are creating first partition in this HDD so we  give simply 1 ,and when we create second partition then  give 2  .
4.First Cylinder option simply enter by accepting default cylinder value .
5.Then give Partition size like +10G for creating 10GB partition .
6.Then type w for write changes on disk .
Do Partitioning by following the same procedure as above in the HDD /dev/sdc and  /dev/sdd also .




When partitioning done then convert our newly created partitions as PV(Physical Volume) run command pvdisplay to see if any PV exist or not .
pvdisplay
pvcreate /dev/sdb1 /dev/sdb2 /dev/sdc1 /dev/sdd1

Now again run pvdisplay for see our pv created or not you will see list of created PV with size and UUID .
Then create VG(Volume Group) and add our Recently created PV to this VG .
Run command vgdisplay to see current VG Information .

Note:- we create Four PV but below we are adding only three PV in this myvg1 group because we will create another VG then add lefted PV to that VG

vgcreate /dev/myvg1 /dev/sdb1 /dev/sdc1 /dev/sdd1



We are creating another VG just for explain that we can create multipleVG from single HDD and can create single VG by using Multiple HDD

vgcreate /dev/myvg2 /dev/sdb2
lvcreate --name lv2 --size 10GB /dev/myvg2

Again run vgdisplay  to ensure that our VG create or not and remember our VG size is always equal to total size of added PV’s and VG also get UUID like PV .


Now we can create any size of LV(Logical Volume)from total size of VG use lvdisplay to see created LV if any .
lvcreate --name lv1 --size 20GB /dev/myvg1

Now we need to provide any File-system for our newly created LV then mount it any location ,and after mounting we can use it .
lvdisplay
mkfs.ext4 /dev/myvg1/lv1


as we create a LV named  /dev/myvg1/lv1  and give filesystem ext4  now Mount it .
mkdir /home/lvmmount
mount /dev/myvg1/lv1 /home/lvmmount
cd /home/lvmmount
Make some test file for testing
touch 1 2 3 4 5 6 7 8


Mount our LV as permanent otherwise it will automatically unmount after restart my machine .
vi /etc/fstab 



LV-RESIZING :-Now see how we can Extend or Reduce our LV size , and before extend me must have free/unallocated space in our VG .

We use + at extending time and - at reducing time

lvextend --size +10G /dev/myvg1/lv1
resize4fs /dev/myvg1/lv1 
df -h   (for check the free space)


If we nee reduce of LV size then do it .
lvreduce --size -15G /dev/myvg1/lv1




VG-RESIZING:- if we want extend our VG size then we must have unallocated PV if we don't have  then add extra HDD create partition Covert those Partitions as PV then add  PV to That VG . 

vgextend /dev/myvg1 /dev/sdb2




If i want remove any PV from my VG then do this .

vgreduce /dev/myvg1 /dev/sdc1


Reduce and extend done so now i want remove my current LVM structure then first i unmount my mounted LV after unmounting 
Step 1. First remove our LV
Step 2. Second remove Our VG
Step 3. Then remove our PV 
run command lvdisplay ,vgdisplay , pvdisplay to see there is no any LV,VG,PV  Exist .



!!!!!!!!!!!!!!!!!!!!!!!WE PERFORM LVM SUCCESSFULLY !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Learn Other Servers :-   DNS                  APACHE                            YUM


No comments:

Post a Comment