Walker News

How To Create Linux LVM In 3 Minutes

What’s LVM? Why using Linux Logical Volume Manager or LVM? Well, these questions are not the scope here. But in brief, the most attractive feature of Logical Volume Manager is to make disk management easier in Linux!

Basically, LVM allows users to dynamically extend or shrink Linux “partition” or file system in online mode! The LVM can resize volume groups (VG) online by adding new physical volumes (PV) or rejecting those existing PVs attached to VG.

A visualized concept diagram of the Linux Logical Volume Manager or LVM.
A visualized concept diagram of the Linux Logical Volume Manager or LVM

In this 3-minutes Linux LVM guide, let’s assume that
  • The LVM is not currently configured or in used. Having say that, this is the LVM tutorial if you’re going to setup LVM from the ground up on a production Linux server with a new SATA / SCSI hard disk.
     
  • Without a luxury server hardware, I tested this LVM tutorial on PC with the secondary hard disk dedicated for LVM setup. So, the Linux dev file of secondary IDE hard disk will be /dev/hdb (or /dev/sdb for SCSI hard disk).
     
  • This guide is fully tested in Red Hat Enterprise Linux 4 with Logical Volume Manager 2 (LVM2) run-time environment (LVM version 2.00.31 2004-12-12, Library version 1.00.19-ioctl 2004-07-03, Driver version 4.1.0)!

How to setup Linux LVM in 3 minutes at command line?
  1. Login with root user ID and try to avoid using sudo command for simplicity reason.
     
  2. Using the whole secondary hard disk for LVM partition:
    fdisk /dev/hdb

    At the Linux fdisk command prompt,
    1. press n to create a new disk partition,
    2. press p to create a primary disk partition,
    3. press 1 to denote it as 1st disk partition,
    4. press ENTER twice to accept the default of 1st and last cylinder – to convert the whole secondary hard disk to a single disk partition,
    5. press t (will automatically select the only partition – partition 1) to change the default Linux partition type (0x83) to LVM partition type (0x8e),
    6. press L to list all the currently supported partition type,
    7. press 8e (as per the L listing) to change partition 1 to 8e, i.e. Linux LVM partition type,
    8. press p to display the secondary hard disk partition setup. Please take note that the first partition is denoted as /dev/hdb1 in Linux,
    9. press w to write the partition table and exit fdisk upon completion.

     
  3. Next, this LVM command will create a LVM physical volume (PV) on a regular hard disk or partition:
    pvcreate /dev/hdb1
     
  4. Now, another LVM command to create a LVM volume group (VG) called vg0 with a physical extent size (PE size) of 16MB:
    vgcreate -s 16M vg0 /dev/hdb1

    Be properly planning ahead of PE size before creating a volume group with vgcreate -s option!
     
  5. Create a 400MB logical volume (LV) called lvol0 on volume group vg0:
    lvcreate -L 400M -n lvol0 vg0

    This lvcreate command will create a softlink /dev/vg0/lvol0 point to a correspondence block device file called /dev/mapper/vg0-lvol0.
     
  6. The Linux LVM setup is almost done. Now is the time to format logical volume lvol0 to create a Red Hat Linux supported file system, i.e. EXT3 file system, with 1% reserved block count:
    mkfs -t ext3 -m 1 -v /dev/vg0/lvol0
     
  7. Create a mount point before mounting the new EXT3 file system:
    mkdir /mnt/vfs
     
  8. The last step of this LVM tutorial – mount the new EXT3 file system created on logical volume lvol0 of LVM to /mnt/vfs mount point:
    mount -t ext3 /dev/vg0/lvol0 /mnt/vfs

To confirm the LVM setup has been completed successfully, the df -h command should display these similar message:

/dev/mapper/vg0-lvol0 388M 11M 374M 3% /mnt/vfs

Some of the useful LVM commands reference:
vgdisplay vg0
 
To check or display volume group setting, such as physical size (PE Size), volume group name (VG name), maximum logical volumes (Max LV), maximum physical volume (Max PV), etc.
 
pvscan
 
To check or list all physical volumes (PV) created for volume group (VG) in the current system.
 
vgextend
 
To dynamically adding more physical volume (PV), i.e. through new hard disk or disk partition, to an existing volume group (VG) in online mode. You’ll have to manually execute vgextend after pvcreate command that create LVM physical volume (PV).

