extend the / partition using lvm on oel6

purpose:using lvm to extend the / partition on oel 6

this picture explain the architecture of LVM in linux,you can see it clearly:
LVM示意图

[root@pig1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_pig1-lv_root
                       19G   15G  3.4G  81% /
tmpfs                 2.0G  200M  1.8G  11% /dev/shm
/dev/sda1             485M   52M  408M  12% /boot

//there are a empty disk “/dev/sdf” size 32G

[root@pig1 ~]# fdisk -l

Disk /dev/sdf: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x00000000

Disk /dev/sdf doesn't contain a valid partition table

about the pv,vg,lv

pv is same as the raw disk,vg is the pool full of pv.OS can not use the vg directly.
os can use the lv which split from vg pool.

//show pv info

[root@pig1 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_pig1
  PV Size               24.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              6274
  Free PE               0
  Allocated PE          6274
  PV UUID               1gLQ8y-6bPU-kMBS-mCN6-po4G-cnS9-0ZTAKK

vg info

[root@pig1 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_pig1
  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               24.51 GiB
  PE Size               4.00 MiB
  Total PE              6274
  Alloc PE / Size       6274 / 24.51 GiB
  Free  PE / Size       0 / 0   
  VG UUID               LPp5ch-F8rX-FbWc-Sww8-ftZ8-ZVKD-cMo3O7

the existing vg named vg_pig1

//lv info

[root@pig1 ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg_pig1/lv_root
  VG Name                vg_pig1
  LV UUID                f32bui-fkqS-XlWq-wils-Jamq-CmUk-H7Bp1v
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                18.63 GiB
  Current LE             4770
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Name                /dev/vg_pig1/lv_swap
  VG Name                vg_pig1
  LV UUID                RmPLiQ-Bwzk-BVlh-goI6-Bsyq-Gceu-TmzqYx
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                5.88 GiB
  Current LE             1504
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
[root@pig1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_pig1-lv_root
                       19G   15G  3.0G  84% /
tmpfs                 2.0G  200M  1.8G  11% /dev/shm
/dev/sda1             485M   52M  408M  12% /boot

try to extend the vg and the lv

1.create pv

the new allocated disk is /dev/sdf

[root@pig1 ~]# pvcreate /dev/sdf
  Writing physical volume data to disk "/dev/sdf"
  Physical volume "/dev/sdf" successfully created

[root@pig1 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_pig1
  PV Size               24.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              6274
  Free PE               0
  Allocated PE          6274
  PV UUID               1gLQ8y-6bPU-kMBS-mCN6-po4G-cnS9-0ZTAKK
   
  "/dev/sdf" is a new physical volume of "30.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdf
  VG Name               
  PV Size               30.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               dlGqpd-Yqop-7ZvK-gcrJ-q0K7-SwSj-wjGCah

you can see the new created pv named /dev/sdf size in 30G

2.extend the vg

[root@pig1 ~]# vgextend vg_pig1 /dev/sdf
  Volume group "vg_pig1" successfully extended

the vg was 24.5G original,after extending,it becomes 54.5G

[root@pig1 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_pig1
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               54.50 GiB
  PE Size               4.00 MiB
  Total PE              13953
  Alloc PE / Size       6274 / 24.51 GiB
  Free  PE / Size       7679 / 30.00 GiB
  VG UUID               LPp5ch-F8rX-FbWc-Sww8-ftZ8-ZVKD-cMo3O7

3.extend the lv
extend the lv named /dev/vg_pig1/lv_root

[root@pig1 ~]# lvextend -L +25G /dev/vg_pig1/lv_root
  Extending logical volume lv_root to 43.63 GiB
  Logical volume lv_root successfully resized

//check the information of lv,the lv /dev/vg_pig1/lv_root has extended to 43.63G

[root@pig1 ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg_pig1/lv_root
  VG Name                vg_pig1
  LV UUID                f32bui-fkqS-XlWq-wils-Jamq-CmUk-H7Bp1v
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                43.63 GiB
  Current LE             11170
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Name                /dev/vg_pig1/lv_swap
  VG Name                vg_pig1
  LV UUID                RmPLiQ-Bwzk-BVlh-goI6-Bsyq-Gceu-TmzqYx
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                5.88 GiB
  Current LE             1504
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

although lv has been extended,but you still need to resize the filesystem to sync the change

[root@pig1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_pig1-lv_root
                       19G   15G  3.0G  84% /
tmpfs                 2.0G  200M  1.8G  11% /dev/shm
/dev/sda1             485M   52M  408M  12% /boot

use the resize2fs to sync the change to the filesystem

[root@pig1 ~]# resize2fs /dev/mapper/vg_pig1-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_pig1-lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 3
Performing an on-line resize of /dev/mapper/vg_pig1-lv_root to 11438080 (4k) blocks.
The filesystem on /dev/mapper/vg_pig1-lv_root is now 11438080 blocks long.

check out the partition information and you will find the / was extended

[root@pig1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_pig1-lv_root
                       43G   15G   27G  36% /
tmpfs                 2.0G  200M  1.8G  11% /dev/shm
/dev/sda1             485M   52M  408M  12% /boot

–EOF–