Cloude Devops Logo Free Clss Will start on Devops from July 15th
Cloud DevOps
Cloud DevOps




Wecome To Linux



LVM stands for Logical Volume Manager. LVM is a tool for logical volume management. LVM can be used to create easy to maintain logical volumes, manage disk quotas using logical volumes, resize logical volumes on the fly, create software RAIDs, combining hard drives into a big storage pool and many more.In this article, I will show you how to install and configure LVM on CentOS 7. Let’s get started.

How LVM Works:

LVM has basically three terms, Physical Volume PV, Volume Group VG, Logical Volume LV.

  • PV – It’s a raw hard drive that it initialized to work with LVM, such as /dev/sdb, /dev/sdc, /dev/sdb1 etc.
  • VG – Many PV is combined into one VG. You can create many VGs and each of them has a unique name.
  • LV – You can create many LVs from a VG. You can extend, reduce the LV size on the fly. The LV also has unique names. You format the LV into ext4, zfs, btrfs etc filesystems, mount it and use it as you do other ordinary partitions.

Installing LVM:

LVM may not be installed on your CentOS 7 machine. But it is available in the official package repository of CentOS 7.

First update the YUM package repository cache with the following command:

[root@clouddevops opt]#yum makecache

Run the following command to install LVM on CentOS 7:

[root@clouddevops opt]#yum install lvm2

Now press y and then press <Enter> to continue.

LVM should be installed.

Initializing Disk for LVM:

Docker Tutorial

[root@clouddevops opt]# fdisk -l


Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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
Disk label type: dos
Disk identifier: 0x0003d1b7

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    83886079    40893440   8e  Linux LVM

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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


Disk /dev/mapper/centos-root: 37.7 GB, 37706792960 bytes, 73646080 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


Disk /dev/mapper/centos-swap: 4160 MB, 4160749568 bytes, 8126464 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@clouddevops ~]#

[root@clouddevops opt]# df -h

Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 894M     0  894M   0% /dev
tmpfs                    910M     0  910M   0% /dev/shm
tmpfs                    910M   11M  900M   2% /run
tmpfs                    910M     0  910M   0% /sys/fs/cgroup
/dev/mapper/centos-root   36G  7.9G   28G  23% /
/dev/sda1               1014M  346M  669M  35% /boot
tmpfs                    182M   28K  182M   1% /run/user/0
/dev/sr0                 4.5G  4.5G     0 100% /run/media/root/CentOS 7 x86_64

[root@clouddevops ~]#

You can use the raw disk such as /dev/sdb or /dev/sdc as LVM PV. LVM has no problem with that but it is not recommended as other operating systems won’t be able to detect LVM metadata and you may not be able to tell whether the disk is set up to use LVM if you have many disks lying around.

So I recommend you create a single partition on your hard drive with all the available space and change the partition type to Linux LVM or 8E.

Use fdisk to create a single partition on the disk, let’s say /dev/sdb:

Docker Tutorial

[root@clouddevops opt]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): m 
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Now type in n and press <Enter> to create a new partition. Now keep pressing <Enter> to accept the defaults.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): +25G
Partition 1 of type Linux and of size 25 GiB is set

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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
Disk label type: dos
Disk identifier: 0x30a7e19f

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

[root@clouddevops ~]#

Docker Tutorial

[root@clouddevops opt]# fdisk -l


Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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
Disk label type: dos
Disk identifier: 0x0003d1b7

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    83886079    40893440   8e  Linux LVM

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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
Disk label type: dos
Disk identifier: 0x30a7e19f

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   83  Linux

Disk /dev/mapper/centos-root: 37.7 GB, 37706792960 bytes, 73646080 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


Disk /dev/mapper/centos-swap: 4160 MB, 4160749568 bytes, 8126464 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@clouddevops ~]#

Docker Tutorial

The partition should be created.

[root@clouddevops opt]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help):m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
  u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
Docker Tutorial

Now type in t and press <Enter>.

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes):l

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT
1e  Hidden W95 FAT1 80  Old Minix
Hex code (type L to list all codes):8e

Now type in 8e as the Hex code and press <Enter>. The partition type should be set to Linux LVM.

Docker Tutorial

Now type in t and press <Enter>. Then type in 8e as the Hex code and press <Enter>. The partition type should be set to Linux LVM.

Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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
Disk label type: dos
Disk identifier: 0x30a7e19f

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   8e  Linux LVM

Now type in w and press <Enter> to save the changes.

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

