18.3.3 Creating and Managing Logical Volumes

Having create a volume group of physical volumes, you can create logical volumes from the storage space that is available in the volume group.

To create a logical volume, use the lvcreate command:

# lvcreate [options] --size size --name logical_volume volume_group

For example, create the logical volume mylv of size 2 GB in the volume group myvg:

# lvcreate -v --size 2g --name mylv myvg
Setting logging type to disk
Finding volume group “myvg”
Archiving volume group “myvg” metadata (seqno 1).
Creating logical volume mylv
Create volume group backup “/etc/lvm/backup/myvg” (seqno 2).
...

lvcreate uses the device mapper to create a block device file entry under /dev for each logical volume and uses udev to set up symbolic links to this device file from /dev/mapper and /dev/volume_group. For example, the device that corresponds to the logical volume mylv in the volume group myvg might be /dev/dm-3, which is symbolically linked by /dev/mapper/myvolg-myvol and /dev/myvolg/myvol.

Note

Always use the devices in /dev/mapper or /dev/volume_group. These names are persistent and are created automatically by the device mapper early in the boot process. The /dev/dm-* devices are not guaranteed to be persistent across reboots.

Having created a logical volume, you can configure and use it in the same way as you would a physical storage device. For example, you can configure a logical volume as a file system, swap partition, Automatic Storage Management (ASM) disk, or raw device.

You can also use lvcreate to create a snapshot of an existing logical volume such as mylv in the volume group myvg, for example:

# lvcreate --size 500m --snapshot --name mylv-snapshot myvg/mylv
  Logical volume “mylv-snapshot” created

You can mount and modify the contents of the snapshot independently of the original volume or preserve it as a record of the state of the original volume at the time that you took the snapshot. The snapshot usually takes up less space than the original volume, depending on how much the contents of the volumes diverge over time. In the example, we assume that the snapshot only requires one quarter of the space of the original volume. You can use the value shown by the Snap% column in the output from the lvs command to see how much data is allocated to the snapshot. If the value of Snap% approaches 100%, indicating that a snapshot is running out of storage, use lvresize to grow it. Alternatively, you can reduce a snapshot's size to save storage space. To merge a snapshot with its original volume, use the lvconvert command, specifying the --merge option.

To display information about logical volumes, you can use the lvdisplay, lvs, and lvscan commands.

To remove a logical volume from a volume group, use the lvremove command:

# lvremove volume_group/logical_volume
Note

You must specify both the name of the volume group and the logical volume.

Other commands that are available for managing logical volumes include lvchange, lvconvert, lvmdiskscan, lvmsadc, lvmsar, lvrename, and lvresize.

For more information, see the lvm(8), lvcreate(8), and other LVM manual pages.