====== Intro ====== I found some valuable Linux specific hotswap stuff today for working with hot-swappable SCSI disks. This should be pretty distro agnostic as well. I've been using FreeBSD, where you use camcontrol/atacontrol, for so long now that I had kind of forgotten how to do this stuff in Linux. Now it's time to make a record. ====== Checking What is Currently in the System ====== Good ol' linux and it's ''proc'' pseudo-filesystem. Essentially, all we are doing is checking a file and echoing commands into the same file for all our operations. The magic file here is **''/proc/scsi/scsi''**. First let's see what's in our file. You should see something like the following, but obviously it will differ depending on hardware. # cat /proc/scsi/scsi vnb1:~ # cat /proc/scsi/scsi Attached devices: Host: scsi0 Channel: 00 Id: 00 Lun: 00 Vendor: FUJITSU Model: MAT3073NC Rev: 0104 Type: Direct-Access ANSI SCSI revision: 03 Host: scsi0 Channel: 00 Id: 01 Lun: 00 Vendor: SEAGATE Model: ST373207LC Rev: 0002 Type: Direct-Access ANSI SCSI revision: 03 Host: scsi0 Channel: 00 Id: 06 Lun: 00 Vendor: SDR Model: GEM318P Rev: 1 Type: Processor ANSI SCSI revision: 02 Host: scsi1 Channel: 00 Id: 02 Lun: 00 Vendor: QUANTUM Model: SDLT320 Rev: 5252 Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi2 Channel: 00 Id: 00 Lun: 00 Vendor: ATL Model: M2500 Rev: 12.0 Type: Medium Changer ANSI SCSI revision: 02 Host: scsi2 Channel: 00 Id: 01 Lun: 00 Vendor: QUANTUM Model: SDLT320 Rev: 5252 Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi3 Channel: 00 Id: 00 Lun: 00 Vendor: NETAPP Model: VTL Rev: 0001 Type: Medium Changer ANSI SCSI revision: 02 Host: scsi3 Channel: 00 Id: 00 Lun: 01 Vendor: QUANTUM Model: SDLT320 Rev: 022C Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi3 Channel: 00 Id: 00 Lun: 02 Vendor: QUANTUM Model: SDLT320 Rev: 022C Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi3 Channel: 00 Id: 00 Lun: 03 Vendor: QUANTUM Model: SDLT320 Rev: 022C Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi3 Channel: 00 Id: 00 Lun: 04 Vendor: QUANTUM Model: SDLT320 Rev: 022C Type: Sequential-Access ANSI SCSI revision: 02 ====== Removing a Device ====== Now, first I want to remove the first device since it failed. Then we will see that it no longer shows up. # echo 'scsi remove-single-device 0 0 0 0' > /proc/scsi/scsi # cat /proc/scsi/scsi Attached devices: Host: scsi0 Channel: 00 Id: 01 Lun: 00 Vendor: SEAGATE Model: ST373207LC Rev: 0002 Type: Direct-Access ANSI SCSI revision: 03 Host: scsi0 Channel: 00 Id: 06 Lun: 00 Vendor: SDR Model: GEM318P Rev: 1 Type: Processor ANSI SCSI revision: 02 Host: scsi1 Channel: 00 Id: 02 Lun: 00 Vendor: QUANTUM Model: SDLT320 Rev: 5252 Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi2 Channel: 00 Id: 00 Lun: 00 Vendor: ATL Model: M2500 Rev: 12.0 Type: Medium Changer ANSI SCSI revision: 02 Host: scsi2 Channel: 00 Id: 01 Lun: 00 Vendor: QUANTUM Model: SDLT320 Rev: 5252 Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi3 Channel: 00 Id: 00 Lun: 00 Vendor: NETAPP Model: VTL Rev: 0001 Type: Medium Changer ANSI SCSI revision: 02 Host: scsi3 Channel: 00 Id: 00 Lun: 01 Vendor: QUANTUM Model: SDLT320 Rev: 022C Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi3 Channel: 00 Id: 00 Lun: 02 Vendor: QUANTUM Model: SDLT320 Rev: 022C Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi3 Channel: 00 Id: 00 Lun: 03 Vendor: QUANTUM Model: SDLT320 Rev: 022C Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi3 Channel: 00 Id: 00 Lun: 04 Vendor: QUANTUM Model: SDLT320 Rev: 022C Type: Sequential-Access ANSI SCSI revision: 02 Now, a quick explanation of the device address. The "0 0 0 0" used in the ''remove-single-device'' command above is the SCSI address of the first drive. The address translates as follows: ^ First zero | Host: scsi0 | ^ Second zero | Channel: 00 | ^ Third zero | Id: 00 | ^ Fourth zero | Lun: 00 | So, if we wanted to remove the second drive instead of the first (the Seagate), the address would be "0 0 1 0". ====== Add the New Device ====== **NOTE:** The following process can be used to just simply add a disk to the system. Now we can add the new drive that we swapped in. We use the same addressing scheme as above. After the add, we should see it in the ''/proc/scsi/scsi'' file again. # echo 'scsi add-single-device 0 0 0 0' > /proc/scsi/scsi # cat /proc/scsi/scsi Attached devices: Host: scsi0 Channel: 00 Id: 01 Lun: 00 Vendor: SEAGATE Model: ST373207LC Rev: 0002 Type: Direct-Access ANSI SCSI revision: 03 Host: scsi0 Channel: 00 Id: 06 Lun: 00 Vendor: SDR Model: GEM318P Rev: 1 Type: Processor ANSI SCSI revision: 02 Host: scsi1 Channel: 00 Id: 02 Lun: 00 Vendor: QUANTUM Model: SDLT320 Rev: 5252 Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi2 Channel: 00 Id: 00 Lun: 00 Vendor: ATL Model: M2500 Rev: 12.0 Type: Medium Changer ANSI SCSI revision: 02 Host: scsi2 Channel: 00 Id: 01 Lun: 00 Vendor: QUANTUM Model: SDLT320 Rev: 5252 Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi3 Channel: 00 Id: 00 Lun: 00 Vendor: NETAPP Model: VTL Rev: 0001 Type: Medium Changer ANSI SCSI revision: 02 Host: scsi3 Channel: 00 Id: 00 Lun: 01 Vendor: QUANTUM Model: SDLT320 Rev: 022C Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi3 Channel: 00 Id: 00 Lun: 02 Vendor: QUANTUM Model: SDLT320 Rev: 022C Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi3 Channel: 00 Id: 00 Lun: 03 Vendor: QUANTUM Model: SDLT320 Rev: 022C Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi3 Channel: 00 Id: 00 Lun: 04 Vendor: QUANTUM Model: SDLT320 Rev: 022C Type: Sequential-Access ANSI SCSI revision: 02 Host: scsi0 Channel: 00 Id: 00 Lun: 00 Vendor: FUJITSU Model: MAT3073NC Rev: 0104 Type: Direct-Access ANSI SCSI revision: 03 Now, checking ''dmesg'', we should see what device the new drive was assigned to: # dmesg | tail sdc: Spinning up disk..........ready SCSI device sdc: 143638992 512-byte hdwr sectors (73543 MB) SCSI device sdc: drive cache: write back SCSI device sdc: 143638992 512-byte hdwr sectors (73543 MB) SCSI device sdc: drive cache: write back sdc: sdc1 sdc2 Now you can use your disk: ''/dev/sdc''. ====== Scan for New Devices ====== You can also use the following to scan the SCSI bus for new devices: # echo 'scsi scan-new-devices' > /proc/scsi/scsi