Next Previous Contents

8. Examples

8.1 Creating three LV on two HD

We want to set up three LV (called "pages", "database" and "proxy") on two IDE HD (/dev/hda and /dev/hdb). Each HD should have only a single partition that covers the whole disk. All the LV must be part of a group called "server".

First at all, we create the partitions /dev/hda1 and /dev/hdb1.

cfdisk /dev/hda
cfdisk /dev/hdb

We can now initialize the single partitions on the disk

pvcreate /dev/hda1 /dev/hdb1

We now create the VG and add the two partitions to this group

vgcreate server /dev/hda1 /dev/hdb1

It's time to create the required LV in the group "server"

lvcreate -L 1G -n pages server
lvcreate -L 500M -n database server
lvcreate -L 2G -n proxy server

In order to use the just created LV, they must be formatted

mkefs -j /dev/server/pages
mkefs -j /dev/server/database
mkefs -j /dev/server/proxy

And finally we can mount them

mount /dev/server/pages /var/www/pages/
mount /dev/server/database /var/lib/mysql/
mount /dev/server/proxy /var/cache/apt-proxy/

Observation

We just created three LV on two HD, and we don't know where these LV are placed. May be all three on /dev/hda1, or the first two on /dev/hda1 and the third on /dev/hdb1. Or may be a part of the first LV is placed on /dev/hda1 and the second part on /dev/hdb1 and same for the others. We really don't know it and we absolutely don't need this information to continue working. This is the idea of LVM!

If in the future one of these LV becomes full, it's possible to reduce the others LV and expand the first one. An other possibility is to add a third HD, add its partition to the same VG and expand the LV that needs more place. Isn't it fantastic?

8.2 Removing one Volume Group

We want to remove the VG "server".

In order to remove it, all the LV must be deleted and the VG must be deactivated.

First at all, we remove all the LV

lvremove /dev/server/pages /dev/server/database /dev/server/proxy

We must now deactive the VG

vgchange -a n server

and only now it's possible to remove the VG

vgremove server


Next Previous Contents