The partition /dev/sdb1 is now ready to be used with LVM.

Create one more Partition sdb2 with sdb raw disk fallow the steps same as like above or fallowing bellow steps.

[root@clouddevops opt]# fdisk -l


Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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
Disk label type: dos
Disk identifier: 0x0003d1b7

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    83886079    40893440   8e  Linux LVM

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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
Disk label type: dos
Disk identifier: 0x30a7e19f

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   8e  Linux LVM 

Disk /dev/mapper/centos-root: 37.7 GB, 37706792960 bytes, 73646080 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


Disk /dev/mapper/centos-swap: 4160 MB, 4160749568 bytes, 8126464 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@clouddevops ~]#

Create a 2nd one sdb2 partition like fallowing bellow steps

[root@clouddevops opt]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p):  p
Partition number (2-4, default 2):
First sector (52430848-209715199, default 52430848):
Using default value 52430848
Last sector, +sectors or +size{K,M,G} (52430848-209715199, default 209715199): +25G
Partition 2 of type Linux and of size 25 GiB is set

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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
Disk label type: dos
Disk identifier: 0x30a7e19f

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   8e  Linux LVM
/dev/sdb2        52430848   104859647    26214400   83  Linux

Command (m for help):

Change the id from 83 to 8e

See the Bellow steps to convert from 83 to 8e

Docker Tutorial

[root@clouddevops opt]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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
Disk label type: dos
Disk identifier: 0x30a7e19f

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   8e  Linux LVM
/dev/sdb2        52430848   104859647    26214400   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

[root@clouddevops ~]#

Docker Tutorial

List the All Physical Volumes (PV)

[root@clouddevops opt]# pvs

  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda2  centos lvm2 a--  <39.00g 4.00m

OR

[root@clouddevops opt]# pvdisplay

  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <39.00 GiB / not usable 3.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              9983
  Free PE               1
  Allocated PE          9982
  PV UUID               S1ncTT-Mlnf-XSfH-J0yi-E6dd-CKri-0GAy4U

[root@clouddevops ~]#

Docker Tutorial

Adding the Disk to LVM PV:

Now run the following command to add the disk /dev/sdb1 to the LVM as PV:

[root@clouddevops opt]# pvcreate /dev/sdb1

  Physical volume "/dev/sdb1" successfully created.

[root@clouddevops ~]#

Docker Tutorial

You can list all the PV with the following command:

[root@clouddevops opt]# pvs

  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda2  centos lvm2 a--  <39.00g  4.00m
  /dev/sdb1         lvm2 ---   25.00g 25.00g

Docker Tutorial

OR

[root@clouddevops opt]# pvdisplay

  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <39.00 GiB / not usable 3.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              9983
  Free PE               1
  Allocated PE          9982
  PV UUID               S1ncTT-Mlnf-XSfH-J0yi-E6dd-CKri-0GAy4U

  "/dev/sdb1" is a new physical volume of "25.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               25.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               rgVeKF-foP0-ri65-rxob-LlZG-B3bq-0Rfcsj

[root@clouddevops ~]#

Docker Tutorial

OR

If you want to display more information about any specific PV, let’s say /dev/sdb1, then run the following command:

[root@clouddevops opt]# pvdisplay /dev/sdb1

  "/dev/sdb1" is a new physical volume of "25.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               25.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               rgVeKF-foP0-ri65-rxob-LlZG-B3bq-0Rfcsj

[root@clouddevops ~]#

Docker Tutorial
$ sudo pvscan

[root@clouddevops opt]# pvscan

  PV /dev/sda2   VG centos          lvm2 [<39.00 GiB / 4.00 MiB free]
  PV /dev/sdb1                      lvm2 [25.00 GiB]
  Total: 2 [<64.00 GiB] / in use: 1 [<39.00 GiB] / in no VG: 1 [25.00 GiB]

[root@clouddevops ~]#

Docker Tutorial

Creating Volume Groups:

Now you can create a VG out of as many PV as you have available. Right now I have only one PV /dev/sdb1 available.

[root@clouddevops opt]# vgs

  VG     #PV #LV #SN Attr   VSize   VFree
  centos   1   2   0 wz--n- <39.00g 4.00m
  
Docker Tutorial

Compelte Information about VOLUME GROUP (VG)

[root@clouddevops ~]# vgdisplay

  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <39.00 GiB
  PE Size               4.00 MiB
  Total PE              9983
  Alloc PE / Size       9982 / 38.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               S7d6eF-L8Xv-XDyc-eKDb-Qvo0-JHr2-JGhk1l