Custom Search

  1. How To Setup Linux VNC Server In 3 Minutes – Walker News 05-07-07@15:39

    […] the newbie (as myself), here is my another 3-minute Linux guide about How to setup VNC server in Red Hat Enterprise […]

  2. How To Install Wordpress Blog In 3 Minutes – Walker News 18-07-07@16:17

    […] and PHP), I’m writing this 3-minutes WordPress setup guide for Red Hat Linux (my another 3-minutes setup guide […]

  3. saan 01-05-09@13:01

    thanks a lot. this is really useful and easy to understand.

  4. Bingo 13-05-09@01:04

    You can actually skip to step 3 and use pvcreate against the entire disk, right?

    Each PhysicalVolume can be a disk partition, whole disk, meta device, or loopback file.

  5. Walker 13-05-09@09:26

    You’re right.

  6. brianko 12-07-09@09:35

    After calling vgextend to add another physical volume, I also had to call lvresize to expand the (new) lv to take advantage of the additional disk space.

  7. Mike 31-10-09@04:03

    Thanks for this Walker- most of the tutorials on the web are just too wordy, this helped me get to where I needed to be, quickly.

  8. Walker 01-11-09@22:32

    You’re welcome.

  9. Dick 02-02-10@15:28

    Please refer to

    http://www.voofie.com/content/13/converting-existing-root-filesystem-to-lvm-in-debian/

    if you wanted to change an existing root system to LVM in Debian. It is very detail, and all the steps needed are shown, and it works for me.

  10. rajkapoor 17-02-10@03:18

    hai i am kapoor, i just want to logical volume manager theory information then how to work in real time.

  11. Fredflintstone 24-02-10@18:07

    I have been looking everywhere for an easy solution to this problem ,and you sorted out this problem in less then 1 minute,
    thank you

  12. Ahmad Tallaa 28-04-10@02:06

    Thanks a lot man. I really appreciate that .

    I will go to the club to celebrate

    Ahmad

  13. Bob 29-04-10@03:02

    Thanks, Brother! This page is very helpful.

  14. Ricola 16-05-10@07:38

    Is it possible to help me out with this ?

    I have Installed latest cent os 64 Bit with 24 GB ram and 4x HDD s 1x 1 TB.

    I need to do this:

    clearpart –all –drives=sda
    part /boot –fstype ext3 –size=128
    part pv.32 –size=12048 –asprimary
    volgroup VolGroup00 –pesize=32768 pv.32
    logvol / –fstype ext3 –name=LogVol00 –vgname=VolGroup00 –size=12032

    But i dont now how i spend alot of money and now i cannot use some software just because of this i dont now how to do it i need some help.

  15. Walker 16-05-10@15:21

    Frankly speaking, I don’t really understand your problem. Sorry about that.

  16. Amit Kumar Pandey 21-05-10@18:56

    Thanks for giving this resolution that we can sortout our problems

  17. Fatiha 03-08-10@23:36

    Thank you very much !!!

  18. Steve Khan 02-10-10@12:33

    It’s the best tutorial i have seen, very descriptive and plain English, i was so confused about PE, then i read your post, and i can’t thank you enough. Please keep educating us.
    Thx
    Steve

  19. Steve Khan 06-10-10@05:23

    Hello Mr. Walker:
    How many Primary PArtitions are allowed in Red Had, or, how many HD i can add as Primary Partitions in Red Had, to extend the LV, Vg in the future.
    Thanks
    Asif

  20. Walker 06-10-10@21:50

    If not mistaken, the fdisk only allow 4 primary partitions per disk.

  21. monu 21-10-10@00:48

    Thnx budy..
    it works..

  22. Ajay 29-11-10@23:00

    It Relay Good Notes, to understand the LVM.

    Thanks…..

  23. subramanian 11-02-11@03:30

    good docs.

  24. Niyas Ahamed 13-02-11@04:16

    It’s wonderful simple notes for Logical volume manager.

  25. Pat 24-11-11@10:19

    I read another tutorial where they didn’t fdisk the hard drive first. Ex:

    pvcreate /dev/hdb
    pvcreate /dev/hdc
    vgcreate -s 16M vg0 /dev/hdb /dev/hdc

    What’s the difference? Will doing it one way versus another lead to any differences in performance/behavior later on? Both methods work for me, just wondering what the best practice is if any? Thx.

  26. mangesh 13-01-12@23:58

    It’s wonderful simple notes for Logical volume manager. very easy

  27. Gaurav 02-03-12@23:37

    very nice and simple to understand article.
    It Helped :)

  28. Paul 30-03-12@16:06

    Thank you a million times. I finally start to understand this architecture now. Small improvement, step 8: I think you should put the entry in /etc/fstab and then mount -a to be sure it returns after reboot. Am I right?

  29. Walker 31-03-12@00:47

    Yes, the /etc/fstab entries will be mounted upon Linux boot-up.

  30. Sabrina 29-06-12@20:14

    This was so helpful. I researched for hours before finding this. I

  31. Adam 10-08-12@21:45

    I have created the logical volume and when I go to use mkfs -V -t ext2 /dev/vg_data/lv_data. And over the course of more than 12 hours it will only go up to “writing inode tables: 5000/22119″.

    Any thoughts on why this is taking so long? I have done this in the past on other systems and a similar size may take up to 10 minutes, but never more than an hour.

  32. Peter 06-09-12@14:06

    Hi,

    You write:
    “df -h command should display these similar message:

    /dev/mapper/vg0-lvol0 388M 11M 374M 3% /mnt/vfs”

    But why are 3% (11M) already used?

    TIA for any hints!
    Peter

  33. Walker 07-09-12@00:10

    …because “-m 1″ used in step-6.

  34. Pratheep 30-06-13@02:43

    Thanks a lot …

  35. Jaky 04-12-13@22:21

    This little blog page still Rocks. (bookmarked 3 years ago) Still the easyest nicest shortest “LV-manage” page on under my lvm,linux,diskpart tags!!
    Thanks again.

  36. Hidayatulla Khan 01-01-14@01:56

    The blog is real useful for newbie….

2014  •  Privacy Policy