How to create LVM(Logical Volume Manager) in Linux

What is Partition?

Using partitions, you can separate your hard drive into sections that can run independently. Storage devices (USB and hard drives) must be structured before being used in Linux. You can also use partitioning when installing multiple operating systems on the same computer.

What is Logical Volume?

In a non-LVM system, a Logical Volume is equivalent to a disk partition. Physical extents within a volume group are the basis for creating logical volumes. Lvcreate can be used to create a logical volume within an existing volume group.

What is Volume Group?

Logical Volume Manager (LVM) is structured around volume groups (VGs). Eventually, you create one storage structure based on the combined storage capacities of multiple physical volumes. We cannot create a Volume Group without a physical volume.

What is Physical Volume?

LVM allows you to create physical volumes, e.g. Hard Disk Drives (HDDs), Solid State Drives (SSDs), and partitions, that are configured as physical volumes initially. Creating Volume Groups and Logical Volumes is not possible without properly initialized physical volumes.

Future Tech India/ Logical Volume Manager

Shutdown your VM and increase the disk size

First, shut down your VM and increase the disk size. Here, I have extended the disk or added three new disks /dev/sdb /dev/sdc and /dev/sdd of size 15 GB. Then start your VM and go to the console.

#fdisk -l

Creating an LVM

Before creating LVM we can see new devices not mounted.

#df -Th

Creating a PV

Create a new physical disk using the command.

#pvcreate /dev/sdb (disk name)

Display physical volumes

Use the pvdisplay, pvs, and pvscan commands to display the PV we just created.

#pvdisplay [disk_name (optional)]

#vgcreate [group_name][disk1][disk2]

#vgdisplay [group_name]

We can run the command vgs and vgdisplay to get more information about the VG we just created:

Creating Logical Volume

A logical volume can now be created using the lvcreate command in the VG.

#lvcreate — size 14G — name [LV name][VG name]

# mkdir mount_point

#mount /dev/mapper/myvg_01-my_LVM mount_point

#df -Th

Increase Size of Logical Volume

Add newly created pv named /dev/vde to an existing lv

We can see disks from below

#fdisk -l

Here new hard disk is attached /dev/sde

#vgextend myvg_01 /dev/sde

#vgdisplay myvg_01

you can see here that the size of vg is extend 14.99GB to 19.89GB

#lvextend –size +5G /dev/myvg_01/my_LVM

#resize2fs /dev/mapper/myvg_01-my_LVM

#df -Th

The size is increase 14 GB to 19GB

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store