How to Setup Additional LVM in CentOS 5.5

In this post, i will share on how to setup additional LVM in CentOS 5.5.

1. Assumed that new hard disk 2 (sdb) has been added in this CentOS 5.5 server.
2. Print the current partition table of the hard disk :

[root@server ~]# fdisk -lu

Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63      208844      104391   83  Linux
/dev/sda2          208845     2313359     1052257+  82  Linux swap / Solaris
/dev/sda3         2313360    14667344     6176992+  8e  Linux LVM
/dev/sda4        14667345    41929649    13631152+  8e  Linux LVM

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes

Disk /dev/sdb doesn't contain a valid partition table
3. Create new partition for /dev/sdb using below command.

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


The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610):
Using default value 2610

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: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

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

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@server ~]# mke2fs -j /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2621440 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
160 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

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

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

4. Next create the new partitions for this LVM.

[root@server ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created

5. Display the Physical Volume using command below:

[root@server ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda4
  VG Name               VolGroup00
  PV Size               13.00 GB / not usable 3.67 MB
  Allocatable           yes (but full)
  PE Size (KByte)       4096
  Total PE              3327
  Free PE               0
  Allocated PE          3327
  PV UUID               JgYuxF-UJiB-t148-g5WQ-Lx05-Ozk1-13UwAR

  "/dev/sdb1" is a new physical volume of "19.99 GB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               19.99 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               246F8V-FMTR-WNK0-9305-q2sf-PKtC-VQXOQr

6. Create new volume group for /dev/sdb1. Assumed that previous volume goup is VolGroup00. So next volume group will be VolGroup01.

[root@server ~]# vgcreate VolGroup01 /dev/sdb1
  Volume group "VolGroup01" successfully created

7. Display the existing Volume Group.

[root@server ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup01
  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               19.99 GB
  PE Size               4.00 MB
  Total PE              5118
  Alloc PE / Size       0 / 0
  Free  PE / Size       5118 / 19.99 GB
  VG UUID               tvLVhu-6Nzo-jB0b-oZQ4-VY30-9TP4-Dhxvvm

  --- Volume group ---
  VG Name               VolGroup00
  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               13.00 GB
  PE Size               4.00 MB
  Total PE              3327
  Alloc PE / Size       3327 / 13.00 GB
  Free  PE / Size       0 / 0
  VG UUID               3XozzT-3A3w-6eXs-XoEb-yRN1-v9FM-N0YheL

8. Create logical volumes with the name of optvol into VolGroup01 volume group.

[root@server ~]# lvcreate --name optvol -l 100%FREE VolGroup01
  Logical volume "optvol" created

9. Display the logical volumes.

[root@server ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup01/optvol
  VG Name                VolGroup01
  LV UUID                YXkMnR-l7gH-tj0r-dCUt-Ncl7-aTmb-Vas4Tp
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                19.99 GB
  Current LE             5118
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Name                /dev/VolGroup00/datavol
  VG Name                VolGroup00
  LV UUID                KowzAO-WWMj-O0xw-IY31-Gfqv-sjaE-nYvdhk
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                13.00 GB
  Current LE             3327
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

10. creating a file with the mke2fs command

[root@server ~]# mke2fs -j /dev/VolGroup01/optvol
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2621440 inodes, 5240832 blocks
262041 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
160 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

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

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@server ~]# e2label /dev/VolGroup01/optvol /opt
[root@server ~]# vi /etc/fstab
[root@server ~]# mount /opt
[root@server ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             5.8G  4.3G  1.2G  79% /
/dev/sda1              99M   12M   83M  13% /boot
tmpfs                 506M     0  506M   0% /dev/shm
/dev/mapper/VolGroup00-datavol
                       13G  855M   12G   7% /data
/dev/mapper/VolGroup01-optvol
                       20G  173M   19G   1% /opt
[root@server ~]# fdisk -lu

Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63      208844      104391   83  Linux
/dev/sda2          208845     2313359     1052257+  82  Linux swap / Solaris
/dev/sda3         2313360    14667344     6176992+  8e  Linux LVM
/dev/sda4        14667345    41929649    13631152+  8e  Linux LVM

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1              63    41929649    20964793+  8e  Linux LVM

References:

https://wiki.archlinux.org/index.php/LVM
http://vr.org/docs/centos/5/html/Cluster_Logical_Volume_Manager/LV_create.html
http://serverfault.com/questions/41904/volume-group-out-of-space-how-do-i-reclaim-it
http://www.idevelopment.info/data/Unix/Linux/LINUX_ManagingPhysicalLogicalVolumes.shtml
http://en.gentoo-wiki.com/wiki/Root_filesystem_over_LVM2,_DM-Crypt_and_RAID
http://wingloon.com/2009/01/16/setup-additional-lvm-in-centos-52/
http://rute.2038bug.com/node22.html.gz