LVM: Difference between revisions

From Omnia
Jump to navigation Jump to search
(No difference)

Revision as of 15:26, 24 June 2014

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.

LVM Components

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." [1]

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 <device>

Initialize a disk or parition for use by LVM:

pvcreate /dev/<device/partition>
pvcreate /dev/md0
pvcreate /dev/sda1

Remove physical volume:

pvremove <device>

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." [2]

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

Display Volume Groups:

vgdisplay
vgdisplay <volume group name>

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 <volume group name> <physical volume(s)>
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:" [3]

vgcreate -s 16M <volume group name> <physical volume>

Remove volume group:

vgremove <volume group name>

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. " [4]

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

Display Logical Volumes:

lvdisplay
lvdisplay <logical volume name>

"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." [5]

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. [6]

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 <PEs> <volume group name> -n <logical volume name>
lvcreate -l 57235 lvm-raid -n lvm0

Remove logical volume:

lvremove <logical volume name>

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:

# will extend /dev/myvg/homevol to 12 Gigabytes.
lvextend -L12G /dev/myvg/homevol 

# will add another gigabyte to /dev/myvg/homevol.
lvextend -L+1G /dev/myvg/homevol

Resize ext2/ext3:

umount /dev/myvg/homevol
resize2fs /dev/myvg/homevol
mount /dev/myvg/homevol /home

Resize reiserfs:

# Reiserfs file systems can be resized when mounted or unmounted as you prefer:
resize_reiserfs -f /dev/myvg/homevol

Resize xfs:

# XFS file systems must be mounted to be resized and the mount-point is specified rather than the device name.
xfs_growfs /home
           

Resize jfs:

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

References:

Tutorials

References

keywords