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 ||

35 Comments

  1. harsh   •  

    this post is wonderful can i get the same for linux i m extream need of it

    • Akash Deep Singh   •     Author

      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.

      • Chin Hock   •  

        i have tested on Redhat EL6, and it worked :)

  2. Dhana   •  

    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,

    • Akash Deep Singh   •     Author

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

  3. Vy   •  

    Great info. Tried on RHEL 6.3 and worked great. Thanks for sharing.

  4. bhuwan   •  

    great post dearr…

  5. Hariprasath   •  

    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.

  6. ravi   •  

    where can i find your next post where you have taught of resizing and deleting LVM????

    • Chanda   •  

      VERY HELPFUL…where is the next post of resizing…????

      :-)

    • Akash Deep Singh   •     Author

      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.

  7. chinna   •  

    Great post

    How to add same in fstab pls

    Thanks
    chinappan

    • openstrike linux   •  

      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

  8. Nitin   •  

    Nice post. i would love to see how to resize the LVs

  9. Avinash Patil   •  

    very helpful :)

  10. pradeep   •  

    hi,
    this is the best way of learn LVM;
    thnks….

  11. muhammad farooq   •  

    thanks well done

  12. Mohit   •  

    Good explaination. thank you.

  13. izn0g00d   •  

    great lecture for clients

  14. Amit Anchal   •  

    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!

  15. agnel   •  

    You have saved my interview bro..lol.
    Thanks for this arcticle.

    • Akash Deep Singh   •     Author

      Great to hear that

  16. Muthukumar   •  

    Thanks for the explain and shared the knowledge

  17. sanjay Guntupalli   •  

    it’s really good, please post more technical doc’s in linux

  18. shameem   •  

    Great!

  19. ranjith kumar   •  

    hi akash,its good about that iam telling lvm concepts,iam getting understand good ,
    thank you for explaining lvm concepts

    • Akash Deep Singh   •     Author

      Thanks

  20. mack   •  

    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……..

    • Akash Deep Singh   •     Author

      Thanks, I appreciate the comments

  21. Sirisha   •  

    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….

  22. prakash talekar   •  

    Thanks very much.I am new to Linux.This post help me slots. I did setup

  23. CENTRAFRIQUE   •  

    This post is more than excellent, who ever should understand now how to set up LVM base on this post. God bless you.

  24. Akash Rana   •  

    Thanks sir that was create but waiting for extend, resize or delete waiting for your reply….

  25. Venkat   •  

    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.”

Leave a Reply

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