Lvcreate
Create Logical Volumes with Lvcreate
The lvcreate command is a fundamental tool in the Linux
Logical Volume Manager (LVM) suite, used for creating new logical
volumes. Logical volumes provide a flexible layer of abstraction over
physical storage, allowing for easier management of disk space,
resizing, snapshots, and more. This guide provides essential examples
of how to use lvcreate to manage your storage
effectively.
Lvcreate Command Examples
Below are common use cases and examples for the
lvcreate command:
Create a new logical volume with a specified size
This command creates a logical volume named my_lv within
the volume group my_vg, allocating exactly 10 Gigabytes
of space.
# lvcreate -L 10G -n my_lv my_vg
Create a logical volume using a percentage of the volume group
This example creates a logical volume that occupies 50% of the total
available space in the volume group my_vg.
# lvcreate -l 50%VG -n my_lv my_vg
Create a mirror logical volume
This command creates a mirrored logical volume with two copies (one original and one mirror) for data redundancy, using 10 Gigabytes of space.
# lvcreate -m 1 -L 10G -n my_mirror_lv my_vg
Create a thin logical volume from a thin pool
Thin provisioning allows for over-allocation of storage. This command
creates a thin logical volume my_thin_lv with a virtual
size of 10GB, drawing space from the thin pool my_pool in
my_vg.
# lvcreate -V 10G -T my_vg/my_pool -n my_thin_lv
Create a snapshot of an existing logical volume
Snapshots allow you to capture the state of a logical volume at a
specific point in time. This creates a 5GB snapshot named
my_snapshot of the logical volume
/dev/my_vg/my_lv.
# lvcreate -L 5G -s -n my_snapshot /dev/my_vg/my_lv
Create a striped logical volume
Striping distributes data across multiple physical volumes to improve
performance. This creates a striped logical volume
my_striped_lv using 2 stripes and 10 Gigabytes of space.
# lvcreate -i 2 -L 10G -n my_striped_lv my_vg
Create a logical volume with specific physical volumes
This command creates a 10GB logical volume my_pv_lv,
explicitly using /dev/sda1 and /dev/sdb1 as
its underlying physical volumes.
# lvcreate -L 10G -n my_pv_lv my_vg /dev/sda1 /dev/sdb1
Create a logical volume with specific permissions
This command creates a 10GB logical volume my_lv with
read-write (rw) permissions.
# lvcreate -L 10G -n my_lv -p rw my_vg
Create a logical volume specifying metadata size
This command creates a 10GB logical volume my_lv and
explicitly sets the metadata size to 128MB.
# lvcreate --size 10G --name my_lv --poolmetadatasize 128M my_vg
Create a logical volume with zeroing of the first block
The -Z y option ensures that the first block of the
logical volume is zeroed out upon creation, which can be useful for
security or clean state initialization.
# lvcreate -Z y -L 10G -n my_lv my_vg
Clone an LVM volume
Cloning an LVM volume typically involves creating a mirror and then splitting it. This process ensures data integrity during the cloning operation.
# Clone LVM volume: test => testCopy
lvconvert --type mirror --alloc anywhere -m1 /dev/mylv/test
lvs -a -o +devices | grep -E "LV|test"
# After Cpy%Sync is 100% finished:
lvconvert --splitmirrors 1 --name testCopy /dev/rootvg/test