Main menu

Linux LVM in 10 minutes

LVM is an logical layer between Physical hard drive and your Operating system. This logical is used to provide an interface for your physical disk so your partition or say LVM no longer tied with your physical disk.

Benefit of using LVM is, you can logically expand your partition to any number of physical disk.

Let’s see how can we user LVM…

  1. Create partition
  2. Create Physical volume
  3. Create Volume group
  4. Create Logical volume

LVM

In this artical we are using two disks…

/dev/sda

  • Partition 1 : /dev/sda1
  • Partition 2 : /dev/sda2

/dev/sdb

  • Partition 1 : /dev/sdb1
  • Partition 2 : /dev/sdb2

1. Create Physical Volume

# pvdisplay /dev/sda1 /dev/sdb1
# pvscan
# pvdisplay

2. Create Volume Group

# vgcreate vg_newvg /dev/sda1 /dev/sdb1

# vgscan
# vgdisplay

3. Create logical volume

# lvcreate --name volume_name --size 40G vg_newvg
# lvscan
# lvdisplay

4. Creating file system on newly created logical volume.

# mkfs.ext3 /dev/vg_newvg/volume_name

5 Extending Volume Group

vgextend mynew_vg /dev/sdb2

6 Extending logical volume

# lvextend -L  +10G  /dev/vg_newvg/volume_name
# lvresize -L +10G  /dev/vg_newvg/volume_name
# resize2fs   /dev/vg_newvg/volume_name

7 Reducing logical volume

# lvreduce -L 5G  /dev/vg_newvg/volume_name
# lvresize -L -5G /dev/vg_newvg/volume_name

8. Moving data between physical volume

# pvmove /dev/sdb1 /dev/sdf1

9. Removing everything

# lvremove  /dev/vg_newvg/volume_name
# vgremove /dev/vg_newvg/
# pvremove /dev/sda1 /dev/sdb1

 

FacebookTwitterGoogle+RSS