LVM

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

IBM: Learning Linux LVM, Part 1

LVM Hierarchy
LVM hierarchy:


 * Physical Volume: (physical disk with LVM partition type) A physical volume (PV) is another name for a regular physical disk partition that is used or will be used by LVM.


 * Volume Group: (virtual disk composed of physical volume(s)) Any number of physical volumes (PVs) on different disk drives can be lumped together into a volume group (VG). Under LVM, volume groups are analogous to a virtual disk drive.


 * Volume Groups are built from blocks called Physical Extents. The maximum number of physical extents is 65k.


 * Physical Extent: Real disk partitions are divided into chunks of data called physical extents (PEs) when you add them to a logical volume. PEs are important as you usually have to specify the size of your volume group not in gigabytes, but as a number of physical extents.


 * Logical Volumes: (virtual partition divided from a volume group) Volume groups must then be subdivided into logical volumes. Each logical volume can be individually formatted as if it were a regular Linux partition. A logical volume is, therefore, like a virtual partition on your virtual disk drive.


 * This may seem complicated, but it allows you to create new virtual partitions with sizes you can change from groups of real disk partitions whose sizes you probably cannot change. Another advantage of LVM is that this can all be done without disturbing other partitions on your hard disks.

Physical Volumes
"Physical Volume: A physical volume (PV) is another name for a regular physical disk partition that is used or will be used by LVM." 

Are devices (ie. /dev/md0)

If using a non md partition, use fdisk and set the partition type to "8e": Command (m for help): t Partition number (1-6): 1 Hex code (type L to list codes): 8e Changed system type of partition 6 to 8e (Linux LVM)

Display Physical Volumes: pvdisplay pvdisplay

Initialize a disk or parition for use by LVM: pvcreate /dev/ pvcreate /dev/md0 pvcreate /dev/sda1

Remove physical volume: pvremove

Volume Groups
"Volume Group: Any number of physical volumes (PVs) on different disk drives can be lumped together into a volume group (VG). Under LVM, volume groups are analogous to a virtual disk drive." 

Are the folder (ie. /dev/lvm-raid)

Display Volume Groups: vgdisplay vgdisplay

After creating a physical volume make Linux scan for any new LVM disk partitions and automatically create the LVM configuration files in the /etc directory.: vgscan

Create the Volume Group vgcreate  vgcreate lvm-raid /dev/md0 vgcreate lvm-hde /dev/hdf1 /dev/hde5

"The default value for the physical extent size can be too low for a large RAID array. In those cases you'll need to specify the -s option with a larger than default physical extent size. The default is only 4MB as of the version in Fedora Core 5. The maximum number of physical extents is approximately 65k so take your maximum volume size and divide it by 65k then round it to the next nice round number. For example, to successfully create a 550G RAID let's figure that's approximately 550,000 megabytes and divide by 65,000 which gives you roughly 8.46. Round it up to the next nice round number and use 16M (for 16 megabytes) as the physical extent size and you'll be fine:" vgcreate -s 16M

Remove volume group: vgremove

Logical Volumes
"Logical Volumes: Volume groups must then be subdivided into logical volumes. Each logical volume can be individually formatted as if it were a regular Linux partition. A logical volume is, therefore, like a virtual partition on your virtual disk drive.

This may seem complicated, but it allows you to create new virtual partitions with sizes you can change from groups of real disk partitions whose sizes you probably cannot change. Another advantage of LVM is that this can all be done without disturbing other partitions on your hard disks. "

Are the partition (ie. /dev/lvm-raid lvm0)

Display Logical Volumes: lvdisplay lvdisplay

"Ok, you've created a blank receptacle but now you have to tell how many Physical Extents from the physical device (/dev/md0 in this case) will be allocated to this Volume Group. In my case I wanted all the data from /dev/md0 to be allocated to this Volume Group. If later I wanted to add additional space I would create a new RAID array and add that physical device to this Volume Group.

To find out how many PEs are available to me use the vgdisplay command to find out how many are available and now I can create a Logical Volume using all (or some) of the space in the Volume Group. In my case I call the Logical Volume lvm0." vgdisplay lvm-raid  ...  Free  PE / Size       57235 / 223.57 GB lvcreate -l 57235 lvm-raid -n lvm0

Note: You can also define percentages of the volume group to be used. The first example defines the use of 100% of the volume group's free space and the second example specifies using 50% of the total volume group.  sh-2.05b# lvcreate -l 100%FREE -n lvm0 lvm-hde sh-2.05b# lvcreate -l 50%VG -n lvm0 lvm-hde

Create Logical Volume: lvcreate -l  -n lvcreate -l 57235 lvm-raid -n lvm0

Remove logical volume: lvremove

Mounting LVM Logical Volume
Format LVM device: mkfs.ext3 /dev/[VG]/[LV]

Mount LVM device: mount /dev/[VG]/[LV] /data

Extend an LVM partition
Extend volume group: vgextend my_volume_group /dev/hdc1

Extend logical volume: lvextend -L12G /dev/myvg/homevol lvextend -L+1G /dev/myvg/homevol
 * 1) will extend /dev/myvg/homevol to 12 Gigabytes.
 * 1) will add another gigabyte to /dev/myvg/homevol.

Resize ext2/ext3: umount /dev/myvg/homevol resize2fs /dev/myvg/homevol mount /dev/myvg/homevol /home

Resize reiserfs: resize_reiserfs -f /dev/myvg/homevol
 * 1) Reiserfs file systems can be resized when mounted or unmounted as you prefer:

Resize xfs: xfs_growfs /home Resize jfs: mount -o remount,resize /home
 * 1) XFS file systems must be mounted to be resized and the mount-point is specified rather than the device name.
 * 1) Just like XFS the JFS file system must be mounted to be resized and the mount-point is specified rather
 * 2) than the device name.  You need at least Version 1.0.21 of the jfs-utils to do this.

References:
 * LVM HOWTO: Extending a logical volume
 * Extending LVM partition
 * How To Resize ext3 Partitions Without Losing Data

Tutorials

 * Expanding Disk Capacity
 * The Software-RAID HOWTO