LVM installation and configuration in CentOS 7 and RHEL 7

In this tutorial we will see, LVM installation and configuration in CentOS 7 and RHEL 7. So first of all we should know what is LVM? and why we use LVM in Linux?

What is LVM?

Logical Volume Management (LVM), is a storage device management technology that gives users the power to pool and abstract the physical layout of component storage devices for easier and flexible administration. The main advantages of LVM are increased abstraction, flexibility, and control. Volumes can be resized dynamically as space requirements change and migrated between physical devices within the pool on a running system or exported easily. LVM also offers advanced features like snapshotting, striping, and mirroring.

Now we can follow these steps to create LVM in Linux CentOS 7 or RHEL 7

Add one new 4GB additional disk in our Virtual Machine.

In this tutorial I am going to add one 4GB additional virtual disk in our Virtual Machine, I will see you how to create LVM on this disk. You can see in below snapshot we have only one disk where operating system has been installed.

[[email protected] ~]# fdisk -l

Disk /dev/sda: 16.1 GB, 16106127360 bytes, 31457280 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: 0x00063127

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 31457279 15215616 8e Linux LVM

Disk /dev/mapper/centos-root: 13.9 GB, 13925089280 bytes, 27197440 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: 1610 MB, 1610612736 bytes, 3145728 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

[[email protected] ~]#

Now I am going to add one 4GB additional disk where I will create LVM. Currently I am using Oracle Virtual box where my Virtual Machine has been created if you are also using Oracle Virtual box for VM then you can follow this steps to attached one additional disk in your Virtual Machine. Or if you can attached disk in other server or other Virtual Machine then you can follow steps according to those server and VMs.

First of all we have to shut down our Virtual Machine and we have to go to VM setting àStorage à Controller:SATA then we have to click + for add hard disk. After that we can get one new windows where we have to select VDI virtual disk image then next, then we have to select dynamically allocated and next. After that we have to select disk size of our virtual disk then we have to click on create after that we have successfully created additional disk. We can check our disk has been created or not using fdisk –l command like below.

[[email protected] ~]# fdisk -l

Disk /dev/sda: 16.1 GB, 16106127360 bytes, 31457280 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: 0x00063127

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 31457279 15215616 8e Linux LVM

Disk /dev/sdb: 4307 MB, 4307599360 bytes, 8413280 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: 13.9 GB, 13925089280 bytes, 27197440 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: 1610 MB, 1610612736 bytes, 3145728 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

[[email protected] ~]#

You can see in above output we have successfully added one additional disk of 4GB in our Virtual Machine.

Create a partition using fdisk and select partition type LVM  on additional disk of 4GB disk.

[[email protected] ~]# 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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xb378c328.

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-8413279, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-8413279, default 8413279):
Using default value 8413279
Partition 1 of type Linux and of size 4 GiB is set

Command (m for help): p

Disk /dev/sdb: 4307 MB, 4307599360 bytes, 8413280 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: 0xb378c328

Device Boot Start End Blocks Id System
/dev/sdb1 2048 8413279 4205616 83 Linux

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
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 4307 MB, 4307599360 bytes, 8413280 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: 0xb378c328

Device Boot Start End Blocks Id System
/dev/sdb1 2048 8413279 4205616 8e Linux LVM

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

Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] ~]#

Now we need to create physical volume of new created partition /dev/sdb1 as an LVM physical volume

