First getscsi Device information.
[[email protected] ~]# lsscsi [2:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda [
4:0:0:0] cd/dvd NECVMWar VMware SATA CD01 1.00 /dev/sr0
Some operating systems don'tlsscsi command, You can use the following method to getscsi Device information.
[[email protected] ~]# ll /sys/bus/scsi/drivers/sd/ total 0 lrwxrwxrwx 1 root root 0
Jun22 17:29 2:0:0:0 -> ../../../../devices/pci0000:00/0000:00:10.0
/host2/target2:0:0/2:0:0:0 --w------- 1 root root 4096 Jun 22 17:29 bind
--w-------1 root root 4096 Jun 22 2017 uevent --w------- 1 root root 4096 Jun 22
17:29 unbind [[email protected] ~]# ll /sys/bus/scsi/drivers/sd/2\:0\:0\:0/block/
total0 drwxr-xr-x 10 root root 0 Jun 22 2017 sda
Then look at it./proc/scsi/scsi file, Get correspondingscsi Device details.
[[email protected] ~]# cat /proc/scsi/scsi Attached devices: Host: scsi2 Channel:
00 Id: 00 Lun: 00 Vendor: VMware, Model: VMware Virtual S Rev: 1.0 Type: Direct
-Access ANSI SCSI revision:02 Host: scsi4 Channel: 00 Id: 00 Lun: 00 Vendor:
NECVMWar Model: VMware SATA CD01 Rev:1.00 Type: CD-ROM ANSI SCSI revision: 05
Host: scsi2 Channel: 00 Id: 01 Lun: 00 Vendor: VMware, Model: VMware Virtual S
Rev:1.0 Type: Direct-Access ANSI SCSI revision: 02

Here, There are two direct links(Direct-Access) Ofscsi disk, One through the optical drivecd-rom Connected disc. We only considerscsi disk, So these two disks arescsi The locators in are2:0:0:0 and2:0:1:0.
If you continue to insert a disk, So the new dish isscsi The locators in are2:0:2:0, This string is very important.

1.1 Hot plug


After inserting a disk into the computer, The kernel will not generate any event notifications because it cannot recognize it, So in/sys No files will be generated in the directory, No tool can read it. Rebooting the system can definitely be solved, howeverLinux Hot plug support.

The way to hot plug a new disk is to/proc/scsi/scsi Write new inscsi Device information. The way is as follows:
echo "scsi add-single-device a b c d" >/proc/scsi/scsi
among:

      a == hostadapter id (first one being 0)

      b == SCSI channel on hostadapter (first one being 0)

      c == ID

      d == LUN (first one being 0)

For example, the above example, The following information should be added:
[[email protected] ~]# echo "scsi add-single-device 2:0:2:0" >/proc/scsi/scsi
Of course, Re scanscsi The bus can also realize the function of hot plug. Because in the example above,scsi host
id by2( Namelyhost2), So what we're scanning ishost2, suchhost2 thisscsi All devices on will be rescanned.
[[email protected] ~]# echo "- - -" > /sys/class/scsi_host/host2/scan
If you don't know which one to scanhost, Direct use cycle full scan.
[[email protected] ~]# for i in /sys/class/scsi_host/host*/scan;do echo "- - -" >$i;
done
After hot insertion,fdisk -l Wait for the command to recognize the disk.

1.2 Hot drawing

The way to hot unplug a disk is to/proc/scsi/scsi Remove the correspondingscsi Device information. The way is as follows:
echo "scsi remove-single-device a b c d" >/proc/scsi/scsi
For example, delete2:0:2:0 This disk.
[[email protected] ~]# echo "scsi remove-single-device 2 0 2 0" >/proc/scsi/scsi
Because the device to be deleted already exists,/sys It has complete information in, So it is also deleted from its own device.

First look at it.scsi Device information.
[[email protected] ~]# lsscsi [2:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda [
2:0:1:0] disk VMware, VMware Virtual S 1.0 /dev/sdb [4:0:0:0] cd/dvd NECVMWar
VMware SATA CD011.00 /dev/sr0
  For example, to delete/dev/sdb, Namely2:0:1:0. First look at its file information.
[[email protected] ~]# ls /sys/bus/scsi/drivers/sd/2\:0\:1\:0/ block/
evt_lun_change_reported model scsi_level bsg/ evt_media_change power/ state
delete evt_mode_parameter_change_reported queue_depth subsystem/
device_blocked evt_soft_threshold_reached queue_ramp_up_period timeout
device_busy generic/ queue_type type dh_state iocounterbits rescan uevent driver
/ iodone_cnt rev unpriv_sgio eh_timeout ioerr_cnt scsi_device/ vendor
evt_capacity_change_reported iorequest_cnt scsi_disk/ vpd_pg80
evt_inquiry_change_reported modalias scsi_generic/ vpd_pg83

Among them3 File:delete,rescan andstate. amongstate It records whether the device is running. anddelete andrescan Files are used to delete and rescan the device.

for example, Delete this device, Hot draw.
[[email protected] ~]# echo 1 > /sys/bus/scsi/drivers/sd/2\:0\:1\:0/delete