Show Table of Contents
5.4. Logical Volume Administration
This section describes the commands that perform the various aspects of logical volume administration.
5.4.1. Creating Linear Logical Volumes
To create a logical volume, use the
lvcreatecommand. If you do not specify a name for the logical volume, the default name
lvol#is used where # is the internal number of the logical volume.
When you create a logical volume, the logical volume is carved from a volume group using the free extents on the physical volumes that make up the volume group. Normally logical volumes use up any space available on the underlying physical volumes on a next-free basis. Modifying the logical volume frees and reallocates space in the physical volumes.
As of the Red Hat Enterprise Linux 6.3 release, you can use LVM to create, display, rename, use, and remove RAID logical volumes. For information on RAID logical volumes, see Section 5.4.16, “RAID Logical Volumes”.
The following command creates a logical volume 10 gigabytes in size in the volume group
lvcreate -L 10G vg1
The default unit for logical volume size is megabytes. The following command creates a 1500 MB linear logical volume named
testlvin the volume group
testvg, creating the block device
lvcreate -L 1500 -n testlv testvg
The following command creates a 50 gigabyte logical volume named
gfslvfrom the free extents in volume group
lvcreate -L 50G -n gfslv vg0
You can use the
-largument of the
lvcreatecommand to specify the size of the logical volume in extents. You can also use this argument to specify the percentage of the volume group to use for the logical volume. The following command creates a logical volume called
mylvthat uses 60% of the total space in volume group
lvcreate -l 60%VG -n mylv testvg
You can also use the
-largument of the
lvcreatecommand to specify the percentage of the remaining free space in a volume group as the size of the logical volume. The following command creates a logical volume called
yourlvthat uses all of the unallocated space in the volume group
lvcreate -l 100%FREE -n yourlv testvg
You can use
-largument of the
lvcreatecommand to create a logical volume that uses the entire volume group. Another way to create a logical volume that uses the entire volume group is to use the
vgdisplaycommand to find the "Total PE" size and to use those results as input to the
The following commands create a logical volume called
mylvthat fills the volume group named
vgdisplay testvg | grep "Total PE"Total PE 10230 #
lvcreate -l 10230 testvg -n mylv
The underlying physical volumes used to create a logical volume can be important if the physical volume needs to be removed, so you may need to consider this possibility when you create the logical volume. For information on removing a physical volume from a volume group, see Section 5.3.7, “Removing Physical Volumes from a Volume Group”.
To create a logical volume to be allocated from a specific physical volume in the volume group, specify the physical volume or volumes at the end at the
lvcreatecommand line. The following command creates a logical volume named
testlvin volume group
testvgallocated from the physical volume
lvcreate -L 1500 -ntestlv testvg /dev/sdg1
You can specify which extents of a physical volume are to be used for a logical volume. The following example creates a linear logical volume out of extents 0 through 24 of physical volume
/dev/sda1and extents 50 through 124 of physical volume
/dev/sdb1in volume group
lvcreate -l 100 -n testlv testvg /dev/sda1:0-24 /dev/sdb1:50-124
The following example creates a linear logical volume out of extents 0 through 25 of physical volume
/dev/sda1and then continues laying out the logical volume at extent 100.
lvcreate -l 100 -n testlv testvg /dev/sda1:0-25:100-
The default policy for how the extents of a logical volume are allocated is
inherit, which applies the same policy as for the volume group. These policies can be changed using the
lvchangecommand. For information on allocation policies, see Section 5.3.1, “Creating Volume Groups”.