Extend iSCSI (Physical) Disk when using LVM


Here is a little how to on how to extend your physical disk when used as a LVM partition.
This setup was used in combination with an iSCSI connector where a SAN slice can be resized upon request.
The best practice in the matter would be to NOT create a partition on it before assigning it to a LVM group.

Lets say your sdb disk is 2 Gb in size and you want to increase that to 3 Gb.
On your storage device , increase the number to your needs and reboot the server it is allocated to.
( A rescan or restart of the iSCSI adapter / driver , results in a new device with the correct new size, but this is not what we want. )

Now lets check our newly assign space.


[root@db01 bin]# fdisk -l

Disk /dev/sdb: 3221 MB, 3221225472 bytes
100 heads, 62 sectors/track, 1014 cylinders
Units = cylinders of 6200 * 512 = 3174400 bytes

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

As we can see , the size is increased as wanted on the sdb ( same device )
Now we need our Volume group to recognize this newly assign space.

[root@db01 bin]# lvm
lvm> pvscan
PV /dev/oracle VG vg_ora lvm2 [2.00 GB / 1.51 GB free]
PV /dev/sda5 VG VolGroup00 lvm2 [134.06 GB / 0 free]
Total: 2 [136.06 GB] / in use: 2 [136.06 GB] / in no VG: 0 [0 ]

lvm> pvresize /dev/oracle
Physical volume "/dev/oracle" changed
1 physical volume(s) resized / 0 physical volume(s) not resized

lvm> pvscan
PV /dev/oracle VG vg_ora lvm2 [3.00 GB / 2.51 GB free]
PV /dev/sda5 VG VolGroup00 lvm2 [134.06 GB / 0 free]
Total: 2 [137.06 GB] / in use: 2 [137.06 GB] / in no VG: 0 [0 ]

lvm> exit
Exiting.

Now that the group is updated with the new size , you might find your Volume Group to have disappeared from your device list.
So in our case , no vg_ora device is found under /dev which prevent us from using the underlining Logical Volumes.
To recreate this device in order to be able to mount the Logical Volume later , you have to de-activate and activate the Volume Group.

[root@db01 bin]#lvm
lvm> vgchange -an vg_ora
0 logical volume(s) in volume group "vg_ora" now active
lvm> vgchange -ay vg_ora
1 logical volume(s) in volume group "vg_ora" now active
lvm> exit
Exiting.

Now you will be able to use this new space by extending your logical volume , in our case the lv_oradata01

root@db01 dev]# lvm
lvm> lvresize -L+2G /dev/vg_ora/lv_oradata01
Extending logical volume lv_oradata01 to 2.49 GB
Logical volume lv_oradata01 successfully resized
lvm> exit
Exiting.

Now we are ready to mount and see the result.

[root@db01 dev]# mount /dev/vg_ora/lv_oradata01 /oradata01/
[root@db01 dev]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 125G 2.8G 116G 3% /
/dev/sda2 99M 12M 82M 13% /boot
tmpfs 8.0G 0 8.0G 0% /dev/shm
/dev/mapper/vg_ora-lv_oradata01
485M 11M 449M 3% /oradata01

As you can see the partition is mounted but still the extra size is now usable.
In order to make this size usable , we still need to extend our Logical Volume partition by resizing the partition.


[root@db01 dev]# resize2fs /dev/vg_ora/lv_oradata01
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/vg_ora/lv_oradata01 is mounted on /oradata01; on-line resizing required
Performing an on-line resize of /dev/vg_ora/lv_oradata01 to 2609152 (1k) blocks.
The filesystem on /dev/vg_ora/lv_oradata01 is now 2609152 blocks long.

Now lets check again


[root@db01 dev]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sdb 125G 2.8G 116G 3% /
/dev/sda3 99M 12M 82M 13% /boot
tmpfs 8.0G 0 8.0G 0% /dev/shm
/dev/mapper/vg_ora-lv_oradata01
3.0G 11M 2.7G 1% /oradata01

Voila !