[[email protected] ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
[[email protected] ~]#

We can scan our block device using lvmdiskscan command like below.

[[email protected] ~]# lvmdiskscan
/dev/centos/root [ <12.97 GiB]
/dev/sda1 [ 500.00 MiB]
/dev/centos/swap [ 1.50 GiB]
/dev/sda2 [ 14.51 GiB] LVM physical volume
/dev/sdb1 [ 4.01 GiB] LVM physical volume
2 disks
1 partition
0 LVM physical volume whole disks
2 LVM physical volumes
[[email protected] ~]#

We can display our physical volume using pvdisplay command. Like below.

[[email protected] ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size 14.51 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 3714
Free PE 10
Allocated PE 3704
PV UUID 5xJdNh-wNQI-68UB-Mgty-kAau-0xjs-PZvplY

"/dev/sdb1" is a new physical volume of "4.01 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 4.01 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 7mG1mN-C0zc-qQrs-fIXm-ucnU-uuoE-tQi1Ov

[[email protected] ~]#

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

We can use pvscan command to scans all supported LVM block devices in our system for physical volumes. Like below.

[[email protected] ~]# pvscan
PV /dev/sda2 VG centos lvm2 [<14.51 GiB / 40.00 MiB free]
PV /dev/sdb1 lvm2 [4.01 GiB]
Total: 2 [<18.52 GiB] / in use: 1 [<14.51 GiB] / in no VG: 1 [4.01 GiB]
[[email protected] ~]#

Now we need to create volume group name vg_backuplvm and add /dev/sdb1 partition into the group.

[[email protected] ~]# vgcreate vg_backuplvm /dev/sdb1
Volume group "vg_backuplvm" successfully created
[[email protected] ~]#

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

[[email protected] ~]# vgcreate vg_backuplvm /dev/sdb1 /dev/sdc1

Now we need to creates a logical volume called vm_backupvol that uses all of the unallocated space of the volume group vg_backuplvm volume.

[[email protected] ~]# lvcreate --name vm_backupvol -l 100%FREE vg_backuplvm
Logical volume "vm_backupvol" created.
[[email protected] ~]#

Now can display the created logical volumes using lvdisplay command. Like below.

[[email protected] ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg_backuplvm/vm_backupvol
LV Name vm_backupvol
VG Name vg_backuplvm
LV UUID QstkX6-SL0T-eLs1-Lkt9-WvoV-5vzb-gM4LXb
LV Write Access read/write
LV Creation host, time urclouds, 2018-08-29 18:30:21 +0200
LV Status available
# open 0
LV Size <4.01 GiB
Current LE 1026
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2

--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID Zo8pWg-YlLo-cU7w-6m7F-AYWl-gOE9-s60kEj
LV Write Access read/write
LV Creation host, time localhost, 2017-09-26 12:44:34 +0200
LV Status available
# open 2
LV Size 1.50 GiB
Current LE 384
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1

--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID ae6QrZ-fPaf-LDPr-ybgr-laz0-3jRL-TjrLGE
LV Write Access read/write
LV Creation host, time localhost, 2017-09-26 12:44:34 +0200
LV Status available
# open 1
LV Size <12.97 GiB
Current LE 3320
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

[[email protected] ~]#

We can use mkfs command to format a newly created LVM volume using below command.

[[email protected] ~]# mkfs.ext4 /dev/vg_backuplvm/vm_backupvol
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
262944 inodes, 1050624 blocks
52531 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1075838976
33 block groups
32768 blocks per group, 32768 fragments per group
7968 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736

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

[[email protected] ~]#

Now we need to create the mount point and mount our new LVM volume

[[email protected] ~]# mkdir -p /backup2
[[email protected] ~]# mount /dev/vg_backuplvm/vm_backupvol /backup2
[[email protected] ~]#

We can verify our mount point using df –h command like below.

[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 13G 6.4G 6.7G 49% /
devtmpfs 904M 0 904M 0% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 8.9M 911M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/sda1 497M 214M 283M 44% /boot
tmpfs 184M 24K 184M 1% /run/user/1001
tmpfs 184M 24K 184M 1% /run/user/1000
tmpfs 184M 0 184M 0% /run/user/0
/dev/mapper/vg_backuplvm-vm_backupvol 3.9G 17M 3.6G 1% /backup2
[[email protected] ~]#

You can see in above we have successfully mounted our lvm volume in /backup2 mount point.

So in this tutorial we have seen how to install and configure LVM volume and How to mount LVM volume in our operating system.

2 thoughts on “LVM installation and configuration in CentOS 7 and RHEL 7

  1. It is not my first time to pay a visit this website, i am visiting this web site dailly
    and take fastidious information from here daily.

Leave a Reply

Your email address will not be published. Required fields are marked *