How Does ChkDsk Recover Data and Repair Bad Sectors?

KAWill70

Distinguished
Aug 23, 2008
25
0
18,540
Can anyone explain how the Windows ChkDsk program recovers data and repairs bad sectors where possible?

I was just wondering if any error correction techniques are used or whether the program just performs multiple reads and attempts to verify the data using the existing CRC.

 
it recovers what data it can read and moves it to a good part of the disk anything corrupt or missing in the bad spot is just lost ,and blocks the bad sectors from being wrote to this is a mechanical issue with the drive but if another one goes bad where windows has something that it needs to boot then its a dun deal--- you may get 10 more years or 10 more day out of the drive but damage is damage....


http://en.wikipedia.org/wiki/Bad_sector
 

Paperdoc

Polypheme
Ambassador
CHKDSK is not very good at recovering data, but it does get hidden help from the HDD unit itself. Modern HDD's have significant smarts built into them that Windows does not actually see. When the HDD is asked to read a Sector, it checks the data it gets for validity (checksums and the like) and also for the quality of the signal levels it receives. Note that checksums cannot be used to regenerate damaged data from a Sector - they merely tell you whether the data retrieved is valid or has errors. If the data checks say no problems, no action is needed. But if the data has errors, OR if the HDD is not satisfied that the signals are clean, the drive's on-board smarts go through an attempt to recover data. This may include multiple re-reads of the Sector and some work to assess the signals and get good data from them. If this all succeeds, the recovered good data are written to a replacement good Sector (the HDD itself has a semi-hidden stock of unused known-good Sectors) and the faulty Sector is marked off as unusable. Then the data are fed back to the OS that requested it, and no further action is taken. Most of this checking and data recovery attempt is completely unknown to Windows. Only if the data recovery effort fails does the HDD tell Windows it cannot delivery good data and a read error has occurred.

Now, if CHKDSK gets a Read Error reply from the HDD, it requests a re-read. It will do this several times before giving up. Each re-read request actually triggers that same on-disk process. But note that CHKSDK itself has no process to recover data. It can only ask the HDD to try again a limited number of times. If, in the end, even that many requests from CHKDSK fails, then CHKDSK considers that Sector to be a Bad Sector. It logs that into its own file on disk listing Bad Sectors so that Windows will never use it again. Then it asks the HDD to assign a new clean Sector to that position in the file in use so that the file can still be read. The problem here, though, is that the new clean Sector assigned contains random data - CHKDSK never had good data to write to it. So the resulting file, although readable, contains corrupted data. In some cases (for example, a simple graphics file or a text file) you may be able to open the file and manually edit it to restore the lost info. In many cases, however (for example, an .exe file that is part of the Windows OS or of an application software package), the only way to recover from this problem is to find another good copy of that file and use it to replace the corrupted copy.
 

KAWill70

Distinguished
Aug 23, 2008
25
0
18,540
Thanks junkeymonkey and Paperdoc very much for your replies. It is much appreciated.

Things now make much more sense. I hadn't realized the role played by the hard drive itself and the disk controller hardware and firmware.

This is really quite fascinating and there is apparently more much technology here than most people realize. I assume that the NTFS file system plays a role also and that similar features would not be supported by the FAT file system.

I've also noticed that disk drives are generally listed as SCSI disk drives when viewed from the operating system even though no disk drive with SCSI hardware interface is actually used. I assume that SCSI features may be in use and I have an idea that some of the data recovery features may be part of SCSI.

It would be interesting to know exactly what goes on when the hard drive attempts to read a bad sector. I do know that the SpinRite Program has special capabilities in reading data and also rewriting the entire drive.
 
bottom line is your now getting disk damage so as I said it may run fine for 10 more years or 10 more hrs. keep your important files backed up as I said above if another one goes bad where windows has something that it needs to boot it will not boot and its now a storage drive... also did you notice that when you defrag the disk it throws that error cause defrag want to defrag that part of the disk? look in event viewer and see how many disk errors listed . if you start to see slow downs or little/odd glitches or some noise from the disk that you never noticed before you may want to replace it .. as I said damaged is damaged and something caused it
 

KAWill70

Distinguished
Aug 23, 2008
25
0
18,540
Thanks junkeymonkey for the additional information. Actually my system is fine and my questions related to a friend who was getting WinXP blue screens during boot. He recovered after trying many things including multiple runs of chkdsk. At this point I don't know what really fixed the problem although it could well have been chkdsk. He did review items in the Event Viewer but I don't know the details. I'll pass along your information.

That's interesting about the disk defrag and bad sectors. Will see what I can learn about that.
 

KAWill70

Distinguished
Aug 23, 2008
25
0
18,540
His system is not that old as it was upgraded with a new Motherboard, Intel dual core processor, and 250 GB SATA Disk Drive. He is aware that WinXP has ended support and is considering moving to Win 7.

Just found out that Windows can mark a Disk Volume as dirty if errors are detected. Defrag will apparently not run if the dirty bit is set.