∟Create LV on VG on the Fly

Describes what is a LV (Logical Volume) - A virtual storage partition in a VG (Volume Group) managed by the LVM. A tutorial example is given on how to create a new LV on a VG.

What Is LV (Logical Volume)? LV represents a virtual storage partition in a VG (Volume Group) managed by the LVM (Logical Volume Manager). A LV can be formatted into a specific file system.

There are a number commands provided on CentOS 8 systems for you to create and manage PVs.

1. List all LVs that are currently managed by LVM using the "lvs" command, which is a also sub-command of the "lvm" command. The output shows that I have 3 LVs named hosted on the "cl" VG.

herong$ sudo lvs
  LV   VG Attr       LSize   Pool Origin Data%  Meta%  ...
  home cl -wi-ao---- 138.94g
  root cl -wi-ao----  50.00g
  swap cl -wi-ao----   7.71g

2. Display details of each LV using the "lvdisplay" command, which is also a sub-command of the "lvm" command. The output shows the VG's format is "lvm2".

herong$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/cl/swap
  LV Name                swap
  VG Name                cl
  LV UUID                gMCDUY-Ew9v-OFBj-pOuq-lZ27-...
  LV Write Access        read/write
  LV Creation host, time localhost, 2020-03-27 05:01:49 +0800
  LV Status              available
  # open                 2
  LV Size                7.71 GiB
  Current LE             1974
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/cl/home
  LV Name                home
  VG Name                cl
  LV UUID                GTeo46-cl6I-XFL8-tCvb-vCeN-...
  LV Write Access        read/write
  LV Creation host, time localhost, 2020-03-27 05:01:49 +0800
  LV Status              available
  # open                 1
  LV Size                138.94 GiB
  Current LE             35569
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

  ...

As you can see from the output, a LV has 3 identities:

How To Create a New LV on a VG? If you have free spaces on a VG, you create a new LV using the "lvcreate" command.

1. Check free space on VG. I see "data" VG has 93 GiB of free space.

herong$ sudo vgs
  VG   #PV #LV #SN Attr   VSize   VFree
  cl     2   3   0 wz--n-   1.00t 831.69g
  data   1   0   0 wz--n-  93.13g  93.13g

2. Create a new PV called "hr" with 10GiB on "data" using "lvcreate" command.

herong$ sudo lvcreate -L 10G -n hr data
  Logical volume "hr" created.

herong$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/data/hr
  LV Name                hr
  VG Name                data
  LV UUID                2upNkI-v5p8-ctQZ-mBPD-CmKC-...
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3

3. Check the device path of the new LV using "file -s" command. The new LV is not formatted with file system yet and can be used as "data" device, also called "byte" device.

...
herong$ sudo file -s /dev/data/hr
/dev/data/hr: symbolic link to ../dm-3

herong$ sudo file -s /dev/dm-3
/dev/dm-3: data

4. Create an "ext4" file system on the LV using "mkfs" command.

herong$ sudo mkfs -t ext4 /dev/data/hr
mke2fs 1.44.6 (5-Mar-2019)
Creating filesystem with 2621440 4k blocks and 655360 inodes
Filesystem UUID: b560da43-52a3-41c4-98a9-...
Superblock backups stored on blocks:
  32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

herong$ sudo file -s /dev/dm-3
/dev/dm-3: Linux rev 1.0 ext4 filesystem data, UUID=b560da43-52a3-...

5. Mount the file system on the LV. I see new file system path, /dev/mapper/data-hr, is given to the LV.

herong$ sudo mount /dev/data/hr /mnt/temp

herong$ ls -l /mnt/temp
total 16
drwx------. 2 root root 16384 Mar 22 14:20 lost+found

herong$ df
Filesystem            1K-blocks      Used Available Use% Mounted on
/dev/mapper/data-hr    10255636     36888   9678076   1% /mnt/temp

Cool. I have successfully create a LV on a VG, and formatted it as an "ext4" file system.

Table of Contents

 About This Book

 Introduction to Linux Systems

 Cockpit - Web Portal for Administrator

 Process Management

 Memory Management

 Files and Directories

 Users and Groups

 File Systems

 Block Devices and Partitions

►LVM (Logical Volume Manager)

 What Is LVM (Logical Volume Manager)

 Create New PV (Physical Volume)

 Add/Remove PV on VG on the Fly

►Create LV on VG on the Fly

 Extend /home LV with a New Partition

 Installing CentOS

 SELinux - Security-Enhanced Linux

 Network Connection on CentOS

 Internet Networking Tools

 SSH Protocol and ssh/scp Commands

 Software Package Manager on CentOS - DNF and YUM

 vsftpd - Very Secure FTP Daemon

 LDAP (Lightweight Directory Access Protocol)

 Administrative Tasks

 References

 Full Version in PDF/EPUB