lvcreate Command Examples in Linux

lvcreate is a Linux command used to create a logical volume (LV) in a Linux Logical Volume Manager (LVM) setup. A logical volume is a virtual block device that provides a layer of abstraction between the physical storage and the file system. This allows for more flexible and dynamic management of storage, such as resizing and moving of volumes without affecting the data.

lvcreate command is used basically to create a new logical volume in LVM. To create a basic LVM volume, you can use the below command:

$ sudo lvcreate -l 100%FREE -n lvtest Vol1
  Logical volume “lvtest” created

If you want to see the details of what you created, use the lvdisplay command:

$ sudo lvdisplay Vol1
  --- Logical volume ---
  LV Path                 /dev/Vol1/lvtest
  LV Name                 lvtest
  VG Name                 Vol1
  LV UUID                 4W2369-pLXy-jWmb-lIFN-SMNX-xZnN-3KN208
  LV Write Access         read/write
  LV Creation host, time  … -0400
  LV Status               available
  # open                  0
  LV Size                 2.00 GiB
  Current LE              513
  Segments                1
  Allocation              inherit
  Read ahead sectors      auto
  - currently set to      256
  Block device            253:2

The -l parameter defines how much of the available space on the volume group specified to use for the logical volume. Notice that you can specify the value as a percent of the free space in the volume group. This example used all (100%) of the free space for the new logical volume.

You can use the -l parameter to specify the size as a percentage of the available space or the -L parameter to specify the actual size in bytes, kilobytes (KB), megabytes (MB), or gigabytes (GB). The -n parameter allows you to provide a name for the logical volume (called lvtest in this example).

LVM command options are as shown below:

lvcreate Command examples

1. To Power of 2 chunk size for the snapshot logical volume between 4k and 512k:

# lvcreate -c ChunkSize
# lvcreate --chunksize ChunkSize

2. To Sets or resets the contiguous allocation policy for logical volumes:

# lvcreate -C y|n
# lvcreate --contiguous y|n

3. To give the number of stripes

# lvcreate -i stripes:
# lvcreate --stripes stripes

4. To Gives the number of kilobytes for the granularity of the stripes:

# lvcreate -I StripeSize
# lvcreate --stripesize StripeSize

5. To give the number of logical extents to allocate for the new logical volume:

# lvcreate -l LogicalExtentsNumber[%{VG|PVS|FREE|ORIGIN}
# lvcreate --extents LogicalExtentsNumber[%{VG|PVS|FREE|ORIGIN}

6. To give the size to allocate for the new logical volume:

# lvcreate -L --size LogicalVolumeSize[bBsSkKmMgGtTpPeE]

7. To set the minor number:

# lvcreate --minor minor

8. To Set to y to make the minor number specified persistent:

# lvcreate -M y|n
# lvcreate --persistent y|n

9. To creates a mirrored logical volume with Mirrors copies:

# lvcreate -m mirrors
# lvcreate --mirrors mirrors

10. To give name for the new logical volume:

# lvcreate -n LogicalVolumeName
# lvcreate --name LogicalVolumeName

11. To disable udev synchronization:

# lvcreate --noudevsync

12. To Start or avoid monitoring a mirrored or snapshot logical volume with dmeventd:

# lvcreate --monitor y|n

13. To Make no attempt to interact with dmeventd unless –monitor is specified:

# lvcreate --ignoremonitoring

14. To Set access permissions to read only or read and write:

# lvcreate -p r|rw
# lvcreate --permission r|rw

15. To set read ahead sector count of this logical volume:

# lvcreate -r ReadAheadSectors|auto|none
# lvcreate --readahead ReadAheadSectors|auto|none

16. To divide the mirror into regions:

# lvcreate -R MirrorLogRegionSize
# lvcreate --regionsize MirrorLogRegionSize

17. To Create a snapshot logical volume (or snapshot) for an existing:

# lvcreate -s
# lvcreate --snapshot

18. To create a logical volume that uses the specified segment type:

# lvcreate --type SegmentType

19. To Create a sparse device of the given size (in MB by default) using a snapshot:

# lvcreate --virtualsize VirtualSize

20. To Controls zeroing of the first KB of data in the new logical volume:

# lvcreate -Z y|n
# lvcreate --zero y|n
Related Post