4 lvcreate Command Examples on Linux

lvcreate

Logical volume management (LVM) is a widely-used technique and extremely flexible disk management scheme. It basically contain three basic commands:

a. Creates the physical volumes using pvcreate
b. Create the volume group and add partition into volume group using vgcreate
c. Create a new logical volume using lvcreate

lvm-diagram1

The following examples focus on the command to create a logical volume in an existing volume group, lvcreate. lvcreate is the command to allocating logical extents from the free physical extent pool of that volume group. Normally logical volumes use up any space available on the underlying physical volumes on a next-free basis. Modifying the logical volume will free and reallocates space in the physical volumes. The following lvcreate command has been tested on Linux CentOS 5, CentOS 6, CentOS 7, RHEL 5, RHEl 6 and RHEL 7 version.

See also  How to Migrate LVM or Volume Group to New Linux Server

4 lvcreate Command Examples on Linux:

1. The following command creates a logical volume 15 gigabytes in size in the volume group vg_newlvm:

[root@centos7 ~]# lvcreate -L 15G vg_newlvm

2. The following command creates a 2500 MB linear logical volume named centos7_newvol in the volume group
vg_newlvm, creating the block device /dev/vg_newlvm/centos7_newvol:

[root@centos7 ~]# lvcreate -L 2500 -n centos7_newvol vg_newlvm

3. You can use the -l argument of the lvcreate command to specify the size of the logical volume in extent. 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 centos7_newvol that uses 50% of the total space in volume group vg_newlvm:

[root@centos7 ~]# lvcreate -l 50%VG -n centos7_newvol vg_newlvm

4. The following command creates a logical volume called centos7_newvol that uses all of the unallocated space in the volume group vg_newlvm:

[root@centos7 ~]# lvcreate --name centos7_newvol -l 100%FREE vg_newlvm

To see more lvcreate command options, issue the following command:

[root@centos7 ~]# lvcreate --help
lvcreate: Create a logical volume

lvcreate
        [-A|--autobackup {y|n}]
        [-a|--activate [a|e|l]{y|n}]
        [--addtag Tag]
        [--alloc AllocationPolicy]
        [--cachemode CacheMode]
        [-C|--contiguous {y|n}]
        [-d|--debug]
        [-h|-?|--help]
        [--ignoremonitoring]
        [--monitor {y|n}]
        [-i|--stripes Stripes [-I|--stripesize StripeSize]]
        [-k|--setactivationskip {y|n}]
        [-K|--ignoreactivationskip]
        {-l|--extents LogicalExtentsNumber[%{VG|PVS|FREE}] |
         -L|--size LogicalVolumeSize[bBsSkKmMgGtTpPeE]}
        [-M|--persistent {y|n}] [--major major] [--minor minor]
        [-m|--mirrors Mirrors [--nosync] [{--mirrorlog {disk|core|mirrored}|--corelog}]]
        [-n|--name LogicalVolumeName]
        [--noudevsync]
        [-p|--permission {r|rw}]
        [--[raid]minrecoveryrate Rate]
        [--[raid]maxrecoveryrate Rate]
        [-r|--readahead ReadAheadSectors|auto|none]
        [-R|--regionsize MirrorLogRegionSize]
        [-T|--thin  [-c|--chunksize  ChunkSize]
          [--discards {ignore|nopassdown|passdown}]
          [--poolmetadatasize MetadataSize[bBsSkKmMgG]]]
          [--poolmetadataspare {y|n}]
        [--thinpool ThinPoolLogicalVolume{Name|Path}]
        [-t|--test]
        [--type VolumeType]
        [-v|--verbose]
        [-W|--wipesignatures {y|n}]
        [-Z|--zero {y|n}]
        [--version]
        VolumeGroupName [PhysicalVolumePath...]

lvcreate
        { {-s|--snapshot} OriginalLogicalVolume[Path] |
          [-s|--snapshot] VolumeGroupName[Path] -V|--virtualsize VirtualSize}
          {-T|--thin} VolumeGroupName[Path][/PoolLogicalVolume]
                      -V|--virtualsize VirtualSize}
        [-c|--chunksize]
        [-A|--autobackup {y|n}]
        [--addtag Tag]
        [--alloc AllocationPolicy]
        [-C|--contiguous {y|n}]
        [-d|--debug]
        [--discards {ignore|nopassdown|passdown}]
        [-h|-?|--help]
        [--ignoremonitoring]
        [--monitor {y|n}]
        [-i|--stripes Stripes [-I|--stripesize StripeSize]]
        [-k|--setactivationskip {y|n}]
        [-K|--ignoreactivationskip]
        {-l|--extents LogicalExtentsNumber[%{VG|FREE|ORIGIN}] |
         -L|--size LogicalVolumeSize[bBsSkKmMgGtTpPeE]}
        [--poolmetadatasize MetadataVolumeSize[bBsSkKmMgG]]
        [-M|--persistent {y|n}] [--major major] [--minor minor]
        [-n|--name LogicalVolumeName]
        [--noudevsync]
        [-p|--permission {r|rw}]
        [-r|--readahead ReadAheadSectors|auto|none]
        [-t|--test]
        [--thinpool ThinPoolLogicalVolume[Path]]
        [-v|--verbose]
        [--version]
        [PhysicalVolumePath...]

How to Reset the Directory Manager Password on RHEL 7 / CentOS 7
How to Reset the Directory Manager Password on RHEL 7 / CentOS 7

It is best practice to remember passwords, but because too many passwords, sometimes we forget. We are not encouraged to write the password on any paper or share the password...

How to Find Big Files Size on Linux RHEL/CentOS
How to Find Big Files Size on Linux RHEL/CentOS

As the linux administrator, sometimes we have to identify which files are most take much space in the linux server resulting in low free space. Low disk space can also...

Why Linux users should worry about malware and what they can do about it
Why Linux users should worry about malware and what they can do about it

Don’t drop your guard just because you’re running Linux. Preventing the spread of malware and/or dealing with the consequences of infection are a fact of life when using computers. If...

How to Reset Forgotten Root Password on Linux RHEL 7 / CentOS 7
How to Reset Forgotten Root Password on Linux RHEL 7 / CentOS 7

This short howto will explain the steps to reset a lost root password or to reset a forgotten root password on Linux RHEL 7 or CentOS 7. Basically, we will...

How to Update CentOS or Upgrade CentOS to the Latest Version
How to Update CentOS or Upgrade CentOS to the Latest Version

Recently, the latest version of CentOS 7.3 was released. All users of CentOS 7.0, 7.1 and 7.2 can upgrade their system to the most recent. This quick guide will explain...

How to Change your WordPress Username, Nickname and Display Name in MySQL
How to Change your WordPress Username, Nickname and Display Name in MySQL

After you create an account log in WordPress, you may want to change your WordPress username, as appropriate or due to security reason. However, you can not do this from...

How to Enable SSH Root Login on Ubuntu 16.04
How to Enable SSH Root Login on Ubuntu 16.04

As what we wrote in the previous article on how to allow SSH root on Ubuntu 14.04, after installing a fresh new copy of Ubuntu 16.04 LTS, we find that...

How to Change UUID of Linux Partition on CentOS 7
How to Change UUID of Linux Partition on CentOS 7

UUID (Universally Unique IDentifier) should be unique and it is used to identify storage devices on a linux system. If you cloned a virtual machine from vCenter, the metadata containing...

Leave a Reply

Your email address will not be published. Required fields are marked *