SCSI Harddrive Resurrection

Repairing a disk that has corrupted geometry information.


While in the process of trying to get cdda2wav to work under Linux I hacked up the source code to eliminate some annoying check that kept preventing the program from working. At least thats that I thought. Turns out that I did not understand the ordering scheme of the generic scsi devices (sg*). I should have read the SCSI Programming HOWTO first. It has a section on device mapping. With my newly hacked code I managed to render one of my 2GB SCSI disks unuseable! Furthermore, Linux would no longer boot. The kernel would panic during SCSI disk driver installation. I tried fixing the disk under DOS but fdisk did not even see the drive. I tried to low-level format the drive also but the low-level format program was too confused about the disk size to work.

Some weeks later, after restoring my system to a new 7200 rpm Utra-Wide SCSI disk I found time to work on my broken disk. I began by adding debugging messages to the scsi device driver section of the Linux kernel. I eventually came to understand that the problem was that some of the mode page settings had been overwritten with incorrect values. The scsi mode pages are stored on the disk in an area not used for data storage (usually on the first track). The complete SCSI-II draft standard specification describes the contents of the mode pages and the standards for accessing them.

Driver programs provide access to mode page information on a hard disk drive by implementing the MODE_SENSE ioctl operation. Some of the fields of the mode pages are writeable and can be written with the MODE_SELECT ioctl. Here is a table of the mode pages:

Mode Page Op-Code SCSI Spec. Section
Control 0Ah 7.3.3.1
Disconnect-Reconnect 02h 7.3.3.2
Peripheral Device 09h 7.3.3.3
Caching 08h 8.3.3.1
Format Device 03h 8.3.3.3
Notch and Partition 0Ch 8.3.3.5
Error Recovery 01h 8.3.3.7
Rigid Disk Geometry 04h 8.3.3.7
Verify Error Recovery 07h 8.3.3.8

By adding debugging messages to my kernel I eventually found that the bytes per sector entry in the Format Device page of the broken drive had been changed to 2048 bytes instead of the 512 bytes that it should have been. Now I needed to change it back and it was not too clear at the time exactly where to do this in the kernel code. If I could have booted Linux then I could have use a neat Linux program called scsiinfo. This tools dumps all sorts of information about a scsi device including mode page settings and it will even let you change mode page settings. Here's a sample of the output from running "scsiinfo -a /dev/sdb" on my machine. But, alas, I could not boot Linux.

Fortunately I discovered an awesome Windows95 program called SCSI toolbox32. This program does alot of stuff related to SCSI devices including changing mode page settings. This is an expensive commercial product but a time limited full demo version is available from their site and that was all I needed to repair my disk.

Here's a summary of some of the useful links that I used in resurrecting my disk drive.

cdda2wav
Linux program for extracting digital audio data from audio cd's. FYI, don't hack up the code unless you know what you're doing!

scsiinfo
Linux program that dumps scsi information including mode page settings.

SCSI Faq - comp.periphs.scsi
Lot's of useful information about SCSI configuration.

SCSI toolbox32
This program runs under Windows95 and allows you to change mode page settings.

SCSI-II draft standard specification
This site is maintained by the T10 Techinical Committee and contains all sort of useful standards documents regarding SCSI

Linux SCSI Programming HOWTO
A guide to the installation and programming of the Linux generic SCSI interface.