Re: LVM (was Re: [Hampshire] Strange overflow messages when …

Top Page
Author: Hugo Mills
Date:  
To: Hampshire LUG Discussion List
Old-Topics: Re: [Hampshire] Strange overflow messages when backing up
Subject: Re: LVM (was Re: [Hampshire] Strange overflow messages when backing up)

Reply to this message
gpg: failed to create temporary file '/var/lib/lurker/.#lk0x5677f100.hantslug.org.uk.22963': Permission denied
gpg: keyblock resource '/var/lib/lurker/pubring.gpg': Permission denied
gpg: Signature made Sat Nov 3 11:58:32 2007 GMT
gpg: using DSA key 20ACB3BE515C238D
gpg: Can't check signature: No public key
On Sat, Nov 03, 2007 at 11:28:21AM +0000, John Lewis wrote:
> On Sat, 3 Nov 2007 09:11:41 -0000 (GMT)
> "Vic" <lug@???> wrote:
> > The three-line version:
> >
> > - Turn your disks (or partitions) into LVM-capable Physical
> > Volumes (PVs) with pvcreate
> > - Group your PVs into Volume Groups (VGs) with vgcreate
> > - Slice off a logical volume (LV) for your filesystem with lvcreate
>
> I had install etch onto one of the drives in my test box and used the
> option to create LV with separate partitions for /home /var /usr
> etc.
>
> I have just wiped the second drive with cfdisk and
> created /dev/hdb1 as type 8E.
>
> I then ran 'pvcreate /dev/hdb1' and got response 
>     Physical volume "/dev/hdb1" successfully created 

>
> vgscan told me it had found volume group "telgar" using
> metadata type lvm2
>
> I then tried vgextend telgar /dev/hdb1 and got response
>     Volume group "telgar" successfully extended.  

>
> so what has actually happened and how do I take advantage of the
> 'larger' volume. Does it just mean I now have a lump of unused space
> attached to /dev/hda1?


It's not attached to /dev/hda1. It's attached to the /dev/telgar/
storage pool. Think of the volume group as a single large hard disk
that you can repartition flexibly while it's in use. The raw storage
used to make up that volume group is actually two physical devices
(/dev/hda5 and /dev/hdb1). There's a diagram below which may make
things clearer.

Terminology:

Physical Volume (PV) is a lump of raw storage -- usually a hard
                     disk or a partition on a hard disk.


Volume Group (VG)    is a large pool of storage made up of one or
                     more PVs, which can be divided up arbitrarily.


Logical Volume (LV)  is a section of a VG -- think of this as a
                     partition, on which filesystems can be created.


> cfdisk shows /dev/hda with /dev/hdb1 as a bootable primary Linux
> ext3 partition and /dev/hda5 as a logical Linux LVM partition
>
> cfdisk shows /dev/hdb with just /dev/hdb1 as a primary Linux LVM
> partition


cfdisk won't show you anything particularly interesting. See below
for more useful information tools.

> Both disks are 30gig and one is normally quite adequate for my needs.
> This is the first time I have used LVM and I really don't understand
> how best to use it.


The main thing is online "repartitioning" and extension of disk
space. If, for example, you find yourself running out of space on
/home, you can now do the following:

$ lvextend -L +5G /dev/mapper/telgar-home
$ ext2online /dev/mapper/telgar-home

This will allocate an additional 5 GiB of space to the "partition"
(actually, logical volume) that /home lives on, and then extend the
filesystem up to fill it. Note that if you'd allocated all the space
from the first hard disk originally, then the extension will be
allocated on the second hard disk, so your /home is, ultimately,
partly on one disk and partly on the other. Diagramatically:

     +-----------------------------+--------------------------+
PVs  |      Disk 1 = /dev/hda5     |    Disk 2 = /dev/hdb1    |
     +-----------------------------+--------------------------+


     +--------------------------------------------------------+
VGs  |                  Volume group = telgar                 |
     +--------------------------------------------------------+


     +--------+--------------+-----------------+--------------+
LVs  |  /var  |     /usr     |     /home       |   free       |
     +--------+--------------+-----------------+--------------+


You can inspect the three layers with pvdisplay, vgdisplay and
lvdisplay (use the -C option to get a one-line-per-volume summary of
the information). The abbreviation "PE" is "Physical Extents", which
is the allocation unit for the volume.

There's a whole range of tools for things like recovery when PVs
are missing, and for managing the positioning of LVs on specific PVs.
These can generally all be done online, as the system is being used.

You'll find the device nodes for the LVs in /dev/mapper/telgar-*,
with handy symlinks in /dev/telgar/*.

> Wikipedia says LVM can be used to
>
> * Create read-write snapshots of logical volumes (LVM2).


Yes, although I've never used it.

> * Stripe whole or parts of logical volumes across multiple PVs, in a
> fashion similar to RAID0.
>
> * Mirror whole or parts of logical volumes, in a fashion similar to
> RAID1


IMO, these are better done at a lower layer by the RAID system.

Hugo.

-- 
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
               --- Quantum est ille canis in fenestra? ---