Configure LVM (Logical Volume Management) Disc Management on CentOS/RHEL 7.x

Configure LVM (Logical Volume Management) Disc Management on CentOS/RHEL 7.x

Make new partition :

#fdisk /dev/sda
Command (m for help) : n
Command action
              e extended
              p primary partion 
p
Partition number (1-4) : 1
First cylinder :
second cylinder : +5G
Command (m for help) : t
select partition : 1
Hex code (type L to List codes) : 8e
Command (m for help) : p
Command (m for help) : w
#partprobe /dev/sda

Then Create the new Physical Disks using command :

#pvcreate /dev/sda1
#pvs

Then Create the new Volume Group using command :

#vgcreate myvol /dev/sda1
#vgs

Then Create the new Logical Volume using command :

#lvcreate  -L  2G  -n  lv1  myvol
#lvs

Now Assign File System :

#mkfs.ext4 /dev/myvol/lv1

Now Create a Mount Point :

#mkdir -p /lvm

Now Mount this Logical Volume :

#mount /dev/myvol/lv1 /lvm

Edit the fstab file for Permanent Mount :

#vim /etc/fstab

Add the following line in the /etc/fstab

/dev/myvol/lv1            /lvm         ext4         defaults       0 0

Now run the following command :

#mount -a

Removing LVM partition :

Umount the mount point :

#umount /lvm

we need to remove from /etc/fstab entry :

/dev/myvol/lv1       /lvm          ext4         defaults 0 0

Now remove the Logical Volume :

#lvremove /dev/myvol/lv1

Now remove Volume Group :

#vgremove myvol

Now remove Physical Volume :

#pvremove /dev/sda

Now remove the Partition :

#fdisk /dev/sda
Command (m for help) : d
Partition number (1-4): 1
Command (m for help): w

Now reboot the system.

Leave a Reply

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