View the Most Wanted LQ Wiki articles.
LinuxQuestions.org > Linux Wiki > LVM

From LQWiki

Jump to: navigation, search

Contents

LVM

LVM is an abbreviation for Logical Volume Manager which has been available under Linux for some time; the 2.4 kernel has the original LVM whilst 2.6 has LVM2 although both essentially do the same job. LVM allows one or more physical devices to be treated as a storage pool from which logical drives may be created whose size can altered dynamically. Assuming your file system supports dynamic resizing the upshot of this is you can grow/shrink logical drives (mount points) as your wish. In addition to combining drives in to logical devices you can also control the spread of data amongst devices through the use of striping, however this is often better left to a RAID implementation. LVM works on top of Software-RAID just fine by the way. :)

Concept

physical volume
A physical volume (PV) can be created using any block device you choose, typically the block device would be a physical disk, RAID device, partition or even a file. PVs are sliced into logical allocation units knows as physical extents (PEs), the default PE size is 4MB. A single PE is the smallest storage area (Logical volume or LV) you can create, so if you have a 128MB PE size then you could create a 128MB storage area, or any size that is a multiple of 128MB.
volume group
In LVM a volume group (VG) is, as the name suggests, a set of physical volumes. All physical volumes in a volume group should have the same extent size. It is from the volume group that you actually allocate extents to created your logical volumes (see below). If you have 2 VGs each holding two 250GB physical volumes (say 250GB hard disks) then you could create, at most, two logical volumes each 500GB in size. Alternatively if you had a single VG holding all four of your 250GB PVs you could create yourself a single 1TB logical volume. Note that you don't have to just create a single LV for each VG, in these examples you could create say eight 128GB LVs, or 16 64GB LVs.
logical volume
A logical volume is a set of extents allocated from a volume group and is a concept analogous of a disk partition. A logical volume can be resized as necessary without the need of reformatting and explicit copying of all its contents. A filesystem can be created on a logical volume in the usual way, and can be mounted afterwards just as any other filesystem. Logical volumes are to seen as devices with names like /dev/VolGroup00/LogVolume00, or /dev/StudentVG/year1/

commands

Quite a large set of commands can be used to manipulate LVM

pysical volume volume group logical volume

Using webmin it is possible to use and configure LVM from within a browser. Fedora has a utility system-config-lvm.

example

The first step for putting LVM on a disk is to pick an empty partition, and change its type to Linux LVM (8e).

For fdisk:

# fdisk /dev/sde
Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 8e

For cfdisk:

# cfdisk /dev/sde

to select the hard drive. cfdisk displays lists of partitions and commands, and I selected sde5, Type. I typed in 8e. The type was changed, but cfdisk treats it as an unknown type. I told it to write the partition table, and exited.

To verify, I ran fdisk, which recognized the type as Linux LVM.

To create the physical volume I exectued

# pvcreate /dev/sde5

Then to create a volume group called vg-maxtor containing the physical volume on /dev/sde5 I used

# vgcreate vg-maxtor /dev/sde5

And finally to display my newly created volume group

# vgdisplay

To create a logical volume called mydata using extents from the vg-maxtor I used

# lvcreate -L 10G -nmydata vg-maxtor

I then created a file system in the usual way and mounted the 10G LV

# mkfs -t ext3 /dev/vg-maxtor/mydata
# mount -o users /dev/vg-maxtor/mydata /home/tom/maxtor-mydata

I can now access the mydata logical volume at /home/tom/maxtor-mydata

I tried adding the mount to fstab, but the entry gets removed when I reboot, and vg-maxtor goes inactive. I wrote a script file to bypass this problem:

#!/bin/sh
#
vgscan
vgchange -a y
mount -o users  /dev/vg-maxtor/bulkdata /addonics/bulkdata

External links


Personal tools