Tuesday, 12 November 2013

LVM Introduction

LVM is a Logical Volume Manager for the Linux operating system.

This gives the system administrator much more flexibility in allocating storage to applications and users.
Storage volumes created under the control of the logical volume manager can be resized and moved around.

The logical volume manager also allows management of storage volumes in user-defined groups, allowing the system administrator to deal with sensibly named volume groups such as "development" and "sales" rather than physical disk names such as "sda" and "sdb".

Logical volume management is traditionally associated with large installations containing many disks but it is equally suited to small systems with a single disk or maybe two.

When new drives are added to the system, it is no longer necessary to move users files around to make the best use of the new storage;
simply add the new disk into an existing volume group or groups and extend the logical volumes as necessary.


It is also easy to take old drives out of service by moving the data from them onto newer drives - this can be done online, without disrupting user service.

NOTE: If a system if full and there is no more space, we can either add a new disk into an existing volume group or groups and extend the logical volumes. OR export the LVM to another system.


hda1   hdc1  (PV:s on partitions or whole disk)             
       \   /                                                                   
        \ /                                                                    
 diskvg   
(VG)     
      /    |  \                                                                 
      /      |   \                                                               usrlv rootlv varlv (LV:s)
         |      |     |                                                               ext2  reiserfs  xfs (filesystems)


# volume group (VG)

The Volume Group is the highest level abstraction used within the LVM. It gathers together a collection of Logical Volumes and Physical Volumes into one administrative unit.

# physical volume (PV)

A physical volume is typically a hard disk, though it may well just be a device that 'looks' like a hard disk (eg. a software raid device).

# logical volume (LV)

The equivalent of a disk partition in a non-LVM system. The LV is visible as a standard block device; as such the LV can contain a file system (eg. /home).

# physical extent (PE)

Each physical volume is divided chunks of data, known as physical extents, these extents have the same size as the logical extents for the volume group.

# logical extent (LE)

Each logical volume is split into chunks of data, known as logical extents. The extent size is the same for all logical volumes in the volume group.

# Tying it all together

Example:
  Lets suppose we have a volume group called VG1, this volume group has a physical extent size of 4MB.
  Into this volume group we introduce 2 hard disk partitions, /dev/hda1 and /dev/hdb1.
 
These partitions will become physical volumes PV1 and PV2 (more meaningful names can be given at the administrators discretion).
 

The PV's are divided up into 4MB chunks, since this is the extent size for the volume group.
 
The disks are different sizes and we get 99 extents in PV1 and 248 extents in PV2.


  We now can create ourselves a logical volume, this can be any size between 1 and 347 (248 + 99) extents. When the logical volume is created a mapping is defined between logical extents and physical extents,
 
  eg. logical extent 1 could map onto physical extent 51 of PV1, data written to the first 4 MB of the logical volume in fact be written to the 51st extent of PV1.

No comments:

Post a Comment