Linux: Detect a new drive without rebooting
Sometimes we can run into a situation where we need to add a drive to a running virtual linux machine. There is a way to nudge linux to see the newly attached physical drive from the command line.
In the below path you can find a list of host symlinks pointing to the iscsi device configured on your Linux box
yourname@computername:~$ ls -l /sys/class/scsi_host/
total 0
lrwxrwxrwx 1 root root 0 Jun 15 08:30 host0 -> ../../devices/pci0000:00/0000:00:07.1/host0/scsi_host/host0
lrwxrwxrwx 1 root root 0 Jun 15 08:30 host1 -> ../../devices/pci0000:00/0000:00:07.1/host1/scsi_host/host1
lrwxrwxrwx 1 root root 0 Jun 15 08:30 host2 -> ../../devices/pci0000:00/0000:00:10.0/host2/scsi_host/host2
But to detect a new hard drive attached you need to first get your host bus number used which you can get by using below command
# grep mpt /sys/class/scsi_host/host?/proc_name
You should get a output like below
/sys/class/scsi_host/host2/proc_name:mptspi
So as you see your host2 is the relevant fiels where you need to reset the storage buffer values. Run the below command
# echo “- – -” > /sys/class/scsi_host/host2/scan
Here “- – -“ defines the three values stored inside host*/scan i.e. channel number, SCSI target ID, and LUN values. We are simply replacing the values with wild cards so that it can detect new changes attached to the Linux box. This procedure will add LUNs, but not remove them.
Once done verify if you can see the new hard drive which in my case worked very fine as I see below
# fdisk -l
Disk /dev/sdb: 26.8 GB, 26843545600 bytes
255 heads, 63 sectors/track, 3263 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Credit: D. Prasad