lvcreate
Create a logical volume
TLDR
Create a logical volume of 10 gigabytes in the volume group vg1
Create a 1500 megabyte linear logical volume named mylv in the volume group vg1
Create a logical volume called mylv that uses 60% of the total space in volume group vg1
Create a logical volume called mylv that uses all the unallocated space in the volume group vg1
SYNOPSIS
lvcreate {OPTIONS} {VolumeGroupName} [{LogicalVolumeName}]
PARAMETERS
-L Size[bBsSkKmMgGtTpPeE]
Create a logical volume of a specific Size. This is the most common way to specify the logical volume's extent in bytes, kilobytes, megabytes, gigabytes, etc. (e.g., -L 10G).
-l LogicalExtents | Percentage{VG|PV|LV|FREE|ORIGIN}
Create a logical volume using a number of LogicalExtents or a Percentage of the volume group, physical volume, or existing logical volume's free space. For example, -l 50%FREE uses half of the available free space.
-n LogicalVolumeName
Specify the LogicalVolumeName for the new logical volume. If not provided, LVM typically generates a default name like 'lvol#'.
-s
Create a snapshot logical volume. This option must be used with an existing logical volume as the origin for the snapshot.
-V VirtualSize[bBsSkKmMgGtTpPeE]
Create a thin provisioned logical volume with a given VirtualSize. This logical volume will consume space from a thin pool only as data is written to it.
--thinpool ThinPoolLVPath
Specify the existing thin pool logical volume from which a new thin logical volume should consume space. Required when creating thin LVs with -V.
--type {snapshot|mirror|raidX|thin-pool}
Specify the type of logical volume to create. Common types include snapshot, mirror, raidX (e.g., raid1, raid5), and thin-pool.
-C|--contiguous {y|n}
Force the allocation of contiguous logical extents on the physical volume. This can limit flexibility but might be useful for specific performance requirements.
-m Mirrors
Create a mirrored logical volume with the specified number of additional data copies (Mirrors). For example, -m 1 creates a two-copy mirror (original + 1 mirror).
-r|--regionsize RegionSize[bBsSkKmMgGtTpPeE]
Specify the size of regions for RAID or mirror LVs. Smaller regions can improve performance for random I/O but increase metadata overhead.
-Z|--zero {y|n}
Controls whether the first KBytes of the new logical volume are zeroed. Default is 'y' for most types of LVs to ensure data integrity, especially for filesystems.
-K|--skipactivation
Do not activate the logical volume immediately after creation. Useful for maintenance or when the LV needs to be configured before activation.
DESCRIPTION
The lvcreate command is a fundamental utility within the Linux Logical Volume Manager (LVM) framework. It is used to create new logical volumes (LVs) from the free space within an existing volume group (VG). Logical volumes serve as flexible, resizable 'partitions' that can span multiple physical volumes (PVs) and provide advanced storage management features such as snapshots, striping, and mirroring. lvcreate allows administrators to specify the size, name, and type of the new logical volume, tailoring it to specific application or system requirements. It's a crucial step in setting up storage before it can be formatted with a filesystem or used by applications, offering greater flexibility than traditional disk partitioning.
CAVEATS
Creating a logical volume consumes free space from the volume group; ensure sufficient capacity before creation. While lvcreate itself doesn't typically cause data loss, incorrect sizing or misidentification of the volume group can lead to unexpected behavior or resource depletion. For thin provisioned LVs, it's crucial to monitor the thin pool's usage to prevent out-of-space conditions, which can halt I/O for all LVs within that pool. Snapshot LVs are dependent on their origin LV; if the origin is removed or heavily modified, the snapshot may become unusable.
THIN PROVISIONING
lvcreate is central to thin provisioning in LVM. You can create a thin pool (e.g., lvcreate --type thin-pool -L 100G -n my_pool my_vg) and then create thin logical volumes within that pool (e.g., lvcreate -V 500G --thinpool my_vg/my_pool -n my_thin_lv). Thin LVs appear significantly larger than their actual allocated space, only consuming physical storage from the pool as data is written. This allows for efficient space utilization and over-provisioning.
SNAPSHOTS
Using the -s option, lvcreate can create a point-in-time snapshot of an existing logical volume. Snapshots are copy-on-write, meaning only changes to the origin or snapshot are stored, making them highly efficient for backups, testing, or quick rollback operations. Example: lvcreate -s -L 5G -n my_lv_snap my_vg/my_lv. The snapshot size determines how many changes it can record before running out of space.
HISTORY
Logical Volume Manager (LVM) in Linux was first introduced around the year 2000, inspired by similar implementations in commercial Unix systems. lvcreate has been a core command since LVM's inception, providing the fundamental capability to carve out flexible storage units from underlying physical storage. Over time, its functionality has expanded to include support for advanced features like snapshots, mirroring, striping (RAID), and more recently, thin provisioning, reflecting the evolving needs of modern storage management and virtualization.