– First you need to create partition image

– In this example i create 3 partitions
————————————————-
[root@localhost ~]# fdisk /dev/sdb

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

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): c
DOS Compatibility flag is not set

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 or +size or +sizeM or +sizeK (1-652, default 652): +2000M

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

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

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

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

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 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

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         244     1959929+  8e  Linux LVM
/dev/sdb2             245         488     1959930   8e  Linux LVM
/dev/sdb3             489         611      987997+  8e  Linux LVM

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

Calling ioctl() to re-read partition table.
Syncing disks.
– 3 partitions create with LVM type ( 8e )
– Sync partition table with kernal
[root@localhost ~]# partprobe /dev/sdb

– Create physical volume with “pvcreate” 
[root@localhost ~]# pvcreate /dev/sdb1 /dev/sdb2
  Physical volume “/dev/sdb1” successfully created
  Physical volume “/dev/sdb2” successfully created
– Display physical volume
[root@localhost ~]# pvdisplay
  “/dev/sdb1” is a new physical volume of “1.87 GB”
  — NEW Physical volume —
  PV Name               /dev/sdb1
  VG Name              
  PV Size               1.87 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               wB03Xj-pmeY-nQsD-4sUE-TDKo-DixY-2sM921
  
  “/dev/sdb2” is a new physical volume of “1.87 GB”
  — NEW Physical volume —
  PV Name               /dev/sdb2
  VG Name              
  PV Size               1.87 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               A1Ya1v-Y2gn-NqYc-mlV3-7BDJ-lEFp-p2bFMB
– Create volume group where “data” is name of volume group  
[root@localhost ~]# vgcreate data /dev/sdb1 /dev/sdb2

    Volume group “data” successfully created
– Display Volume goup
[root@localhost ~]# vgdisplay
  — Volume group —
  VG Name               data
  System ID            
  Format                lvm2
  Metadata Areas        2
  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                2
  Act PV                2
  VG Size               3.73 GB
  PE Size               4.00 MB
  Total PE              956
  Alloc PE / Size       0 / 0  
  Free  PE / Size       956 / 3.73 GB
  VG UUID               5AMVM3-3gZE-CTw4-tF85-PWD0-eNXE-NHHJGf
– Create Logical volume where ora is name of Logical volume ( +2G is size )  
[root@localhost ~]# lvcreate data -L +2G -n ora
  Logical volume “ora” created
– Display Logical volume information
[root@localhost ~]# lvdisplay
  — Logical volume —
  LV Name                /dev/data/ora
  VG Name                data
  LV UUID                uCBDf5-I1H6-SmWF-Z6kG-TMPV-qCi3-0QaDPK
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                2.00 GB
  Current LE             512
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  – currently set to     256
  Block device           253:0
– Make file system  
[root@localhost ~]# mkfs.ext3 /dev/data/ora
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
262144 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

Writing inode tables:  0/16 1/16 2/16 3/16 4/16 5/16 6/16 7/16 8/16 9/1610/1611/1612/1613/1614/1615/16done                           
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
– Mount Logical volume for use
[root@localhost ~]# mount /dev/data/ora /data/
– See mounting details
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             3.8G  3.1G  569M  85% /
sysfs                 3.8G  3.8G     0 100% /sys
/dev/sda5             4.0G  139M  3.6G   4% /home
/dev/sda1              46M   11M   33M  25% /boot
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.8G  3.8G     0 100% /sys
.host:/               196G   31G  165G  16% /mnt/hgfs
/dev/mapper/data-ora  2.0G   68M  1.9G   4% /data
– Now we want to add more space in Logical volume
– So 1st add space in PV ( Physical Volume )
[root@localhost ~]# pvcreate /selinux/dev/sdb3
  Physical volume “/dev/sdb3” successfully created
– Add this in Virtual group
[root@localhost ~]# vgextend data /dev/sdb3

  /dev/cdrom: open failed: Read-only file system
  Attempt to close device ‘/dev/cdrom’ which is not open.
  Volume group “data” successfully extended
– See details
[root@localhost ~]# vgdisplay
  — Volume group —
  VG Name               data
  System ID            
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               4.68 GB
  PE Size               4.00 MB
  Total PE              1197
  Alloc PE / Size       512 / 2.00 GB
  Free  PE / Size       685 / 2.68 GB
  VG UUID               5AMVM3-3gZE-CTw4-tF85-PWD0-eNXE-NHHJGf
– Here we have free space which is add in VG ( Free  PE / Size  685 / 2.68 GB )
– Add space in LV ( +30 is PE size 30x4MB ) 

[root@localhost ~]# lvextend -l +30 /dev/data/ora
  Extending logical volume ora to 2.12 GB
  Logical volume ora successfully resized
– But space still same. Not updated /dev/mapper/data-ora
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             3.8G  3.1G  569M  85% /
sysfs                 3.8G  3.8G     0 100% /sys
/dev/sda5             4.0G  139M  3.6G   4% /home
/dev/sda1              46M   11M   33M  25% /boot
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.8G  3.8G     0 100% /sys
.host:/               196G   31G  165G  16% /mnt/hgfs
/dev/mapper/data-ora  2.0G   68M  1.9G   4% /data
– To do this run this command
[root@localhost ~]# rezsize2fs /dev/sdbdata/ora
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/data/ora is mounted on /data; on-line resizing required
Performing an on-line resize of /dev/data/ora to 555008 (4k) blocks.
The filesystem on /dev/data/ora is now 555008 blocks long.
– Now it’s show
[root@localhost ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             3.8G  3.1G  569M  85% /
sysfs                 3.8G  3.8G     0 100% /sys
/dev/sda5             4.0G  139M  3.6G   4% /home
/dev/sda1              46M   11M   33M  25% /boot
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.8G  3.8G     0 100% /sys
.host:/               196G   31G  165G  16% /mnt/hgfs
/dev/mapper/data-ora  2.1G   68M  2.0G   4% /data

Leave a Reply