• How To Create LVM Using pvcreate, vgcreate, lvcreate Commands

    LVM stands for Logical Volume Manager.

    With LVM, we can create logical partitions that can span across one or more physical hard drives. First, the hard drives are divided into physical volumes, then those physical volumes are combined together to create the volume group and finally the logical volumes are created from volume group.

    To create a LVM, we need to run through the following steps.

    • Select the physical storage devices for LVM
    • Create the Volume Group from Physical Volumes
    • Create Logical Volumes from Volume Group
    Suppose that your physical device that you want to work on is /dev/sda
    #pvcreate /dev/sda
    #[root@Raafat~]# pvdisplay
       --- Physical volume ---
      PV Name               /dev/sda
      VG Name               Raafat_DB
      PV Size               59.63 GiB / not usable 1.34 MiB
      Allocatable           yes (but full)
      PE Size               4.00 MiB
      Total PE              15264
      Free PE               0
      Allocated PE          15264
      PV UUID               s5hY1E-o0dm-G13d-KXx2-jmPq-e4ao-JFYo4N

    Create the Volume Group – Use vgcreate, vgdisplay Commands:

    #vgcreate Raafat_DB /dev/sda
    #[root@Raafat~]# vgdisplay
     --- Volume group ---
      VG Name               Raafat_DB
      System ID
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  2
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                1
      Open LV               1
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               59.62 GiB
      PE Size               4.00 MiB
      Total PE              15264
      Alloc PE / Size       15264 / 59.62 GiB
      Free  PE / Size       0 / 0
      VG UUID               Oj5hbN-s5yE-Jc22-5UC6-uvd3-zeuP-78Snye

    LVM Create: Create Logical Volumes – Use lvcreate, lvdisplay command:

    #lvcreate -n mysql -l 100%FREE  Raafat_DB
    Note:The abov command will add all space to the LVM created ,if you want to add some space only (20 GB) ,use the following :

    lvcreate -L 20G -n mysql Raafat_DB
    [root@Raafat ~]# lvdisplay

    — Logical volume —
    LV Path                /dev/Raafat_DB/mysql
    LV Name                mysql
    VG Name                Raafat_DB
    LV UUID                K0vpGT-uDI8-jVHt-0HKw-m21Y-W7QQ-JkyrlX
    LV Write Access        read/write
    LV Creation host, time Raafat, 2012-09-23 15:44:57 +0300
    LV Status              available
    # open                 1
    LV Size                59.62 GiB
    Current LE             15264
    Segments               1
    Allocation             inherit
    Read ahead sectors     auto
    – currently set to     256
    Block device           253:4

    After creating the appropriate filesystem on the logical volumes, it becomes ready to use for the storage purpose.

    $ mkfs.ext4 /dev/Raafat_DB/mysql
    Then you can mount it under any mount point
    mkdir /var/lib/mysql
    mount -t ext4 /dev/Raafat_DB/mysql /var/lib/mysql
    Add the settings to /etc/fstab to be mounted automatically if server rebooted:
    /dev/Raafat_DB/mysql    /var/lib/mysql          ext4   defaults        0 0
    That is all what you have to do :)

    Categories: Linux

    Comments are currently closed.