Wednesday, 5 June 2013

LVM (Logical volume manager) configuration in Linux

What Is LVM ?
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.
LVM Terms 
Physical Volume: A physical volume (PV) is another name for a regular physical disk partition that is used or will be used by LVM. 
Volume Group: Any number of physical volumes (PVs) on different disk drives can be added  together into a volume group (VG).


Logical Volumes: Volume groups must then be subdivided into logical volumes. Each logical volume can be individually formatted as if it were a regular Linux partition. A logical volume is, therefore, like a virtual partition on your virtual disk drive.

 Create A LVM-


Step-1 –   Create two Partitions of 500 MB each using FDISK and set type   as     
                     LINUX LVM
Step-2 –   Create Physical Volumes
pvcreate   /dev/hda8    /dev/hda9
Step-3 –   Create Volume Group
 vgcreate   VG1   /dev/hda8    /dev/hda9
Step-4 –   Change Volume  Group to ACTIVE
vgchange   -a   y    VG1
Step-5 –   Create Logical Volume
lvcreate     -L   +600M    -n    LV1    VG1
Step-6 –   Format the Logical Volume
mkfs.ext3     /dev/VG1/LV1
Step-7 –   Mount in /etc/fstab
/dev/VG1/LV1  /mnt/data  ext3  defaults  0 0
Step-8 – Activate the new volume
mount -a 

Check the newly mounted Logical Volume
For Short details 
pvscan
lvscan 
vgscan
For Long Full Details
pvdisplay 
lvdisplay 
vgdisplay

RESIZING THE LVM 

Step-1 – Umountthe LVM

  umount    /dev/VG1/LV1

Step-2 – Resize the LVM

  lvextend    -L    +200M      /dev/VG1/LV1

Step-3 – Make the LVM active

  vgchange    -a   y     VG1

Step-4 – Update  the /etc/fstab for new size

  mount -a

Step-5 – Configuring the HDD for new extended space

  resize2fs      /dev/VG1/LV1
ADVANCE LVM ------------- extraaa 

 Renaming a Volume Group
vgrename   /dev/vg02   /dev/my_volume_group 
vgrename   vg02   my_volume_group 
Creating LVM by percentage % of free space
lvcreate   -l 60%VG   -n   mylv   testvg 
lvcreate   -l 100%FREE   -n   yourlv   testvg 
Creating Striped LVM
lvcreate   -L50G   -i2   -I64   -n   gfslv   vg0
Creating Mirror LVM
lvcreate   -L50G   -m1   -n gfslv   vg0 
lvcreate   -L12MB   -m1   --corelog   -n   ondiskmirvol   bigvg 
Changing LVM Type
lvconvert   -m1   vg00/lvol1   ---- converting linear to mirror 
lvconvert   -m0   vg00/lvol1   ---- converting mirror to linear 
 Changing Permission of LVM
lvchange   -pr   vg00/lvol1    ---- changing LVM to read-only

No comments:

Post a Comment