Add a new hard disk without rebooting in Linux

Having added a virtual hard drive to a virtual machine, the fdisk -cul command doesn't reveal any new drives.  There are a few ways to get Linux to recognize this new drive without having to reboot the computer.

A tried and true method that I have used on many occasions is this approach.  The problem with this approach is that I really don't know how many hosts there are, I simply run three commands and hope that the new drive will be found.  This typically works on systems with only a couple of drives and is relatively easy to remember.

echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "- - -" > /sys/class/scsi_host/host2/scan

Another approach I have found; however, admittedly never really used is this approach as there is too much to remember.

for host in $(ls /sys/class/scsi_host/);do
 echo "- - -" > /sys/class/scsi_host/${host}/scan
 done

A way to scan the one host without guessing is using this command.

grep mpt /sys/class/scsi_host/host?/proc_name

The result of that command will provide the host of the new drive.

/sys/class/scsi_host/host2/proc_name:mptspi

In this case, we have identified host2.

echo "- - -" > /sys/class/scsi_host/host2/scan

While that is a really cool approach, there is another.

yum install sg3_utils
rescan-scsi-bus.sh -a

rescan-scsi-bus

Notice that 1 new or changed device(s) found.

Using fdisk supports the conclusion that the new drive was added.

fdisk -cul | grep "Disk /dev"
Disk /dev/sda: 3221 MB, 3221225472 bytes
Disk /dev/sdb: 3221 MB, 3221225472 bytes

 

Source(s)

http://karngusain.blogspot.com/search?q=/class/scsi_host
http://www.golinuxhub.com/2014/07/how-to-detect-new-hard-disk-attached.html