Once you have created the Physical volumes and volume groups, the next step is to create logical volumes from the space allocated to volume groups. The post discusses few of the most commonly used logical volume related commands and utilities.
Creating Logical Volumes
Use the lvcreate command to create a new logical volume. This command automatically creates the block device nodes in the /dev directory. The syntax is:
# lvcreate [options] --size [size] --name LV_name VG_name
The –size option defines the size of the logical volume by allocating logical extents from the free physical extent pool of the volume group. For example, to create a logical volume named lv01 from the volume group named vg01 with a size of 2 GB, enter:
# lvcreate -v --size 2g --name lv01 vg01 Archiving volume group "vg01" metadata (seqno 1). Creating logical volume lv01 Creating volume group backup "/etc/lvm/backup/vg01" (seqno 2). Activating logical volume vg01/lv01. activation/volume_list configuration setting not defined: Checking only host tags for vg01/lv01. Creating vg01-lv01 Loading vg01-lv01 table (253:2) Resuming vg01-lv01 (253:2) Wiping known signatures on logical volume "vg01/lv01" Initializing 4.00 KiB of logical volume "vg01/lv01" with value 0. Logical volume "lv01" created.
Displaying Logical Volumes
Use the lvdisplay command to display the attributes of logical volumes.
# lvdisplay vg01/lv01 --- Logical volume --- LV Path /dev/vg01/lv01 LV Name lv01 VG Name vg01 LV UUID DyCyoq-5fF1-HujN-WeUi-XvYN-eloM-wdDSVt LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-10-02 13:28:01 +0530 LV Status available # open 0 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2
In addition to lvdisplay, two other commands list information about logical volumes. The lvs command reports information about logical volumes in a more condensed form. The lvscan command scans all disks for logical volumes. Example:
# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root cl -wi-ao---- 17.00g swap cl -wi-ao---- 2.00g lv01 vg01 -wi-a----- 2.00g
# lvscan ACTIVE '/dev/cl/swap' [2.00 GiB] inherit ACTIVE '/dev/cl/root' [17.00 GiB] inherit ACTIVE '/dev/vg01/lv01' [2.00 GiB] inherit
Removing Logical Volumes
Use the lvremove command to remove a logical volume. You must include the volume group name as well as the logical volume name. You are prompted to confirm your request. Example:
# lvremove vg01/lv01 Do you really want to remove active logical volume vg01/lv01? [y/n]: y Logical volume "lv01" successfully removed
Additional LV Commands
The following commands are used to manipulate logical volumes :
- lvchange : Change the attributes of logical volumes.
- lvconvert : Change logical volume layout.
- lvextend : Add space to a logical volume.
- lvmdiskscan : List devices that may be used as physical volumes.
- lvmsadc : Collect activity data.
- lvmsar : Create activity report.
- lvreduce : Reduce the size of a logical volume.
- lvrename : Rename a logical volume.
- lvresize : Resize a logical volume.