[root@clouddevops ~]#

Docker Tutorial

Run the following command to create VG clouddevops with PV /dev/sdb1:

[root@clouddevops opt]# vgcreate clouddevops /dev/sdb1

  Volume group "clouddevops" successfully created

[root@clouddevops ~]#

Docker Tutorial

Now you can list all the VGs with the following command:

[root@clouddevops opt]# vgscan

  Reading volume groups from cache.
  Found volume group "centos" using metadata type lvm2
  Found volume group "clouddevops" using metadata type lvm2

[root@clouddevops ~]#

Docker Tutorial

You can display more information about any specific VG, such as clouddevops with the following command:

[root@clouddevops opt]# vgdisplay clouddevops

  --- Volume group ---
  VG Name               clouddevops
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <25.00 GiB
  PE Size               4.00 MiB
  Total PE              6399
  Alloc PE / Size       0 / 0
  Free  PE / Size       6399 / <25.00 GiB
  VG UUID               Cffkp2-iStu-fcsp-gWYf-FTfi-cN60-jmWOjA

[root@clouddevops ~]#

Docker Tutorial

Extending Volume Groups:

If you wish you can add more PV to an existing VG clouddevops with the following command:

[root@clouddevops opt]# vgextend clouddevops /dev/sdb2

  Physical volume "/dev/sdb2" successfully created.
  Volume group "clouddevops" successfully extended

[root@clouddevops ~]#

Docker Tutorial

Creating Logical Volumes:

Now you can create as many LVs as you want using a VG, in my case VG clouddevops.

we can create from 1MB aslo but here i am using25GB LV clouddevops from VG clouddevops with the following command:

[root@clouddevops opt]# lvcreate --size 20G --name devopslvm clouddevops

  Logical volume "devopslvm" created.

[root@clouddevops ~]# lvs

  LV        VG          Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root      centos      -wi-ao---- <35.12g
  swap      centos      -wi-ao----  <3.88g
  devopslvm clouddevops -wi-a-----  20.00g

[root@clouddevops ~]#

Docker Tutorial

Let’s create another LV lvmtwo of size 10GB from VG clouddevops with the following command:

[root@clouddevops opt]# lvcreate --size 10G --name lvm_two clouddevops

  Logical volume "lvm_two" created.
  

[root@clouddevops opt]# lvs

  LV        VG          Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root      centos      -wi-ao---- <35.12g
  swap      centos      -wi-ao----  <3.88g
  devopslvm clouddevops -wi-a-----  20.00g
  lvm_two   clouddevops -wi-a-----  10.00g

[root@clouddevops ~]#

Docker Tutorial

Now you can list all the LVs with the following commands:

[root@clouddevops opt]# lvscan

  ACTIVE            '/dev/centos/swap' [<3.88 GiB] inherit
  ACTIVE            '/dev/centos/root' [<35.12 GiB] inherit
  ACTIVE            '/dev/clouddevops/devopslvm' [20.00 GiB] inherit
  ACTIVE            '/dev/clouddevops/lvm_two' [10.00 GiB] inherit

[root@clouddevops ~]#

Docker Tutorial

Or

[root@clouddevops opt]# lvs

  LV        VG          Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root      centos      -wi-ao---- <35.12g
  swap      centos      -wi-ao----  <3.88g
  devopslvm clouddevops -wi-a-----  20.00g
  lvm_two   clouddevops -wi-a-----  10.00g

[root@clouddevops ~]#

Docker Tutorial

You can also display more information about any specific LV with the following command:

$ sudo lvdisplay VG_NAME/LV_NAME

In my case, VG_NAME is clouddevops and LV_NAME is clouddevops

[root@clouddevops opt]# lvdisplay /dev/clouddevops/clouddevops

  --- Logical volume ---
  LV Path                /dev/clouddevops/clouddevops
  LV Name                clouddevops
  VG Name                clouddevops
  LV UUID                fgru9C-ICZi-BfmR-mvJg-0Fjb-FxUW-2D0MYy
  LV Write Access        read/write
  LV Creation host, time clouddevops.com, 2020-08-15 23:00:56 +0530
  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:4

[root@clouddevops ~]#

Docker Tutorial

Formatting and Mounting Logical Volumes:

You can access your LVs just as you do with ordinary hard drive partitions such as /dev/sdb1, /dev/sdc2 etc.

