Tuesday, 10 March 2020

How to Create LVM Partition on CentOS 7 Using Additional Hard Disk



Logical Volume Management (LVM) is an abstraction layer between operating system and physical hard drives and can be easily managed the disk space.
This article describes How to Create LVM Partition on CentOS7 Using Additional Hard Disk.

Step 1. Check Hard Disk Details: Run the following command to get the hard disk details:

[root@linuxcnf ~]# fdisk -l
…………………….
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
…………………….
[root@linuxcnf ~]#

Step 2. Create a Physical Volume: Run the following command to create a physical volume using the above hard disk:

[root@linuxcnf ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.
[root@linuxcnf ~]#

Step 3. Create a Volume Group: Run the following command to create volume group using the above physical volumes:

[root@linuxcnf ~]# vgcreate vg-data /dev/sdb
  Volume group "vg-data" successfully created
[root@linuxcnf ~]#

Step 4. Create a Logical Volume: Run the following commands to create logical volume from the above created volume group:

[root@linuxcnf ~]# lvcreate -n nginx-data -l +100%FREE vg-data
  Logical volume "nginx-data" created.
[root@linuxcnf ~]#

Use -l +100%FREE option to use entire space of the volume group for a logical volume.

Step 5. Verify the Changes: Run the following command to verify the physical volume:

[root@linuxcnf ~]# pvs
  PV         VG      Fmt  Attr PSize   PFree
…………………….
  /dev/sdb   vg-data lvm2 a--  <10.00g    0
[root@linuxcnf ~]#

Run the following command to verify volume group:

[root@linuxcnf ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree
  ……………………
  vg-data   1   1   0 wz--n- <10.00g    0
[root@linuxcnf ~]#

Run the following command to verify the logical volume and it will show as below:

[root@linuxcnf ~]# lvs
  LV         VG      Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
…………………….
  nginx-data vg-data -wi-a----- <10.00g
[root@linuxcnf ~]#

Done!!! LVM and LVM partition is created successfully and ready to use. Follow the article Howto Create and Mount a LVM Partition/Volume on CentOS 7 to create and mount the LVM partition on CentOS 7.

No comments:

Post a comment