Rabu, 01 Februari 2023

How to Create Lvm in Linux Step by Step

How to Create Lvm in Linux Step by Step

Step 1: Add Harddrive to System


Check with dmesg

[admin@ora87 ~]$ sudo dmesg



Step 2: Create a new Partiton using cfdisk tool :

[admin@ora87 ~]$ sudo cfdisk /dev/sda








Step 3: Initializes the partition /dev/sda1 as an LVM physical volume :

[root@ora87 ~]# pvcreate /dev/sda1



Step 4: Scanning for Block Devices

[root@ora87 ~]# lvmdiskscan



Step 5: Displaying Physical Volumes :

There are three commands you can use to display properties of LVM physical volumes: pvs, pvdisplay, and pvscan.

The pvdisplay command provides a verbose multi-line output for each physical volume. It displays physical properties
(size, extents, volume group, etc.) in a fixed format.

[root@ora87 ~]# pvdisplay

The pvscan command scans all supported LVM block devices in the system for physical volumes

[root@ora87 ~]# pvscan



Step 6: Create volume group name oradata and add /dev/sda1 partition into the group.

[root@ora87 ~]# vgcreate vg_oradata /dev/sda1


If you have more than one partition, you can add multiple partition in single command. This command creates a local volume
named vg_newlvm that contains physical volumes /dev/sda1 and /dev/sdb1 :

[root@ora87 ~]# vgcreate vg_oradata /dev/sda1  /dev/sdb1


Step 7: Creates a logical volume called oradata_vol that uses all of the unallocated space in the volume group vg_oradata :

[root@ora87 ~]# lvcreate --name oradata_vol -l 100%FREE vg_oradata



Step 8: Display the created logical volumes :

[root@ora87 ~]# lvdisplay



Step 9: Use the mkfs command to format a newly created LVM :

[root@ora87 ~]# mkfs.ext4 /dev/vg_oradata/oradata_vol



Step 10: Create the mount point and mount the new LVM :

[root@ora87 ~]# mkdir -p /oradata

[root@ora87 ~]# mount /dev/vg_oradata/oradata_vol /oradata


Step 11: Verify thew new disk layout :

[root@ora87 ~]# df -h