How to Create and Manage LVM on Oracle Linux 8.5

To Create and manage LVM on Oracle Linux 8.5

Introduction:

A logical volume manager (LVM) is a type of storage virtualization that combines multiple hard drives or partitions into a single volume group (VG), which then can be subdivided into logical volumes (LV), or can be used as a single large volume.

Installation Steps:

Step 1: Check the Oracle Linux Version by using the below command.

[root@linuxhelp linuxhelp]# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="8.5"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"

Step 2: Check current Disk status by using the below command.

[root@linuxhelp linuxhelp]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   10G  0 disk 
sr0          11:0    1 1024M  0 rom  
nvme0n1     259:0    0   20G  0 disk 
├─nvme0n1p1 259:1    0    1G  0 part /boot
└─nvme0n1p2 259:2    0   19G  0 part 
  ├─ol-root 252:0    0   17G  0 lvm  /
  └─ol-swap 252:1    0    2G  0 lvm  [SWAP]

Step 3: Create new Partition by using the below command.

[root@linuxhelp linuxhelp]# fdisk /dev/sda

Welcome to fdisk (util-linux 2.23.2).
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G
Partition 1 of type Linux and of size 5GiB is set
Command (m for help): wq

Selected partition 1
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Step 4: Create a physical volume by using the below command.

[root@linuxhelp linuxhelp]# pvcreate /dev/sda1
Physical volume "/dev/sda1" successfully created.

Step 5: Create a volume group by using the below command.

[root@linuxhelp linuxhelp]# vgcreate vg /dev/sda1
 Volume group "vg" successfully created

Step 6: Create a logical volume by using the below command.

[root@linuxhelp linuxhelp]# lvcreate -n lv -L 2G vg
 Logical volume "lv" created.

Step 7: Create a Directory by using the below command.

[root@linuxhelp linuxhelp]# mkdir /home/linuxhelp/part

Step 8: Create File System by using the below command.

[root@linuxhelp linuxhelp]# mkfs.ext4 /dev/vg/lv
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: ad44c4a1-6c8b-4335-96fe-56e68916c4b4
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 

Step 9: Make insert the file path to mount by using the below command.

[root@linuxhelp linuxhelp]# vi /etc/fstab
/dev/vg/lv             /home/linuxhelp/part        vfat    defaults        0 0

Step 10: Update mount by using the below command.

[root@linuxhelp linuxhelp]# mount /dev/vg/lv

Step 11: Once all the modification is done in the partition, you can restart it by make use of the below command.

[root@linuxhelp linuxhelp]# partprobe

Step 12: Check the Mount point by using the below command.

[root@linuxhelp linuxhelp]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   10G  0 disk 
└─sda1        8:1    0    5G  0 part 
  └─vg-lv   252:2    0    2G  0 lvm  /home/linuxhelp/part

Step 13: Remove the entry in vi/etc/fstab and If you want to remove Logical volume, run the below command.

[root@linuxhelp11 /]# lvremove  /dev/vg/lv

Step 14: You can remove volume group by making use of the below command.

[root@linuxhelp11 /]# vgremove /dev/vg

Step 15: Remove Physical volume by making use of the below command.

[root@linuxhelp11 /]# pvremove /dev/sda1

With this the creating and managing lvm on oracle linux 8.5 has come to an end.

FAQ
Q
How to scan a logical volume from the existing volume group?
A
Using lvscan we can scan a logical volume from the existing volume group.
Q
Is it possible to increase the logical volume?
A
yes, we can increase the logical volume without umount it.
Q
How to list the available logical volumes on the system?
A
Use lvs command to list the available logical volumes on the system.
Q
How to list the imported volume groups?
A
Use vgs command to display the imported volume group.
Q
How to list the available physical volumes in LVM?
A
Use pvs command to list the available physical volumes.