Create a new LVM partition on an extra disk

This article deals with showing how to configure a second disk using LVM. This could be for example in a situation where the server currently has 1 disk but no LVM configured and now you have added a second disk. The examples use KVM virtual machine hence the device names are vd* while if you were using vmware or physical disks they would be sd* .

Create a partition on the new disk using fdisk.

The first thing we do is to create a partition on the new disk using fdisk.

[root@rhel-lab1 ~]# fdisk /dev/vdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x1b480d00.
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): p

Disk /dev/vdc: 8589 MB, 8589934592 bytes
16 heads, 63 sectors/track, 16644 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x1b480d00

   Device Boot      Start         End      Blocks   Id  System

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

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): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@rhel-lab1 ~]#

In the above, once fdisk is launched, press p and then 1 to create the partition and I have accepted the default start and size of the partition [using the whole disk] and then pressed *t* to set the type of the partition to *8e*

Create Physical Volume

[root@rhel-lab1 ~]# pvcreate /dev/vdc1 
  Physical volume "/dev/vdc1" successfully created
[root@rhel-lab1 ~]# pvdisplay /dev/vdc1
  "/dev/vdc1" is a new physical volume of "8.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/vdc1
  VG Name               
  PV Size               8.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               fUnT5I-wL5j-u8nN-cTD4-oMPu-0Ff5-zKKWJe

Create a new Volume Group

In this example we want to create a new volume group. [For example in the case where there is no volume groups yet]

[root@rhel-lab1 ~]# vgcreate VolumeGroupHome /dev/vdc1 
  Volume group "VolumeGroupHome" successfully created

We can examine the newly created VolumeGroup as:

[root@rhel-lab1 ~]# vgdisplay VolumeGroupHome
  --- Volume group ---
  VG Name               VolumeGroupHome
  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               8.00 GiB
  PE Size               4.00 MiB
  Total PE              2047
  Alloc PE / Size       0 / 0   
  Free  PE / Size       2047 / 8.00 GiB
  VG UUID               Tzd0l6-A4Ji-zR9n-cjGx-2ou3-EggK-2xDJWK

The final step is to create the Logical Volume

[root@rhel-lab1 ~]# lvcreate -L 2G -n lv_home VolumeGroupHome
  Logical volume "lv_home" created