2015-10-05

Rescanning for drive changes in CentOS and Ubuntu

As we now move to a world where most things are virutalized, I've found it repeatedly useful to change the size of a Virtual Hard Drive in VMWare and have it show up in the Virtualized OS as the updated size. I've also found that Ubuntu does this slightly differently than CentOS... but in either case it works:

Ubuntu

$ echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan

CentOS

$ echo "1" > /sys/bus/scsi/devices/2\:0\:0\:0/rescan 

Either way, they'll both give you some great data in the dmesg log:
$ dmesg|tail
sd 2:0:0:0: [sda] 157286400 512-byte logical blocks: (80.5 GB/75.0 GiB)
sd 2:0:0:0: [sda] Cache data unavailable
sd 2:0:0:0: [sda] Assuming drive cache: write through
sda: detected capacity change from 26843545600 to 80530636800

You'll want to make sure you have partprobe installed. It seems to come with the default Ubuntu Install on v14.04+... in CentOS you'll have to "yum install parted" to get it. Simply make your fdisk changes and then run partprobe /dev/, in the above case, /dev/sda.

Happy Re-Scanning!