Sunday, May 06, 2007

LVM TUTORIAL BASICS

LVM TUTORIAL BASICS V 1.0 03/21/07

by derrick caluag


[root@intel-4 ~]# fdisk -l

Disk /dev/sda: 145.4 GB, 145492017152 bytes

255 heads, 63 sectors/track, 17688 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sda1 * 1 16 128488+ 83 Linux

/dev/sda2 17 1060 8385930 83 Linux

/dev/sda3 1061 1321 2096482+ 82 Linux swap

/dev/sda4 1322 17688 131467927+ 8e Linux LVM

INITIALIZATION

-- Create Physical Volume

pvcreate /dev/sda4

-- Create Volume Group

vgcreate VolG00 /dev/sda4

-- Create Logical Group (this will create 21G for LVhome)

lvcreate -L21000 VolG00 -n LVhome

-- Format the create Group with desired file system

mkfs.ext3 -b 4096 /dev/VolG00 / LVhome

-- Create Mount point on fstab

vi /etc/fstab

/dev/VolG00/LVhome /home ext3 defaults 1 2

-- Backup files on mountpoint

tar –zcvf /tmp/home.tgz /home

mv /home home2

mkdir home

-- Mount the partition

mount /dev/VolG00/LVhome

-- Untar the backup file back to the mount point

cd /home

cp /tmp/home.tgz

tar –zxvf home.tgz

EXTENDING LVM

-- Unmount partition

umount /dev/VolG00/LVhome

Extend LV

lvextend -L+1G /dev/VolG00/LVhome

add 1G to current size

or

lvextend -L12G /dev/VolG00/LVhome

extend size to 12G

-- Check extended LV for errors

e2fsck -f /dev/VolG00/LVhome

-- Resize the LV

resize2fs /dev/VolG00/LVhome

-- Remount the partition

mount /dev/VolG00/LVhome