How are bad sectors recorded?

Chris Tate-Davies

Honorable
Dec 10, 2013
4
0
10,510
I know that a hard drive can contain bad sectors, but how does the OS know not to use them? Are they recorded on the actual drive, or within the OS somewhere?

The reason I ask is that I have a 1TB hdd and its the Linux boot disk in my Xubuntu machine. I also have a Windows VirtualBox that shares the drive. I know the 1TB drive is old and creaky and has bad sectors, but a large torrent that I was downloading (within the VM) has started failing on some of the files. I think its because Windows doesn't know about the bad sectors. Am I right?

I don't really need a solution, just confirmation that this could be the cause of the corrupt files in the VM/Torrent.

Thanks, Chris
 

Paperdoc

Polypheme
Ambassador
From a Windows perspective, Windows itself tries to monitor HDD performance and detect "Bad Sectors". What is more reliable, though, is using Windows' own utility, CHKDSK, to find and mark Bad Sectors. And here's where your answer comes in. Windows creates and updates its own file on the HDD to mark Bad Sectors so that it doe not use them. BUT that does NOT mean that any other OS (like your Linux OS) will use that information. So your Linux system is responsible for its own separate way of detecting and handling Bad Sectors. I don't now enough about Linux to tell you how that is done.

Even within Windows, though, this can still produce problems. Windows may not detect a Bad Sector by itself until after it has been written and then used for a read. By then you have corrupt data stored there. And all of Windows' processes for handling these things can NOT re-construct the original data; all they do is copy the corrupted data to a new reliable Sector to keep the file readable, and mark off the Bad Sector so that it is not re-used later. Worse, it can be very difficult to figure out which file might have contained the recently-detected Bad Sector and hence may now contain a good sector with corrupted data. But if you know a file is giving problems, it is up to you to fix that. In a few cases (like a document) you may be able to see the trouble and edit the file. But in many cases (a .dll file in the OS, or a video file, etc.) you have no practical way of editing out the error - your only solution is to find a good copy of that file and replace the faulty copy.

So, you can run CHKDSK to find any Bad Sectors so that Windows will not try to use them in future. This will not correct any corrupted files you have - you'll have to do that yourself. And it will not prevent your Linux system for using those Bad Sectors. May be Linux has its own way of doing this, too?
 

Chris Tate-Davies

Honorable
Dec 10, 2013
4
0
10,510
Thats what I thought, the Windows VM is not reading the Linux bad sector "database" and therefore its creating files that can't be read as they may overlap a bad sector.

I suspected as such, but wanted a second opinion. So thanks.