LVM Logical Volumes
A logical volume is created in a volume group. Logical volumes that contain a file system can be mounted. The use of logical volumes is similar to the use of partitions and is accomplished with the same standard commands (mkfs, mount, fsck, df, ...).
The commands used to manage a logical volume start with lv
:
lvchange lvextend lvconvert lvm lvcreate lvmchange lvdisplay lvmconf lvmdiskscan lvmdump lvmetad lvmsadc lvmsar lvreduce lvremove lvrename lvresize lvs lvscan
lvcreate
Use the lvcreate command to create Logical Volumes in a Volume Group. This example creates an 8GB Logical Volume in Volume Group vg32:
# lvcreate -L5G vg32 Logical volume "lvol0" created
As you can see, lvm automatically names the Logical Volume lvol0
. The next example creates a 200MB Logical Volume named MyLV in Volume Group vg32:
# lvcreate -L200M -nMyLV vg32 Logical volume "MyLV" created
The next example does the same thing, but with different syntax:
# lvcreate --size 200M -n MyLV vg32 Logical volume "MyLV" created
This example creates a Logical Volume that occupies 10 percent of the Volume Group:
# lvcreate -l 10%VG -n MyLV2 vg32 Logical volume "MyLV2" created
This example creates a Logical Volume that occupies 30 percent of the remaining free space in the Volume Group:
# lvcreate -l 30%FREE -n MyLV3 vg32 Logical volume "MyLV3" created
lvremove
Use the lvremove command to remove Logical Volumes from a Volume Group. Removing a Logical Volume requires the name of the Volume Group.
# lvremove vg32/MyLV Do you really want to remove active logical volume "MyLV"? [y/n]: y Logical volume "MyLV" successfully removed
Removing multiple Logical Volumes will request confirmation for each individual volume.
# lvremove vg32/MyLV vg32/MyLV2 vg32/MyLV3 Do you really want to remove active logical volume "MyLV"? [y/n]: y Logical volume "MyLV" successfully removed Do you really want to remove active logical volume "MyLV2"? [y/n]: y Logical volume "MyLV2" successfully removed Do you really want to remove active logical volume "MyLV3"? [y/n]: y Logical volume "MyLV3" successfully removed
lvextend
Extending the volume is easy with lvextend. This example extends a 200MB Logical Volume with 100 MB:
# lvdisplay /dev/vg32/lvol0 | grep Size LV Size 200.00 MB # lvextend -L +100 /dev/vg32/lvol0 Extending logical volume lvol0 to 300.00 MB Logical volume lvol0 successfully resized # lvdisplay /dev/vg32/lvol0 | grep Size LV Size 300.00 MB
The next example creates a 100MB Logical Volume, and then extends it to 500MB:
# lvcreate --size 100M -n extLV vg32 Logical volume "extLV" created # lvextend -L 500M vg32/extLV Extending logical volume extLV to 500.00 MB Logical volume extLV successfully resized
This example doubles the size of a Logical Volume.
# lvextend -l+100%LV vg32/extLV Extending logical volume extLV to 1000.00 MB Logical volume extLV successfully resized
lvrename
Renaming a Logical Volume is done with lvrename. This example renames extLV to bigLV in the vg32 Volume Group:
# lvrename vg32/extLV vg32/bigLV Renamed "extLV" to "bigLV" in volume group "vg32"
lvs
Use lvs
for a quick look at all existing logical volumes. Below you can see two logical volumes named LogVol00 and LogVol01:
# lvs LV VG Attr LSize Origin Snap% Move Log Copy% LogVol00 vg33 -wi-ao 14.88G LogVol01 vg33 -wi-ao 1.00G
lvscan
The lvscan command will scan all disks for existing Logical Volumes:
# lvscan ACTIVE '/dev/vg33/LogVol00' [14.88 GB] inherit ACTIVE '/dev/vg33/LogVol01' [1.00 GB] inherit
lvdisplay
More detailed information about logical volumes is available through the lvdisplay
command.
# lvdisplay vg33/LogVol01 --- Logical volume --- LV Name /dev/vg33/LogVol01 VG Name vg33 LV UUID RnTGK6-xWsi-t530-ksJx-7cax-co5c-A1KlDp LV Write Access read/write LV Status available # open 1 LV Size 1.00 GB Current LE 32 Segments 1 Allocation inherit Read ahead sectors 0 Block device 253:1