Setup Flexible Disk Storage with Logical Volume Management (LVM) in Linux – PART 1

Logical Volume Management (LVM) makes it easier to manage disk space. If a file system needs more space, it can be added to its logical volumes from the free spaces in its volume group and the file system can be re-sized as we wish. If a disk starts to fail, replacement disk can be registered as a physical volume with the volume group and the logical volumes extents can be migrated to the new disk without data loss.

Create LVM Storage in Linux

Create LVM Storage in Linux

In a modern world every Server needs more space day by day for that we need to expand depending on our needs. Logical volumes can be use in RAID, SAN. A Physical Disk will be grouped to create a volume Group. Inside volume group we need to slice the space to create Logical volumes. While using logical volumes we can extend across multiple disks, logical volumes or reduce logical volumes in size with some commands without reformatting and re-partitioning the current disk. Volumes can stripes data across multiple disks this can increase the I/O stats.

LVM Features

  1. It is flexible to expand the space at any time.
  2. Any file systems can be installed and handle.
  3. Migration can be used to recover faulty disk.
  4. Restore the file system using Snapshot features to earlier stage. etc…
My Server Setup – Requirements
  1. Operating System – CentOS 6.5 with LVM Installation
  2. Server IP – 192.168.0.200

This series will be titled Preparation for the setting up LVM (Logical Volume Management) through Parts 1-6 and covers the following topics.

Part 1Setup Flexible Disk Storage with Logical Volume Management

Creating LVM Disk Storage in Linux

1. We’ve used CentOS 6.5 Operating system using LVM in a Virtual Disk (VDA). Here we can see the Physical Volume (PV), Volume Group (VG), Logical Volume (LV) by using following command.

# pvs 
# vgs
# lvs
Check Physical Volumes

Check Physical Volumes

Here, is the description of each parameters shown in above screenshot.

  1. Physical Disk Size (PV Size)
  2. Disk which used was Virtual Disk vda.
  3. Volume Group Size (VG Size)
  4. Volume Group name (vg_tecmint)
  5. Logical Volume name (LogVol00, LogVol01)
  6. LogVol00 Assigned for sawp with 1GB Size
  7. LogVol01 Assigned for / with 16.5GB

So, from here we come to know that there is not enough free space in VDA disk.

2. For Creating a New Volume Group, we need to add Additional 3 hard disks in this server. It is not Compulsory to use 3 Drives just 1 is Enough to create a new VG and LV inside that vg, I am adding more here for demonstration purpose and for more feature command explanations.

Following are the disks I have added additionally.

sda, sdb, sdc
# fdisk -l
Verify Added Disks

Verify Added Disks

  1. Default Disk using for Operating system (Centos6.5).
  2. Partitions defined in default Disk (vda1 = swap), (vda2 = /).
  3. Additionally added Disks are mentioned as Disk1, Disk2, Disk3.

Each and every Disks are 20 GB in Size. Default PE Size of a Volume Group is 4 MB, Volume group what we are using in this server is configured using default PE.

Volume Group Display

Volume Group Display

  1. VG Name – A Volume Group name.
  2. Format – LVM Architecture Used LVM2.
  3. VG Access – Volume Group is in Read and Write and ready to use.
  4. VG Status – Volume Group can be re-sized, We can Expand more if we need to add more space.
  5. Cur LV – Currently there was 2 Logical volumes in this Volume Group.
  6. CurPV and Act PV – Currently Using Physical Disk was 1 (vda), And its active, so what we can use this volume group.
  7. PE Size – Physical Extends, Size for a disk can be defined using PE or GB size, 4MB is the Default PE size of LVM. For example, if we need to create 5 GB size of logical volume we can use sum of 1280 PE, Don’t you understand what I’m saying ?.

Here the Explanation –> 1024MB = 1GB, if so 1024MB x 5 = 5120PE = 5GB, Now Divide the 5120/4 = 1280, 4 is the Default PE Size.

  1. Total PE – This Volume Group have.
  2. Alloc PE – Total PE Used, full PE already Used, 4482 x 4PE = 17928.
  3. Free PE – Here it’s already used so there was no free PE.

