Thursday, February 18, 2010

How To : Linux LVM (Logical Volume Manager)

This Article shows on how to create a logical volumes on Linux
STEP 1:(Create Partitions)
Here we are considering a physical Hard Disk (dev/sda)
Using fdisk command we are going to partition the /dev/sda into /dev/sda1 and /dev/sda2
Eg:fdisk /dev/sda
We created 2 partitions /dev/sda1 and /dev/sda2
STEP 2:(Create Physical Volumes)
Use the pvcreate command to create physical volumes# pvcreate /dev/sda1# pvcreate /dev/sda2
Use the pvdisplay command displays all physical volumes on your system
STEP 3:(Create Virtual group)
Here I am going to create a new Vitual group
# vgcreate mynew_vg /dev/sda1
To include both the partitions as a Single Virtual group,
# vgcreate mynew_vg /dev/sda1 /dev/sda2
Or else if you want to extend the same virtual group to other partitions
# vgextend mynew_vg /dev/sdb2
STEP 4:(Create Logical Volumes)
create a logical volume of size 1000 MB -L 1000create a logical volume of size 5 GB -L 5G
# lvcreate -L 1000 -n vol01 mynew_vg # lvcreate -L 5G -n vol02 mynew_vg
To display Logical volumes use the command lvdisplay
STEP 5:(Create File systems on logical volumes)
# mkfs.ext3 /dev/mynew_vg/vol01# mkfs.ext3 /dev/mynew_vg/vol02
STEP 6:(Edit fstab)
Edit /etc/fstab
Add the the created logical volumes
Eg:/dev/mynew_vg/vol02 /mnt/lvm ext3 defaults 0 2
STEP 7:(Mount LVM)
Make the directory where we want to mount as mentioned in fstab#mkdir /mnt/lvm
#mount -a
or
#mount /dev/mynew_vg/vol02 /mnt/lvm

No comments: