top of page
Writer's pictureMohammed Niyas

Logical Volumes on three disk - configuration example

Logical volume provides a greater flexibility in a number of ways than physical disk in terms of flexible capacity and re-sizeable storage pools etc.


As you can see, the physical combines and form the Volume Group, and Logical volumes are created from the volume group. The Logical volumes are then formatted and partitioned as devices from the operating system for application and databases.


Let's get started,

Example:

  1. Create three physical volumes for three physical disk

  2. Create a Volume Group

  3. Create a Logical Volume

  4. Create a File System on this LV and mount it.


lvmdiskscan scans all SCSI, (E)IDE disks, multiple devices and a

bunch of other block devices in the system looking for LVM PVs.

  1. Run lvmdiskscan to see the list of current volumes

[root@localhost ~]# lvmdiskscan
  /dev/nvme0n1p1 [       1.00 GiB] 
  /dev/nvme0n1p2 [     <39.00 GiB] LVM physical volume
  /dev/nvme0n2p1 [    1023.00 MiB] 
  /dev/nvme0n3p1 [      <5.00 GiB] 
  /dev/nvme0n4   [       3.00 GiB] 
  /dev/nvme0n5   [       3.00 GiB] 
  /dev/nvme0n6   [       3.00 GiB] 
  0 disks
  6 partitions
  0 LVM physical volume whole disks
  1 LVM physical volume

2. The new disks are added but not labelled as "LVM physical volume". So run pvcreate to label them.


[root@localhost ~]# pvcreate /dev/nvme0n4 /dev/nvme0n5 /dev/nvme0n6
  Physical volume "/dev/nvme0n4" successfully created.
  Physical volume "/dev/nvme0n5" successfully created.
  Physical volume "/dev/nvme0n6" successfully created.
[root@localhost ~]# vgcreate new_group /dev/nvme0n4 /dev/nvme0n5 /dev/nvme0n6
  Volume group "new_group" successfully created

3. Create a volume group

[root@localhost ~]# vgcreate new_group /dev/nvme0n4 /dev/nvme0n5 /dev/nvme0n6
  Volume group "new_group" successfully created

4. Run vgs to see the new volume groups

[root@localhost ~]# vgs
  VG        #PV #LV #SN Attr   VSize   VFree 
  new_group   3   0   0 wz--n-  <8.99g <8.99g
  rhel        1   2   0 wz--n- <39.00g     0 

4. Create a logical volume with 2 GigaByte.

[root@localhost ~]# lvcreate -L 2G -n new_lvm new_group
  Logical volume "new_lvm" created.

5. Run lvmscan to see new logical volume

[root@localhost ~]# lvscan
  ACTIVE            '/dev/new_group/new_lvm' [2.00 GiB] inherit
  ACTIVE            '/dev/rhel/swap' [<3.94 GiB] inherit
  ACTIVE            '/dev/rhel/root' [<35.06 GiB] inherit

6. For detailed view of logical volume

[root@localhost ~]# lvdisplay /dev/new_group/new_lvm 
  --- Logical volume ---
  LV Path                /dev/new_group/new_lvm
  LV Name                new_lvm
  VG Name                new_group
  LV UUID                IdF48L-McZI-inff-3RW0-mNak-ADYO-tVcMxq
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2021-06-12 03:57:35 -0400
  LV Status              available
  # open                 0
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

7. Now format the new logical volume to preferred file system

[root@localhost ~]# mkfs.ext4 /dev/new_group/new_lvm 
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: dcc291cc-924a-4bcb-b81a-de37063eb729
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912

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

8. Assign label to the new logical volume, use blkid if you want to verify

[root@localhost ~]# tune2fs -L lvlabel /dev/new_group/new_lvm 
tune2fs 1.45.6 (20-Mar-2020)

9. Now add the entry to fstab

[root@localhost ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Fri Jun 11 06:41:30 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rhel-root   /                       xfs     defaults        0 0
UUID=5dc60cd5-8e84-4132-8d4d-89957c00ba4e /boot                   xfs     defaults        0 0

/dev/mapper/rhel-swap   none                    swap    defaults        0 0

LABEL=mylabel /mymount1 ext4 defaults 0 0

LABEL=lvlabel /lvdrive ext4 defaults 0 0 

10. Create the folder and mount it.

[root@localhost ~]# mkdir /lvdrive
[root@localhost ~]# mount -a

11. Run df to verify above action

[root@localhost lvdrive]# df
Filesystem                    1K-blocks    Used Available Use% Mounted on
devtmpfs                        1869140       0   1869140   0% /dev
tmpfs                           1899504       0   1899504   0% /dev/shm
tmpfs                           1899504    9992   1889512   1% /run
tmpfs                           1899504       0   1899504   0% /sys/fs/cgroup
/dev/mapper/rhel-root          36743652 5015516  31728136  14% /
/dev/nvme0n3p1                  5095004   20472   4796008   1% /mymount1
/dev/nvme0n1p1                  1038336  248444    789892  24% /boot
tmpfs                            379900    4636    375264   2% /run/user/1000
/dev/mapper/new_group-new_lvm   1998672    6144   1871288   1% /lvdrive

139 views0 comments

Recent Posts

See All

Comentários


bottom of page