LVM

Linux File System Management

 Here I am taken three disk for use of different different examples to manage the linux filesystem, where

the disk name is /dev/sda, /dev/sdb, /dev/sdc.

 How to Create Physical Volume?

# pvcreate /dev/sdb

# pvdisplay or pvs

 How to Create Physical Volume?

# pvcreate /dev/sdb

# pvdisplay or pvs

 How to Create Volume Group?

# vgcreate vg0 /dev/sdb

# vgdisplay or vgs

 

 How to Create Logical Volume?

# lvcreate –L 100M –n lv0 /dev/vg0

# lvdispaly or lvs

# mkfs.ext4 /dev/vg0/lv0

# mkdir /data

# mount /dev/vg0/lv0 /data

# df –Th

# mount –a

 

 How to remove the logical volume, volume group, physical volume?

# umount /dev/vg0/lv0 /data

# lvremove /dev/vg0/lv0

# vgremove /dev/vg0

# pvremove /dev/sdb

 How to extend the vgsize in volume group?

# vgs

# vgextend vg0 /dev/sdc

# vgs

 How to reduce the vgsize in volume group?

# vgs

# vgreduce vg0 /dev/sdc

# vgs

 

 How to extend the lvsize in logical volume?

# vgs

# df –Th /data

# lvextend –L +100M /dev/vg0/lv0

# resize2fs /dev/vg0/lv0

# df –Th /data

 How to reduce the lvsize in logical volume?

# lvs

# df –Th /data

# umount /dev/vg0/lv0 /data

# e2fsck –f /dev/vg0/lv0

# resize2fs /dev/vg0/lv0 200M

# lvreduce –L -100M /dev/vg0/lv0

 

 How to create the snapshot of logical volume?

# lsv /dev/vg0/lv0*

# lvcreate –size 200M –snapshot –name lv0_snap /dev/vg0/lv0

# lsv /dev/vg0/lv0*

# mkdir /data_snap

# mount /dev/vg0/lv0_snap /data

# df –Th /data*

 How to activate and deactivate the volume group & logical volume?

# vgchange –an /dev/vg0 [deactivate vg]

# vgchange –ay /dev/vg0 [activate vg]

# umount /dev/vg0/lv0 /data

# lvchange –an /dev/vg0/lv0 [deactivate lv]

# lvchange –ay /dev/vg0/lv0 [activate lv]

# mount /dev/vg0/lv0 /data

 

 How to create the mirror of logical volume?

# pvcreate /dev/sdb{1,2,3}

# vgcreate vg0 /dev/sdb{1,2,3}

# lvcreate –L 50M –m 1 –n lv0_mirror /dev/vg0

# mkfs /dev/vg0/lv0_mirror

# mkdir /data_mirror

# mount /dev/vg0/lv0_mirror /data_mirror

# df –Th /data_mirror

 

 How to recover a deleted logical volume?

# lvcreate -L 100M -n lv0 /dev/vg0

# mkfs.ext4 /dev/vg0/lv0

# mkdir /data

# mount /dev/vg0/lv0 /data

# umount /dev/vg0/lv0 /data

# lvremove /dev/vg0/lv0 /data

# cd /etc/lvm/archive

# vgcfgrestore –list vg0

# vgcfgrestore -f /etc/lvm/archive/vg0_xxxxx-xxxxxxxxxx.vg vg0

# lvchange -ay /dev/vg0/lv0

# lvscan

# mount /dev/vg0/lv0 /data

 

Advertisements