Using the Command camcontrol to Find Information and Dynamically Add/Remove SCSI Devices

Posted January 19, 2004 by Michilimackinac in FreeBSD

The command camcontrol is a very useful for finding information and for adding and removing SCSI devices.


To find what CAM SCSI busses exist and what devices are connected to them, use the following:



# camcontrol devlist
at scbus0 target 0 lun 0 (pass0,da0)
at scbus1 target 3 lun 0 (pass1,sa0)
at scbus1 target 6 lun 0 (pass2,cd0)
#

Notice that the USB bus on my system is considered a CAM SCSI bus.
I have two busses here. Bus 0 (USB) has a compact flash reader on it at target 0.
Bus 1 (SCSI) has a tape drive (sequential access device: sa0) at target 3 and a cdrom drive (cd0) at target 6.

Let’s say that we want to temporarily take the tape drive off without rebooting the system and go backup another system. Since we only have a tape drive and
a cdrom drive, this is pretty safe (Disk drives with mounted filesystems would be
a different story.). What we can do is shut off the power to the tape drive and
the cdrom drive and then run a “camcontrol rescan [busnumber]” to rescan the bus.
In this case, the bus I want to rescan is bus 1:



# camcontrol rescan 1
Re-scan of bus 1 was successful
#

In the messages file, you should see some entries like the following logging the
removal of the devices (The ahc0 denotes an Adaptec 2940.):



Jan 19 18:23:02 moonpalace /kernel: (sa0:ahc0:0:3:0): lost device
Jan 19 18:23:02 moonpalace /kernel: (sa0:ahc0:0:3:0): removing device entry
Jan 19 18:23:02 moonpalace /kernel: (cd0:ahc0:0:6:0): lost device
Jan 19 18:23:02 moonpalace /kernel: (cd0:ahc0:0:6:0): removing device entry

Also notice, if we do a devlist again, we only see the USB bus:



# camcontrol devlist
at scbus0 target 0 lun 0 (pass0,da0)
#

Since I am not adding them to a different system, I will turn the power back on to the
devices and run “camcontrol rescan [busnumber]” again:



# camcontrol rescan 1
Re-scan of bus 1 was successful
#

In the messages file, again we show that the devices are back:



Jan 19 18:31:52 moonpalace /kernel: cd0 at ahc0 bus 0 target 6 lun 0
Jan 19 18:31:52 moonpalace /kernel: cd0: Removable CD-ROM SCSI-2 device
Jan 19 18:31:52 moonpalace /kernel: cd0: 5.000MB/s transfers (5.000MHz, offset 15)
Jan 19 18:31:52 moonpalace /kernel: cd0: Attempt to query device size failed: NOT READY, Medium not present
Jan 19 18:31:52 moonpalace /kernel: sa0 at ahc0 bus 0 target 3 lun 0
Jan 19 18:31:52 moonpalace /kernel: sa0: Removable Sequential Access SCSI-2 device
Jan 19 18:31:52 moonpalace /kernel: sa0: 5.000MB/s transfers (5.000MHz, offset 11)

A devlist also shows that everything is back:



# camcontrol devlist
at scbus0 target 0 lun 0 (pass0,da0)
at scbus1 target 3 lun 0 (pass1,sa0)
at scbus1 target 6 lun 0 (pass2,cd0)
#

The Conversation

Follow the reactions below and share your own thoughts.