Skip to content

logical volume manager

Builds logical disk volumes on top of physical ones. Especially useful for resizing and reordering disks.

setup

I have 3 harddisk of 1 GB each, and combine these into one logical volume.

physical volumes

These are just LVM physical disks the size of the underlying hardware :

To prepare these for LVM, partition them as /dev/sdb1, /dev/sdc1 and /dev/sdd1 and give them type 8e (Linux LVM) Then make them physical volumes using pvcreate :

physical
pvcreate /dev/sdb1 dev/sdc1 /dev/sdd1
The reverse action would be pvremove pvdisplaym and pvs would show your volumes.

pvs
pvs 

 PV         VG         Fmt  Attr PSize    PFree   
  /dev/sda2  VolGroup   lvm2 a--     7.51g       0 
  /dev/sdb1  fileserver lvm2 a--  1016.00m       0 
  /dev/sdc1  fileserver lvm2 a--  1016.00m 1008.00m
  /dev/sdd1  fileserver lvm2 a--  1016.00m 1016.00m

volume group

You can now bind physical volumes into a volume group.

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

Again, useful commands are vgremove, vgdisplay, vgrename, and

volume groups
 vgs

 VG         #PV #LV #SN Attr   VSize VFree
  VolGroup     1   2   0 wz--n- 7.51g    0 
  fileserver   3   1   0 wz--n- 2.98g 1.98g

logical volumes

Lvm it is called, and here they are. Let's create two logical volumes.

''' lvcreate --name small --size 1G fileserver lvcreate --name big --size 1.8G fileserver '''

There is probably some overhead since asking for 2G was too much, so i made 1.8G Listing these volumes can be done with lvs

lvs
lvs

  LV      VG         Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_root VolGroup   -wi-ao----   6.71g                                                    
  lv_swap VolGroup   -wi-ao---- 816.00m                                                    
  big     fileserver -wi-a-----   1.80g                                                    
  small   fileserver -wi-a-----   1.00g                                                    
Ok, there was another volume group already, you could do lvs fileserver to get only those LV's

using the volumes

Now they are just like normal partitions, reachable in /dev/. So

ls
ls /dev/fileserver

big      small
Format and mount :

format and mount
mkfs.ext4 /dev/fileserver/small
mkdir /media/small
mount /dev/fileserver/small /media/smal