Langue: en

Version: 51995 (openSuse - 09/10/07)

Section: 8 (Commandes administrateur)


sgdiag - Do Diagnostic functions on SCSI devices


sgdiag [-aentx]


Sgdiag is a program that uses the SCSI Generic interface to send specific SCSI commands to specified SCSI devices. The SCSI Generic interface requires that the kernel .config file have CONFIG_CHR_DEV_SG set.

A log file, named sgdiag.log is created in the /var/log directory which logs the status of the functions and any errors.

Several different functions can be performed with this utility.

c = Compose Command to send
This function allows the user to compose a custom SCSI command to send to one or more devices. It prompts the user for the command length, each command byte, the write data length, each write data byte, and the receive data length.
r = Reset SCSI bus
This function will send a bus reset signal to the SCSI bus of the selected device. This may be useful to free up a hung device.
i = Special Ser# Inquiries
This issues several special SCSI inquiry to obtain the serial number of the device. Normally this is not needed, since the serial number of most modern devices is included in the standard inquiry.
f = Format SCSI disk
This function issues a low-level SCSI format command to the selected device. This will remap any media defects as it formats the disk. Of course, it will erase any data on the selected disk.
w = Wipe SCSI disk
This function issues a low-level SCSI format command to the selected device. This will NOT include the previous grown defect list. This may be useful in testing to cause a disk to expose some media defects. This is dangerous and should not be used on production systems.
d = Send Diagnostic self-test
This function issues a SCSI Send Diagnostic self-test command to the selected device. The device returns a sense error if the self-test does not succeed.
s = Start Unit
This function issues a SCSI Start Unit command. Some disk drives may not be configured to automatically start after power up. A reported sense of 02-04-02 indicates that this command is needed.
t = Stop Unit
This function issues a SCSI Stop Unit command. This might be used in testing to simulate a device failure.
1 = Do bug 1 (sense_len = 18)
The standard sg structure only defines 16 bytes of sense data, whereas 18 bytes are needed to parse some illegal request sense keys. This function attempts to request 18 bytes of sense data from the standard sg structure, which should cause a 5/24/00 sense error, but should not cause the driver or the utility to hang or stop working.
2 = Do bug 2 (INQ hang)
In versions of the old adaptec driver that were delivered with RedHat 6.2, this function will hang the driver by requesting a receive buffer less than 96 bytes. Newer versions of the driver should handle this function without error (status = 0).
3 = Do bug 3 (format w short timeout)
A SCSI format command can take several minutes to complete. If the SCSI timeout is set too short, it should cause several retries, followed by marking the SCSI device offline. The device should return to normal after a reboot.


Command line options are described below.
This option displays a summary of the commands accepted by sgdiag
Automatically send command for all devices. If this option is specified, a default illegal SCSI LOG_SENSE command will be sent to each device.
Causes any file writes to be avoided, such as the log file.
Naming. By default, the device names are displayed as numeric sequences (/dev/sg0). This option shows the device names as alphabetic sequences (/dev/sga).
Timeout for the format operation, in minutes. The default is 150 minutes, which should suffice for 150 GB disks. Larger disks require more time. Figure approximately 1 minute per GB of disk capacity.
Causes extra debug messages to be displayed.


sgdefects(8) sgdskfl(8) sgmode(8)


On some systems with older scsi drivers, the primary defect list cannot be returned without errors.

See for a bug list and any later versions of this utility.

Copyright (C) 2001-2002 Intel Corp.

sgdiag is open source software. You can redistribute it and/or modify it under the terms of the BSD License. See the COPYING file included with this software package for more details regarding distribution.

sgdiag is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.


Andy Cress <>