A Beginner's Guide To LVM - Page 2

Now let's create our volume group fileserver and add /dev/sdb1 - /dev/sde1 to it:

vgcreate fileserver /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1

server1:~# vgcreate fileserver /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
  Volume group "fileserver" successfully created

Let's learn about our volume groups:

vgdisplay

server1:~# vgdisplay
  --- Volume group ---
  VG Name               fileserver
  System ID
  Format                lvm2
  Metadata Areas        4
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                4
  Act PV                4
  VG Size               93.14 GB
  PE Size               4.00 MB
  Total PE              23844
  Alloc PE / Size       0 / 0
  Free  PE / Size       23844 / 93.14 GB
  VG UUID               3Y1WVF-BLET-QkKs-Qnrs-SZxI-wrNO-dTqhFP

Another command to learn about our volume groups:

vgscan

server1:~# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "fileserver" using metadata type lvm2

For training purposes let's rename our volumegroup fileserver into data:

vgrename fileserver data

server1:~# vgrename fileserver data
  Volume group "fileserver" successfully renamed to "data"

Let's run vgdisplay and vgscan again to see if the volume group has been renamed:

vgdisplay

server1:~# vgdisplay
  --- Volume group ---
  VG Name               data
  System ID
  Format                lvm2
  Metadata Areas        4
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                4
  Act PV                4
  VG Size               93.14 GB
  PE Size               4.00 MB
  Total PE              23844
  Alloc PE / Size       0 / 0
  Free  PE / Size       23844 / 93.14 GB
  VG UUID               3Y1WVF-BLET-QkKs-Qnrs-SZxI-wrNO-dTqhFP

vgscan

server1:~# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "data" using metadata type lvm2

Now let's delete our volume group data:

vgremove data

server1:~# vgremove data
  Volume group "data" successfully removed

vgdisplay

No output this time:

server1:~# vgdisplay

vgscan

server1:~# vgscan
  Reading all physical volumes.  This may take a while...

Let's create our volume group fileserver again:

vgcreate fileserver /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1

server1:~# vgcreate fileserver /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
  Volume group "fileserver" successfully created

Next we create our logical volumes share (40GB), backup (5GB), and media (1GB) in the volume group fileserver. Together they use a little less than 50% of the available space (that way we can make use of RAID1 later on):

lvcreate --name share --size 40G fileserver

server1:~# lvcreate --name share  --size 40G fileserver
  Logical volume "share" created

lvcreate --name backup --size 5G fileserver

server1:~# lvcreate --name backup --size  5G fileserver
  Logical volume "backup" created

lvcreate --name media --size 1G fileserver

server1:~# lvcreate --name media  --size  1G fileserver
  Logical volume "media" created

Let's get an overview of our logical volumes:

lvdisplay

server1:~# lvdisplay
  --- Logical volume ---
  LV Name                /dev/fileserver/share
  VG Name                fileserver
  LV UUID                280Mup-H9aa-sn0S-AXH3-04cP-V6p9-lfoGgJ
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                40.00 GB
  Current LE             10240
  Segments               2
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/fileserver/backup
  VG Name                fileserver
  LV UUID                zZeuKg-Dazh-aZMC-Aa99-KUSt-J6ET-KRe0cD
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                5.00 GB
  Current LE             1280
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:1

  --- Logical volume ---
  LV Name                /dev/fileserver/media
  VG Name                fileserver
  LV UUID                usfvrv-BC92-3pFH-2NW0-2N3e-6ERQ-4Sj7YS
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                1.00 GB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:2

lvscan

server1:~# lvscan
  ACTIVE            '/dev/fileserver/share' [40.00 GB] inherit
  ACTIVE            '/dev/fileserver/backup' [5.00 GB] inherit
  ACTIVE            '/dev/fileserver/media' [1.00 GB] inherit

For training purposes we rename our logical volume media into films:

lvrename fileserver media films

server1:~# lvrename fileserver media films
  Renamed "media" to "films" in volume group "fileserver"

lvdisplay

server1:~# lvdisplay
  --- Logical volume ---
  LV Name                /dev/fileserver/share
  VG Name                fileserver
  LV UUID                280Mup-H9aa-sn0S-AXH3-04cP-V6p9-lfoGgJ
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                40.00 GB
  Current LE             10240
  Segments               2
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/fileserver/backup
  VG Name                fileserver
  LV UUID                zZeuKg-Dazh-aZMC-Aa99-KUSt-J6ET-KRe0cD
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                5.00 GB
  Current LE             1280
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:1

  --- Logical volume ---
  LV Name                /dev/fileserver/films
  VG Name                fileserver
  LV UUID                usfvrv-BC92-3pFH-2NW0-2N3e-6ERQ-4Sj7YS
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                1.00 GB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:2

lvscan

server1:~# lvscan
  ACTIVE            '/dev/fileserver/share' [40.00 GB] inherit
  ACTIVE            '/dev/fileserver/backup' [5.00 GB] inherit
  ACTIVE            '/dev/fileserver/films' [1.00 GB] inherit

Next let's delete the logical volume films:

lvremove /dev/fileserver/films

server1:~# lvremove /dev/fileserver/films
Do you really want to remove active logical volume "films"? [y/n]:
 <-- y
  Logical volume "films" successfully removed

We create the logical volume media again:

lvcreate --name media --size 1G fileserver

server1:~# lvcreate --name media  --size  1G fileserver
  Logical volume "media" created

Now let's enlarge media from 1GB to 1.5GB:

lvextend -L1.5G /dev/fileserver/media

server1:~# lvextend -L1.5G /dev/fileserver/media
  Extending logical volume media to 1.50 GB
  Logical volume media successfully resized

Let's shrink it to 1GB again:

lvreduce -L1G /dev/fileserver/media

server1:~# lvreduce -L1G /dev/fileserver/media
  WARNING: Reducing active logical volume to 1.00 GB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce media? [y/n]:
 <-- y
  Reducing logical volume media to 1.00 GB
  Logical volume media successfully resized

Share this page:

3 Comment(s)

Add comment

Comments

From: Anonymous

If you get this error, you'll need to "deregister" the partition table from the kernel.

 kpartx -d /dev/fileserver/films

 lvremove /dev/fileserver/films

From: Andre de Araujo

Correct is: #lvextend -L  +1.5G  /dev/fileserver/media

From: Adrian Varan

"+" is optional (read the manual). If you use +1.5G then the 1.5G is added to the actual size (1.5+1=2.5G), without "+" the 1.5G represents the new absolute value of the logical volume.