First get the SCSI device information.
[[Email protected] ~]# lsscsi[2:0:0:0] Disk VMware, 1.0 /dev/sda[4:0:0:0] CD/DVD 1.00 /dev/sr0
Some operating systems do not have LSSCSI commands, you can use the following methods to obtain SCSI device information.
[Email protected] ~]# ll/sys/bus/scsi/drivers/sd/ Total0lrwxrwxrwx1Root root0June A -: in 2:0:0:0.. /.. /.. /.. /devices/pci0000:xx/0000:xx:10.0/host2/target2:0:0/2:0:0:0--w-------1Root root4096June A -: inBind--w-------1Root root4096June A .uevent--w-------1Root root4096June A -: inUnbind
[[email protected] ~]# ll/sys/bus/scsi/drivers/sd/2\:0\:0\:0/block/ 0 drwxr Ten 0 a SDA
Then view the/proc/scsi/scsi file for more information about the SCSI device.
[Email protected] ~]# cat/proc/scsi/scsiattached Devices:host:scsi2 Channel: xx id:00 lun:00Vendor:vmware, Model:vmware Virtual S Rev:1.0Type:direct-access ANSI SCSI Revision: Genevahost:scsi4 channel:00 id:00 lun:00Vendor:necvmwar model:vmware SATA CD01 Rev:1.00TYPE:CD-rom ANSI SCSI Revision: tohost:scsi2 channel:00 id:01 lun:00Vendor:vmware, Model:vmware Virtual S Rev:1.0Type:direct-access ANSI SCSI Revision: Geneva
Here, there are two direct-attached (direct-access) SCSI disks, a disc attached to the CD-ROM. We only consider SCSI disks, so the two disk locators in SCSI are 2:0:0:0 and 2:0:1:0. If you continue to insert a disk, then the new disk in the SCSI locator is 2:0:2:0, this value string is very important.
1.1 Hot Plug
After inserting a disk into a computer, the kernel does not generate any event notifications because it cannot recognize it, so no files are generated in the/sys directory and no tools can read it. Rebooting the system is sure to work, but Linux supports hot plug.
The way to hot-plug a new disk is to write information about the new SCSI device to the/PROC/SCSI/SCSI. Here's how:
Echo " SCSI Add-single-device a b c D " >/PROC/SCSI/SCSI
which
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 above, you should add the following information:
Echo " SCSI Add-single-device 2:0:2:0 " >/PROC/SCSI/SCSI
Of course, re-scanning the SCSI bus can also achieve the function of hot plug. Because of the above example, the SCSI host ID is 2 (that is, host2), so the scan is host2 so that all the devices on this SCSI host2 will be re-scanned.
Echo " - - - " >/sys/class/scsi_host/host2/scan
If you do not know which host to scan, use the loop all scan directly.
for in 'ls /sys/class/scsi_host/'; Do Echo " - - - " >/sys/class/scsi_host/$i/scan; Done
After hot-plugging, the disk can be identified by commands such as Fdisk-l.
1.2 Hot-drawn
The way to hot-unplug a disk is to remove the information for the SCSI device in the/PROC/SCSI/SCSI. Here's how:
Echo " SCSI Remove-single-device a b c D " >/PROC/SCSI/SCSI
For example, delete the 2:0:2:0 disk.
Echo " SCSI Remove-single-device 2 0 2 0 " >/PROC/SCSI/SCSI
Because the device to be removed already exists, the/sys already has its complete information, so it is also deleted from its own device.
First look at the SCSI device information.
[[Email protected] ~]# lsscsi[2:0:0:0] Disk VMware, 1.0 /dev/sda[2:0:1:0] Disk VMware, 1.0 /dev/sdb[4:0:0:0] CD/DVD 1.00 /dev/sr0
For example, to remove/dev/sdb, that is, 2:0:1:0. Take a look at its file information first.
[Email protected] ~]#ls/sys/bus/scsi/drivers/sd/2\:0\:1\:0/Block/evt_lun_change_reported Model scsi_levelbsg/Evt_media_change power/State Delete Evt_mode_paramet er_change_reported queue_depth Subsystem/device_blocked evt_soft_threshold_reached queue_ramp_up_period Timeoutdev Ice_busy Generic/Queue_type typedh_state iocounterbits rescan ueventdriver/iodone_cnt Rev Unpriv_sgioeh_tim Eout ioerr_cnt Scsi_device/vendorevt_capacity_change_reported iorequest_cnt Scsi_disk/vpd_pg80evt_inquiry_change_reported Modalias Scsi_generic /vpd_pg83
There are 3 files in it: Delete, rescan, and state. Where state records whether the device is running. The delete and rescan files are used to delete and rescan the device.
For example, remove the device, which is hot-swappable.
Echo 1 >/sys/bus/scsi/drivers/sd/2\:0\:1\:0/delete
Back to series article outline:http://www.cnblogs.com/f-ck-need-u/p/7048359.html
Reprint Please specify source:http://www.cnblogs.com/f-ck-need-u/p/7067006.html
Disk Hot swap on Linux