Logical Volume Manager (Linux)
From Wikipedia, the free encyclopedia
LVM is an implementation of a logical volume manager for the Linux kernel. It was originally written in 1998 by Heinz Mauelshagen, who based its design on that of the LVM in HP-UX.
A normal disk partition suffers from a disadvantage that once a partition is occupied you cannot add further space to the mount point even if the disk has free space in it. In such a case an LVM ( Logical Volume Manager ) comes to the rescue. For example, if in /data "disk partition" you have 100% occupied disk space and you want to add further space to the mount point, all you have to do is umount the disk partition, create a new filesystem and mount it under /data. In the case of LVM you can extend the logical boundaries of your hard disk partition to current free space on HardDisk or a new hard disk. I.E. you can attach a new drive to the mount point /data.
LVM includes most of the features expected of a volume manager, including:
- Online resizing of VGs
- Online resizing of LVs
- Read-only snapshotting (LVM2 has read/write support for snapshots)
- RAID0 striping of LVs.
LVM does not implement RAID1 or RAID5 mirroring of LVs. Instead, it is recommended that one use the Linux software RAID driver to mirror the underlying physical volumes to achieve redundancy.
[edit] Creating an LV
We have disk partitions /dev/sda3, /dev/sdb1 and /dev/hda2 free for use and want to create a volume group named "test_vg". Steps required:
1. Change partition type for these 3 partitions to 0x8e with fdisk (see pvcreate(8): 0x8e identifies LVM partitions) 2. pvcreate /dev/sda3 /dev/sdb1 /dev/hda2 3. vgcreate test_vg /dev/sda3 /dev/sdb1 /dev/hda2
With our volume group "test_vg" now online, we can create logical volumes. For example a logical volume with a size of 100MB and standard name (/dev/test_vg/lvol1) and another one named "my_test_lv" with size 200MB striped (RAID0) across all the three physical volumes. Steps required:
1. lvcreate -L 100 test_vg 2. lvcreate -L 200 -n my_test_lv -i 3 test_vg
For example create a file system with mkfs -t ext2 /dev/test_vg/my_test_lv
and mount it with mount /dev/test_vg/my_test_lv /usr1
[edit] Resizing an LV
If a logical volume does not occupy the full space of a volume group (e.g. you added a physical partition after creating it) then you can resize it using the lvextend command. For this example we're going to extend the logical volume created above (my_test_lv).
lvextend -L +64G /dev/test_vg/my_test_lv