How to Create Additional LVM on CentOS 6.3

Share this Article :

This post will covers the steps to create additional Logical volume manager (LVM) on CentOS 6.3. This will very useful when the production system facing run out of disk space to store data. Sometimes there is another request for them to create additional LVM for new system or to store data. It is possible to perform this task if that system administrator has the right skill on linux. Otherwise, they will put themselves and the organization in the disaster or risk as working with the system’s data is on of the most critical job that must be perform with the right steps and skills. Follow below steps :

1. Assumed that second disk has been added called /dev/sdb. Create new partition for /dev/sdb using below command :

[[email protected] ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd29f2d59.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652):
Using default value 652

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd29f2d59

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         652     5237158+  83  Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd29f2d59

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         652     5237158+  8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

2. Convert this disk into a physical volume :

[[email protected] ~]# pvcreate /dev/sdb1
  Writing physical volume data to disk "/dev/sdb1"
  Physical volume "/dev/sdb1" successfully created

Display the physical volume :

[[email protected] ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_centos63
  PV Size               7.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              1922
  Free PE               0
  Allocated PE          1922
  PV UUID               521faS-HW2C-nUrs-yI1E-4OO9-eLmj-1e3bGW

  "/dev/sdb1" is a new physical volume of "4.99 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               4.99 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               qTmTeq-8qoL-xxEk-Dj5V-zOjl-vEag-P6Jl7L

3. With the physical volume created we now need to create new volume group for it. In this case i will give the volume group name vg_data.

[[email protected] ~]# vgcreate vg_data /dev/sdb1
  Volume group "vg_data" successfully created

Display the volume group :

[[email protected] ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_data
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               4.99 GiB
  PE Size               4.00 MiB
  Total PE              1278
  Alloc PE / Size       0 / 0
  Free  PE / Size       1278 / 4.99 GiB
  VG UUID               YV3IYN-3CF9-3Yd1-69ue-wcq4-0UKk-Zk49Vk

  --- Volume group ---
  VG Name               vg_centos63
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               7.51 GiB
  PE Size               4.00 MiB
  Total PE              1922
  Alloc PE / Size       1922 / 7.51 GiB
  Free  PE / Size       0 / 0
  VG UUID               G3H7s2-0yfo-vU9W-5g9g-fq9K-tpNO-U2Y7BQ

4. Create logical volumes with the name of centos63_vol into vg_data volume group :

[[email protected] ~]# lvcreate --name centos63_vol -l 100%FREE vg_data
  Logical volume "centos63_vol" created

Display logical volume :

[[email protected] ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_data/centos63_vol
  LV Name                centos63_vol
  VG Name                vg_data
  LV UUID                bVRJwM-5CuR-mLf4-tqHV-j5e4-cs3o-ffKL41
  LV Write Access        read/write
  LV Creation host, time centos63.ehowstuff.local, 2012-09-28 22:55:13 +0800
  LV Status              available
  # open                 0
  LV Size                4.99 GiB
  Current LE             1278
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/vg_centos63/lv_root
  LV Name                lv_root
  VG Name                vg_centos63
  LV UUID                3Se9Zl-RmAu-f707-1Fv2-wMvX-oH3z-maExU0
  LV Write Access        read/write
  LV Creation host, time centos63.ehowstuff.local, 2012-07-15 20:17:31 +0800
  LV Status              available
  # open                 1
  LV Size                5.54 GiB
  Current LE             1418
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/vg_centos63/lv_swap
  LV Name                lv_swap
  VG Name                vg_centos63
  LV UUID                KijzOf-uPjy-JbJd-dcjw-u0XO-aqPA-2GKScq
  LV Write Access        read/write
  LV Creation host, time centos63.ehowstuff.local, 2012-07-15 20:17:33 +0800
  LV Status              available
  # open                 1
  LV Size                1.97 GiB
  Current LE             504
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

5. Format the LVM using mke2fs with -j switch command :

[[email protected] ~]# mke2fs -j /dev/vg_data/centos63_vol
[[email protected] ~]# mke2fs -j /dev/vg_data/centos63_vol
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1308672 blocks
65433 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

6. Create a mount point for the newly created logical volume :

[[email protected] ~]# mkdir /mydata

7. Define mount point to use this partitions :

[[email protected] ~]# e2label /dev/vg_data/centos63_vol /mydata

8. Modify /etc/fstab and add the following:

[[email protected] ~]# vi /etc/fstab
/dev/vg_data/centos63_vol /mydata                       ext4    defaults        1 1
#
# /etc/fstab
# Created by anaconda on Sun Jul 15 20:17:38 2012
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_centos63-lv_root /                       ext4    defaults        1 1
UUID=2217c7b1-4467-4c81-8596-c3ee7758e2cc /boot                   ext4    defaults        1 2
/dev/mapper/vg_centos63-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/vg_data/centos63_vol /mydata                       ext4    defaults        1 1

9. Mount the newly created logical volume :

[[email protected] ~]# mount /mydata

10. The newly created logical volume will now mount automatically each time the system is booted.

[[email protected] ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos63-lv_root
                      5.5G  2.0G  3.3G  39% /
tmpfs                 504M     0  504M   0% /dev/shm
/dev/sda1             485M   65M  395M  15% /boot
/dev/mapper/vg_data-centos63_vol
                      5.0G  139M  4.6G   3% /mydata

Leave a Reply