Short tip: Online update hard drive sizes under Linux

When hard drive sizes are altered the Linux kernel isn't informed about these changes automatically. Rebooting the system is a possible solution - but often no option.

Beneath the directory /sys/class/scsi_disk you will find additional files controlling some of the device's function depending on the SCSI id. Using the file device/rescan it is possible to schedule re-reading the device information. In this case the kernel will be informed about the new hard drive size. In combination with LVM it is quite easy to serve additional storage:

 1# echo '1' > /sys/class/scsi_disk/`lsscsi|grep sdb|cut -d" " -f 1|sed -e 's/[//g;s/]//g'`/device/rescan
 2
 3# dmesg
 4...
 5ata2: EH complete
 6sd 3:0:0:0: [sdb] 167772160 512-byte logical blocks: (85.8 GB/80.0 GiB)
 7sd 3:0:0:0: [sdb] Cache data unavailable
 8sd 3:0:0:0: [sdb] Assuming drive cache: write through
 9sdb: detected capacity change from 64424509440 to 85899345920
10
11# pvresize /dev/sdb
12  Physical volume "/dev/sdb" changed
13  1 physical volume(s) resized / 0 physical volume(s) not resized
14...

When using SAN systems with multiple paths (multipath) you can save the echo step above:

 1# multipath -l myvol
 2Jun 18 09:40:00 | multipath.conf line 33, invalid keyword: prio_callout
 3myvol (xxxxxxxxxxxxxxxxxxx0000000000032a) dm-8 IBM,2145
 4size=600G features='1 queue_if_no_path' hwhandler='0' wp=rw
 5`-+- policy='round-robin 0' prio=0 status=active
 6  |- 1:0:0:5 sdg  8:96   active undef running
 7  |- 2:0:0:5 sdw  65:96  active undef running
 8  |- 1:0:1:5 sdo  8:224  active undef running
 9  `- 2:0:1:5 sdae 65:224 active undef running
10# multipathd -k"resize map myvol"
11ok
12# multipath -l myvol|grep G
13size=800G features='1 queue_if_no_path' hwhandler='0' wp=rw

myvol needs to be replaced with the volume name taken from the configuration file /etc/multipath.conf. In this example the LUN size was increased from 600 GB to 800 GB.

Translations: