How to create LVM Partition in Linux

How to create LVM Partition in Linux

Physical volume (PV):- PV is the partitions on hard disk, or hard disk itself. PV are the base of LVM structure and referred as physical volumes.

Volume Group (VG):- VG are the combined physical volume into a single pool of storage. Think it is as a group of PV.

Logical volume (LV):- LV is the actual partitions on system created from VG.

Follow below steps to create file systems in Linux machines:

  • fdisk -l command will list the current partitions.
  • Use following command to create PV from hard disk.

      #pvcreate [disk]

           If you have more than one partition to be configured as PV, you can list them as well

               #pvcreate [disk partition] [disk partition] [disk partition]

    Run below command to check physical volumes

      # pvs or pvdisplay

  • To create new volume using fdisk

fdisk /dev/sdx [Replace /dev/sdx with your hard disk mount point]

n [command to create new partition in fdisk prompt]

press enter [ accept default first cylinder ]

+200M [ Size of LVM, specify it at as per your need and availability of space ]

t [command to set the partition type]

6 [Number or our created partition, make sure here you specify current number.]

8e [Code to set partition type LVM]

w [command to save the change ]

  • To create Volume group

# vgcreate VGname pvname

           Run below command to check Volume groups

      # vgs or vgdisplay

  • We can create logical volume by giving the name of a new logical volume, its size, and the volume group it will live on.

# lvcreate -L size(GB/MB/No. of Blocks)-n LVname VGname

  • Create Directory to mount file system

# mkdir –p /NEWFS

  • Mount new FS

# mount /dev/vgname/lvname /NEWFS

  • To mount them permanently add new FS edit  /etc/fstab file

# vi /etc/fstab

eg.

/dev/newvg/newlv mountname fstype defaults 0 0