lvcreate command is used to create logical volume.
To create a logical volume with disk size 10 GB inside volume group vg1, run
lvcreate --size 20G --name LV-NAME-HERE VG-NAME-HERE
First lets list all logical volumes on our server with command “lvs”.
[root@hon ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert kvm101_img vg1 -wi-a----- 33.00g kvm102_img vg1 -wi-a----- 50.00g kvm103_img vg1 -wi-a----- 20.00g [root@hon ~]#
Now create a logical volume with size 20 GB, name testlv1 inside volume group vg1.
[root@hon ~]# lvcreate --size 20G --name testlv1 vg1 Logical volume "testlv1" created. [root@hon ~]#
Let verify the logical volume created with lvs command.
[root@hon ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert kvm101_img vg1 -wi-a----- 33.00g kvm102_img vg1 -wi-a----- 50.00g kvm103_img vg1 -wi-a----- 20.00g testlv1 vg1 -wi-a----- 20.00g [root@hon ~]#
Making file system
If you want to create a file system, you can do this with command
mkfs.ext4 /dev/mapper/VG_NAME-LV-NAME
Example
[root@kvm ~]# lvcreate --size 100G --name vm1 vg_kvm Logical volume "vm1" created. [root@kvm ~]# mkfs.ext4 /dev/mapper/vg_kvm-vm1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 6553600 inodes, 26214400 blocks 1310720 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 800 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 37 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@kvm ~]# mount /dev/mapper/vg_kvm-vm1 /mnt [root@kvm ~]#
lvdisplay
You can also use lvdisplay command to list logical volumes.
[root@hon ~]# lvdisplay vg1/testlv1 --- Logical volume --- LV Path /dev/vg1/testlv1 LV Name testlv1 VG Name vg1 LV UUID W0yUvI-wpQz-TfJR-aCko-Gk98-oyPD-SIDSo4 LV Write Access read/write LV Creation host, time hon.hostonnet.com, 2017-09-02 20:53:55 -0700 LV Status available # open 0 LV Size 20.00 GiB Current LE 5120 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:3 [root@hon ~]#
To delete a logical volume use command lvremove