3. Only vda used, Currently Centos Installed /boot/swap, in vda physical disk using lvm there were no space remaining in this disk.

# df -TH
Check the Disk Space

Check the Disk Space

Above image shows the mount Point we are using 18GB fully used for root, so there is no free space available.

4. So let’s, create new physical volume (pv), Volume Group (vg) in the name of tecmint_add_vg and create Logical Volumes (lv) in it, Here we can create 4 Logical Volumes in the name of tecmint_documentstecmint_manager and tecmint_public.

We can extend the Volume Group of currently using VG to get more space. But here, what we are going to do is to Create new Volume Group and play around it, later we can see how to extend the file systems Volume group which is currently in use.

Before using a new Disk we need to partition the disk using fdisk.

# fdisk -cu /dev/sda
  1. c – Switch off DOS-compatible mode it is Recommend to include this Option.
  2. u – While listing the partition tables it will give us in sector instead of cylinder.
Create New Physical Partitions

Create New Physical Partitions

Next, follow the below steps to create new partition.

  1. Choose n to create new.
  2. Choose p to create a primary partition.
  3. Choose which number of partition we need to create.
  4. Press Enter twice to use the full space of the Disk.
  5. We need to change the type of newly created partition type t.
  6. Which number of partition need to change, choose the number which we created its 1.
  7. Here we need to change the type, we need to create LVM so we going to use the type code of LVM as 8e, if we do not know the type code Press L to list all type codes.
  8. Print the Partition what we created to just confirm.
  9. Here we can see the ID as 8e LINUX LVM.
  10. Write the changes and exit fdisk.

Do the above steps for other 2 disks sdb and sdc to create new partitions. Then Restart the machine to verify the partition table using fdisk command.

# fdisk -l
Verify Partition Table

Verify Partition Table

Creating Physical Volumes

5. Now, it’s time to create Physical Volumes using all 3 disks. Here, I have listed the physical disk using pvs command, only one default pvs is now listed.

# pvs

Then create the new physical disks using command.

# pvcreate /dev/sda1 /dev/sdb1 /dev/sdc1

Once again list the disk to see the newly created Physical disks.

# pvs
Create Physical Volumes

Create Physical Volumes

Creating Volume Groups

6. Create Volume Group in the name of tecmint_add_vg using available free PV Create using PE size 32. To Display the current volume groups, we can see there is one volume group with 1 PV using.

# vgs

This will create the volume group using 32MB PE size in the name of tecmint_add_vg using 3 Physical volumes we created in last steps.

# vgcreate -s 32M tecmint_add_vg /dev/sda1 /dev/sdb1 /dev/sdc1

Next, verify the volume group by running vgs command again.

# vgs
Create Volume Groups

Create Volume Groups

Verify Volume Groups

Verify Volume Groups

Understanding vgs command output:

  1. Volume Group name.
  2. Physical Volumes used in this Volume Group.
  3. Shows free space available in this volume group.
  4. Total Size of the Volume Group.
  5. Logical Volumes inside this volume group, Here we have not yet created so there is 0.
  6. SN = Number of Snapshots the volume group contains. (Later we can create a snapshot).
  7. Status of the Volume group as Writeable, readable, resizeable, exported, partial and clustered, Here it is wz–n- that means w = Writable, z = resizeable..
  8. Number of Physical Volume (PV) used in this Volume Group.

  • 11 Users Found This Useful
  • Was this answer helpful?

    Related Articles

    S.M.A.R.T (smartctl) commands and test

    Installation of Smartcl in Ubuntu $ sudo apt-get install smartmontools Installation of Smartcl...

    How to: Replacing a failed drive in a Linux Software RAID1 configuration (mdraid)

    Scenario: A drive has failed in your linux RAID1 configuration and you need to replace it....

    Check disk details

    lsblk -o name,label,size,fstype,mountpoint,modefdisk -l

    How to Increase the size of a Linux LVM by expanding the Disk

    This post will cover how to increase the disk space for a VMware virtual machine running Linux...

    How to Extend/Reduce LVM’s (Logical Volume Management) in Linux – Part II

    Previously we have seen how to create a flexible disk storage using LVM. Here, we are going to...

    Powered by WHMCompleteSolution