Connect with us

Hi, what are you looking for?

Linux

Linux LVM Logical Volume for CentOS 7

What is LOGICAL VOLUME MANAGEMENT?

  • In LVM we can merge many hard drives & make it as a single hard drive. In previous we cannot resize the file system. Also we have some partition limit in rhel 7.
    If you make a hard drive of 10G using simple partition technique and somehow your drive get full so here we cannot expand it or reduce it. So we use LVM to get those advantages of reducing and expanding drives.
    lvm2
    Here we create 8 physical volume and using it we generate 1 Volume Group 1 TB. And we use 700G to create three logical volume and there is 300G remains in VG. The first LV get full so we use remaining 300G to extend that LV so such a way we can create LV and use it.
    LVM
    Here,
    PV-> Physical volume
    VG-> Volume Group
    LV -> Logical Volume

Configure LVM (Logical Volume Management) Disc Management on CentOS/RHEL/Scentific Linux/Oracle Linux 7/6/5

Step-I (Make new partition)
[root@techbrown]# fdisk  /dev/sda

n:
e extended
p primary partition (1-4)
Make extended partition and then create partition using it.
First cylinder:
second cylinder :+5G
Create 3 more partition like this.

Then toggle it. To toggle type t
t: (x) (y) (z)  (8e)
:p:
:w
[root@techbrown]# partx   -a   /dev/sda
[root@techbrown]# pvcreate   /dev/sdax

OR

[root@techbrown]# pvcreate  /dev/sdax   /dev/sday   /dev/sdaz
Now create physical volume to create it
[root@techbrown]# pvdisplay

Or

[root@techbrown]# pvs  /dev/sdax

Now create VG.

Step-II (Vgcreate vgname pvname(list))
[root@techbrown]# vgcreate   myvol   /dev/sdax  /dev/sday  /dev/sdaz
[root@techbrown]# vgdisplay

OR

[root@techbrown]# vgs myvol

Lvm3

Step-III (Now create Logical Volume)

lvcreate -L lvsize -n Lvname vgname

Advertisement. Scroll to continue reading.
[root@techbrown]# lvcreate  -L  2G  -n  lv1  myvol
[root@techbrown]# lvdisplay

Now Assign file system.

[root@techbrown]# mkfs.ext4  /dev/myvol/lv1
[root@techbrown]# mkdir /data
[root@techbrown]# vim /etc/fstab
/dev/myvol/lv1    /data    ext4   defaults   0    0
:wq
[root@techbrown]# mount    –a
[root@techbrown]# df   -hT
Step-IV (Remove LVM partition)
[root@techbrown]# umount   /data
[root@techbrown]# vim /etc/fstab
Remove entry
[root@techbrown]# lvremove   /dev/myvol/lv1
Step-V (For to remove VG)

First remove all active LVM then remove VG.

[root@techbrown]# vgremove   myvol
[root@techbrown]# pvremove  /dev/sdax   /dev/sday   /dev/sdaz
[root@techbrown]# fdisk  /dev/sda

Delete all Partition.

Step-VI (Create swap LVM)
[root@techbrown]# lvcreate   -L  +2G  -n   lv2   myvol
[root@techbrown]# mkswap  /dev/myvol/lv2
[root@techbrown]# vim   /etc/fstab
/dev/myvol/lv2     swap    swap    default    0    0
:wq
[root@techbrown]#swapon    -a
[root@techbrown]# cat /proc/swaps
Step-VII (To remove swap)
[root@techbrown]# swapof  -a
Step-VIII (Extend LV)
[root@techbrown]# vgs   myvol

Spaces are remaining then extend LV.

[root@techbrown]# lvextend   -L   +5G   /dev/myvol/lv1
[root@techbrown]#resize2fs   /dev/myvol/lv1
Step-IX (Reduce LV)
-Cannot reduce LVM partition on online mode
 -Only free space can reduce
[root@techbrown]# umount   /data
[root@techbrown]# df  -hT
[root@techbrown]# fsck.ext4   -f   /dev/myvol/lv1
Step-X (resize2fs LVname targated size)
[root@techbrown]# resize2fs   /dev/myvol/lv1   7G

lvreduce -L size (targeted size) LVname

Advertisement. Scroll to continue reading.
[root@techbrown]# lvreduce -L 7G  /dev/myvol/lv1
[root@techbrown]# mount   -a
[root@techbrown]#  df   -hT
Step-XI (Using Physical extent and logical extent)
[root@techbrown]# vgcreate  -s  8G  myvol   /dev/sdax
[root@techbrown]#  lvcreate   -l   20   -n   lv3  myvol.

LVM4
Congratulations LVM is now Configured.

Comments
Advertisement
Advertisement

Linux

DNF stands Dandified YUM and this is the default package manager for RHEL 8 / CentOS 8.  This tutorial explains you how to create...

Linux

If you forget a root password of your RHEL 8 and CentOS 8 and want to reset the password so that the RHEL 8...

Windows

How to auto upgrade JioFi firmware for JioFi 2 / JioFi 3 / JioFi 4 / JioFi 5 / JioFi 6 and other JioFi...

Linux

How to Upgrade WordPress Server from Ubuntu 16.04 to Ubuntu 18.04. Right now, Ubuntu 18.04 has been released with tons of new features. Upgrading...

Linux

How to Enable TLS 1.3 on Nginx Web Server. Nginx is a ultra fast web server optimized for modern web applications and servers. TLS...

Advertisement

You May Also Like

Windows

How to auto upgrade JioFi firmware for JioFi 2 / JioFi 3 / JioFi 4 / JioFi 5 / JioFi 6 and other JioFi...

Linux

DNF stands Dandified YUM and this is the default package manager for RHEL 8 / CentOS 8.  This tutorial explains you how to create...

Windows

How to download and install the Mobile Intel 4 Series Express Chipset Graphics Drivers for Windows 10.  Windows 10 is the one of the...

Windows

How to Install and Configure PCSX2 on Windows 10. The Windows 10 is the most recommended operating system for the Games. In stream platform...