October 22, 2019

How To Setup Logical Volume Manager (LVM) Step By Step

In my last post I explained about the concepts of the Logical Volume Manager (LVM). If you need some background on Logical Volume Manager (LVM) or you are new to LINUX you can read the post Understanding The Concept Of Logical Volume Manager – LVM. Now hope you have a fair background with linux and the LVM lets try to setup it on a Ubuntu Linux Machine, you can use any LINUX distribution to set Setup Logical Volume Manager (LVM). The commands are almost same.

The setup of my machine is :-
1.) Primary Disk 20 Gb (dev/sda).
2.) Secondary Disk 10 GB (dev/sdb) [Will be used for LVM].
3.) Third Disk 6GB (dev/sdc) [Will be used for LVM].

Now to find the partitions or drives in your machine you can use the following command.

sudo fdisk -l

Now as per my previous post I want to use the same partition size for secondary disk as 10Gb but 3 Gb for Third disk because I also want to show how to extend the LVM partition. So we start by formatting the drives.

STEP1.) Partitioning the 10 Gb drive

sudo fdisk /dev/sdb

Note:- The hard drive name can be different in your system.

Now press n to create a new partition .

Now press p to make it a primary partition.

Now it will ask you to specify the starting cylinder as it is a raw disk and we need to use it the full capacity simply press enter.

Now enter the last cylinder. Just simply press enter as we need to use the whole disk. The drive has been initialized and read to be formatted.

You can check the partition information by pressing the p. All the steps are explained in the following image.

Now after finishing the above step we see that the above partition type is LINUX (Code 83) so we need to make it type LVM.

Now press t

Select the partition ( In this case we have only single partition on the disk so one will be automatically selected)

Now we need to enter the HEX code for the partition type . To find the Codes we can use l.

Now from the list we know the code is 8e. So type8e. The partition type is now LVM. Now to write the changes press w.

Now to make the kernel aware of the changes use partprobe command.

sudo partprobe /dev/sdb

Now we need to have our third hard-drive ready for the LVM we repeat the same step again but not taking the default start and finish cylinder number instead we specify the size as according to our need. I am using 4 GB ( the previous post explaining mentioned 6GB but to show how to extend LVM I am using 4GB.

So lets start again with the new drive :-

sudo fdisk /dev/sdc

Type n for new partition.
Now type p for making it a primary partition.
Now press enter as we are starting from a raw disk
Now on the finishing cylinder type +4G as we need the size 4GB.
Press t and type 8e (LINUX LVM partition code)
Press w to write changes. You can also issue the command

sudo partprobe /dev/sdc

your basic work is done. The drives are ready to be used to setup LVM.

All the steps can be verified from the following image.

STEP2.) Create the Physical Volumes

sudo pvcreate /dev/sdb1 /dev/sdc1

Now Create the Volume Group the name of the volume group is routemybrain

sudo vgcreate routemybrain /dev/sdb1 /dev/sdc1

You can verify the LOGICAL GROUP using the command vgdisplay

Creating the Logical volume

sudo lvcreate routemybrain -L +14G -n akash

routemybrain -> The name of the volume group
-L -> To specify the size of the partition in our case 14GB
-n -> To specify the name of the Logical volume in our case akash.

we can see the logical volume with the help of lvdisplay.

The LVM setup is done and finally we have created a LVM parition of 14gb now the final step just to mount it.

STEP3.) Make a directory for mounting the share

sudo mkdir /home/newtrojan/Lvm-Mount

now format the LVM partition.

sudo mkfs.ext3 /dev/routemybrain/akash

Now mount the partition

sudo mount /dev/routemybrain/akash /home/newtrojan/Lvm_Mount

you can verify the mount by issuing df -h command

That was really a long post. In the next post I will be explaining how to extend, resize or delete a Logical Volume Manager (LVM) partition

Akash Deep Singh

|| Eat Packets || Drink Management || Sleep Virtual || Work Linux || Think I.T. || Love MAC || Look After Windows || Dream APPS ||

View all posts by Akash Deep Singh →

38 thoughts on “How To Setup Logical Volume Manager (LVM) Step By Step

    1. Thanks for the comment Harsh.

      This post is generic to linux and should work on all distributions. I used ubuntu for this post ( Commands may vary for red hat or centos) I will check out and post soon.

  1. Dear Akash,

    just i want to know how to extend, resize or delete a Logical Volume Manager (LVM) partition and what are the command changes will be there in RHEL while doing LVM,

    1. I have to try that.. Will let you know and if I find another useful Link I will share it with you.

  2. hi Akash

    Yoyr post is very helpfull. I have one doubt, after mount the lvm partition into the new directory, if I restart my machine, what will happen ?

    let me know the answer.

    1. Thanks Ravi.

      SO much busy with office work these days. Havent written a single post since last year.

      I have so much to write on linux, vyatta and vmware.

    1. while adding in vim /etc/fstab
      go with this command vim /etc/fstab
      /dev/vgname/lvm name———– /dell(your mount point) ————-ext4(in whic you want to formate ur drive)—————– defaults ———-0 0

  3. Great document bro!!
    Thanks a lot… it make me understand very easily. Before this I was thinking that LVM is very heard to learn.

    Thanks again!

    Amit Anchal!

  4. Hi Akash,

    I searched in Internet for how to create LVM partition
    but i didn’t get properly method and not understanding properly
    but I check your article I like it so so much and it is very helpful me and I understand it very well
    and you explain lvm partition in very easy way so everybody can understand easily.
    so thanks for share this article
    Thanks a lot……..

  5. Hi,

    Actually i visited so many websites for understanding Lvm Concept, but toomuch confusion regrading this concept. After gone through ur post m totally cleared, its like a spoon feeding..Wahh Super explaination… Thanq soo much for sharing this valuable post…

    Thnks a lottt….

  6. nice post, i tried in my system . but facing some error , please let me know how to resolve this.

    “WARNING: Re-reading the partition table failed with error 22: Invalid argument.”

  7. Hi dear Deep Singh
    I want to use LVM but I used sudo fdisk -l and the result is” Disk -dev/sda ” but the tutorial you have explain has Disk /dev/sdb and Disk /dev/sdc How can I have 2 or 3 disk as your system ?

  8. Hi dear Deep Singh
    I want to use LVM but I used sudo fdisk -l and the result is” Disk -dev/sda ” but the tutorial you have explain has Disk /dev/sdb and Disk /dev/sdc How can I have 2 or 3 disk as your system ?

Leave a Reply

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