[CentOS] [SOLVED] Rescan harddisk size without rebooting - LVM ext3-fs

kadafax kadafax at gmail.com
Tue Nov 15 15:07:16 UTC 2005


Hi list,
First thanks to Aleksandar M, William LM and Bryan JS.

How to reflect a scsi device size change without rebooting and benefit 
the extra space within logical volumes.

I started from over and first I've initially created partitions with 
fdisk (type 8e - linux lvm):
Below, the interesting devices are sdb and sdc who represents the two 
SAN's virtual disks, sda is the system HD using internal RAID adapter. 
sdb and sdc will grow respectively with a few hundred MB and 230GB.
---
[root at X ~]# fdisk -l

Disk /dev/sda: 146.6 GB, 146695782400 bytes
255 heads, 63 sectors/track, 17834 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14       17834   143147182+  8e  Linux LVM

Disk /dev/sdb: 933.0 GB, 933081645056 bytes
255 heads, 63 sectors/track, 113440 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

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

Disk /dev/sdc: 233.0 GB, 233001975808 bytes
255 heads, 63 sectors/track, 28327 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       28327   227536596   8e  Linux LVM
---
then I've created the pv:
---
[root at X ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
[root at X ~]# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created
---
then the vg:
---
[root at X ~]# vgcreate VG-B /dev/sdb1
  Volume group "VG-B" successfully created
[root at X ~]# vgcreate VG-C /dev/sdc1
  Volume group "VG-C" successfully created
---
then the lv with all the available physical extents:
---
[root at X ~]# vgdisplay VG-C | grep "Total PE"
  Total PE              55550
[root at X ~]# lvcreate -l 55550 VG-C -n LV-C
  Logical volume "LV-C" created
[root at X ~]# vgdisplay VG-B | grep "Total PE"
  Total PE              222462
[root at X ~]# lvcreate -l 222462 VG-B -n LV-B
  Logical volume "LV-B" created
---
# Note from the LVM How-To from tldp:
Each physical volume is divided chunks of data, known as physical 
extents, these extents have the same size as the logical extents for the 
volume group.
Each logical volume is split into chunks of data, known as logical 
extents. The extent size is the same for all logical volumes in the 
volume group.
---
[root at X ~]# pvscan
  PV /dev/sdc1   VG VG-C       lvm2 [216.99 GB / 0    free]
  PV /dev/sdb1   VG VG-B     lvm2 [868.99 GB / 0    free]
  ...
  Total: 3 [1.19 TB] / in use: 3 [1.19 TB] / in no VG: 0 [0   ]
---

Now I've added a 250GB HD to the pool in the SAN. The goal is to extend 
the size of the Logical Volumes LV-C and LV-B respectively sourced with 
the devices /dev/sdb and /dev/sdc.

First reflect the new size to the system by unloading then loading the 
qla module:
---
[root at X ~]# /sbin/rmmod qla6312
[root at X ~]# /sbin/modprobe qla6312
---
[root at X ~]# fdisk -l

...
Disk /dev/sdd: 933.3 GB, 933355323392 bytes
255 heads, 63 sectors/track, 113473 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1      113440   911206768+  8e  Linux LVM

Disk /dev/sde: 467.0 GB, 467077693440 bytes
255 heads, 63 sectors/track, 56785 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1       28327   227536596   8e  Linux LVM
---
The new size is correctly reported BUT the drives assignments has 
shifted: sdb --> sdd and sdc --> sde. I don't know how to avoid this.
Hopefully, the physical volume mechanism has followed the shift:
---
[root at X ~]# pvscan
  PV /dev/sde1   VG VG-C       lvm2 [216.99 GB / 0    free]
  PV /dev/sdd1   VG VG-B     lvm2 [868.99 GB / 0    free]
  ...
  Total: 3 [1.19 TB] / in use: 3 [1.19 TB] / in no VG: 0 [0   ]
---
then after the creation of the new partitions (type 8e) supplied with 
the additional space available:
---
[root at X ~]# fdisk -l

...
Disk /dev/sdd: 933.3 GB, 933355323392 bytes
255 heads, 63 sectors/track, 113473 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1      113440   911206768+  8e  Linux LVM
/dev/sdd2          113441      113473      265072+  8e  Linux LVM

Disk /dev/sde: 467.0 GB, 467077693440 bytes
255 heads, 63 sectors/track, 56785 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1       28327   227536596   8e  Linux LVM
/dev/sde2           28328       56785   228588885   8e  Linux LVM
---
go for the lvm stuff.
first the pv:
---
[root at X ~]# pvcreate /dev/sdd2
  Physical volume "/dev/sdd2" successfully created
[root at X ~]# pvcreate /dev/sde2
  Physical volume "/dev/sde2" successfully created
---
then add it to the vg:
---
[root at X ~]# vgextend VG-B /dev/sdd2
  Volume group "VG-B" successfully extended
[root at X ~]# vgextend VG-C /dev/sde2
  Volume group "VG-C" successfully extended
[root at X ~]# pvscan
  PV /dev/sde1   VG VG-C       lvm2 [216.99 GB / 0    free]
  PV /dev/sde2   VG VG-C       lvm2 [218.00 GB / 218.00 GB free]
  PV /dev/sdd1   VG VG-B     lvm2 [868.99 GB / 0    free]
  PV /dev/sdd2   VG VG-B     lvm2 [256.00 MB / 256.00 MB free]
  ...
  Total: 5 [1.41 TB] / in use: 5 [1.41 TB] / in no VG: 0 [0   ]
---
finally the lv:
---
[root at X ~]# vgdisplay VG-B | grep "Free  PE"
  Free  PE / Size       64 / 256.00 MB
[root at X ~]# lvextend -l+64 /dev/VG-B/LV-B
  Extending logical volume LV-B to 869.24 GB
  Logical volume LV-B successfully resized

[root at X ~]# vgdisplay VG-C | grep "Free  PE"
  Free  PE / Size       55807 / 218.00 GB
[root at X ~]# lvextend -l+55807 /dev/VG-C/LV-C
  Extending logical volume LV-C to 434.99 GB
  Logical volume LV-C successfully resized
---
[root at X ~]# lvscan
  ACTIVE            '/dev/VG-C/LV-C' [434.99 GB] inherit
  ACTIVE            '/dev/VG-B/LV-B' [869.24 GB] inherit
---
The lv have grown, now it's the turn of the ext3-fs:
---
[root at X ~]# resize2fs /dev/VG-B/LV-B
resize2fs 1.35 (28-Feb-2004)
Resizing the filesystem on /dev/VG-B/LV-B to 227866624 (4k) blocks.
The filesystem on /dev/VG-B/LV-B is now 227866624 blocks long.

[root at X ~]# resize2fs /dev/VG-C/LV-C
resize2fs 1.35 (28-Feb-2004)
Resizing the filesystem on /dev/VG-C/LV-C to 114029568 (4k) blocks.
The filesystem on /dev/VG-C/LV-C is now 114029568 blocks long.
---
 From here I can mount and work with the volumes.
---
[root at X ~]# df -h
...
/dev/mapper/VG--C-LV--C
                      429G  103M  407G   1% /mount/pointC
/dev/mapper/VG--B-LV--B
                      856G  104M  821G   1% /mount/pointB
---


Note: I haven't done this with mounted volume. However it's seem 
possible to do so but I won't risk it for now.
         After a reboot, activating the volume group with "vgchange -a y 
VG-name" may be necessary.


Now some fun with the 'pvresize' command:
---
[root at X ~]# pvresize
  Command not implemented yet.
---

kfx.









More information about the CentOS mailing list