The LVs are available as /dev/VG_NAME/LV_NAME

For example, if my VG_NAME is clouddevops, and LV_NAME is clouddevops, then the LV is available as /dev/clouddevops/clouddevops

You can use /dev/clouddevops/clouddevops just as you use an ordinary hard drive partition /dev/sdb1.

Once you’ve created a LV, you need to format it.

Run the following command to format /dev/clouddevops/clouddevops LV to EXT4 filesystem:

[root@clouddevops opt]# mkfs.ext4 /dev/clouddevops/clouddevops

mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2151677952
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

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

[root@clouddevops ~]#

Docker Tutorial

Now run the following command to create a mount point where you want to mount /dev/clouddevops/clouddevops LV:

[root@clouddevops opt]# mkdir /opt/clouddevops


[root@clouddevops opt]# ll /opt/

total 0
drwxr-xr-x. 2 root root  6 Aug 15 23:16 clouddevops
drwx--x--x. 4 root root 28 Aug  9 08:45 containerd
drwxr-xr-x. 2 root root  6 Oct 31  2018 rh

[root@clouddevops ~]#

Docker Tutorial

Now you can mount /dev/clouddevops/clouddevops to any empty directory such as /var/www/wordpress with the following command:

[root@clouddevops opt]# mount /dev/clouddevops/clouddevops /opt/clouddevops/

[root@clouddevops ~]#

Docker Tutorial

As you can see, the LV is mounted to the desired mount point:

Docker Tutorial

[root@clouddevops opt]# df -h

Filesystem                           Size  Used Avail Use% Mounted on
devtmpfs                             1.9G     0  1.9G   0% /dev
tmpfs                                1.9G     0  1.9G   0% /dev/shm
tmpfs                                1.9G   13M  1.9G   1% /run
tmpfs                                1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root               36G  7.9G   28G  23% /
/dev/sda1                           1014M  346M  669M  35% /boot
tmpfs                                378M   24K  378M   1% /run/user/0
/dev/sr0                             4.5G  4.5G     0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/clouddevops-clouddevops  9.8G   37M  9.2G   1% /opt/clouddevops

[root@clouddevops ~]#

Docker Tutorial

Now you can use copy and paste files, create new files and directories in the /var/www/wordpress directory.

Extending Logical Volumes:

LVM is a good tool for quota management. You give away the space you need, no more, no less on each LVs. But if you do require more space, you can always resize the LV on the fly.

Even if you’re not doing quota management, when you’re out of disk space, you can just add new hard drives, add it to the PV, extend the VG with your new PV, extend the LV and you’re good to go.

For example, to add 5GB more to our LV clouddevops created from VG clouddevops, run the following command:

Note: You can use G keyword for GB. For example, --size +5G

[root@clouddevops opt]# lvextend --size +5G --resizefs clouddevops/clouddevops

  Size of logical volume clouddevops/clouddevops changed from 10.00 GiB (2560 extents) to 15.00 GiB (3840 extents).
  Logical volume clouddevops/clouddevops successfully resized.
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/clouddevops-clouddevops is mounted on /opt/clouddevops; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 2
The filesystem on /dev/mapper/clouddevops-clouddevops is now 3932160 blocks long.

[root@clouddevops ~]#

Docker Tutorial

The clouddevops LV should be resized as you can see from the screenshot below.

[root@clouddevops opt]# df -h

Filesystem                           Size  Used Avail Use% Mounted on
devtmpfs                             1.9G     0  1.9G   0% /dev
tmpfs                                1.9G     0  1.9G   0% /dev/shm
tmpfs                                1.9G   13M  1.9G   1% /run
tmpfs                                1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root               36G  7.9G   28G  23% /
/dev/sda1                           1014M  346M  669M  35% /boot
tmpfs                                378M   24K  378M   1% /run/user/0
/dev/sr0                             4.5G  4.5G     0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/clouddevops-clouddevops   15G   41M   14G   1% /opt/clouddevops

[root@clouddevops ~]#

Docker Tutorial

That’s how you install and configure LVM on CentOS 7. Thanks for reading this article.












The DevOps seminar will help you to learn DevOps from scracth to deep knowledge of various DevOps tools such as fallowing List.

Linux, Git, Jenkins, Maven, Apache Tomcat, Nexus, Ansible, Chef, Docker, Nagios,   Kubernetes.


                                                                                                                                    

Learn Latest Technologies