Proper way to format a drive with bad sectors

4 Antworten [Letzter Beitrag]
GNUser
Offline
Beigetreten: 07/17/2013

Hey,

I have an external hard drive, quite old now, which a few months ago when I connected it, threw an error stating "error when getting information for file XYZ (some of my folders): input/output error".

I tried a lot of different things back then, and couldn't get it to work properly again. I gave up, was able to salvage the folders with recovery software (I don't remember exactly, I think it was PhotoRec) and kept on accessing the folders that were OK.
Now my plan is to format the entire drive, and just use it fresh, but I would like to "mark" the bad portions of the drive, say it has 1TB it would only get to use 700GB for example. But make sure that only the (currently) good portions were used. I won't store any sensitive files there, I am aware at some point it will die, but for now I would like to solve it in the short term.

How should I do this, should GParted be the right tool? Or is there any other GNU/Linux tool better suited for this type of job?

Thanks!

GNUser
Offline
Beigetreten: 07/17/2013

Btw, I will leave here a trick that helped me, maybe it will help other people. From the point that error appeared, when I connect the drive it only shows a single folder. I right click inside, choose open terminal here, run ls and then caja .
this launches a new caja window showing a lot more of the contents of the drive, even some that are not accessible (I can see the folder but can't get inside).
Hope this serves someone someday :)

KaKooDa
Offline
Beigetreten: 03/20/2023

After doing what Alice Wilton said, it might be a good idea to check what is causing bad sectors, the health condition and assess if your disk worth using anymore by using S.M.A.R.T (Self-Monitoring, Analysis and Reporting Technology System). sudo apt-get install smartmontools
smartctl -h /dev/sdb

Pay attention that you have to do it after "mkfs.ext4 -cc" is done or smartctl won't be able to detect problems correctly.

GNUser
Offline
Beigetreten: 07/17/2013

Thanks for the reply!
Well, given the current nature of its intended usage, yes it is worthy of being kept around for now.
However, I do wonder, what exactly will that do, what kind of extra information or operation will that add to the above instructions?
Thanks!

KaKooDa
Offline
Beigetreten: 03/20/2023

A hard disk failure occurs when the data written on it can't be accessed. While having bad sectors is not an indicator of failure; It is associated with it. Hard disk failure may be due to physical damage, or just natural wear and tear over time. The later one is predictable to some extent. The probability of failure follows the concept of bathtub curve.

Earlier drives had a tendency toward developing bad sectors with use and wear; these bad sectors could be "mapped out" so they were not used and did not affect operation of a drive, and this was considered normal unless many bad sectors developed in a short period of time. Some early drives even had a table attached to a drive's case on which bad sectors were to be listed as they appeared. Later drives map out bad sectors automatically, in a way invisible to the user; a drive with remapped sectors may continue to be used, though performance may decrease as the drive must physically move the heads to the remapped sector. Statistics and logs available through S.M.A.R.T. provide information about the remapping. In modern HDDs, each drive ships with zero user-visible bad sectors, and any bad/reallocated sectors may predict the impending failure of a drive. [1]

The S.M.A.R.T tries to guess failure based on disk characteristics like operating temperature, spin-up time, data error rates, etc. Although its information may not be up to date. Running "mkfs.ext4 -cc" tries to read and write on all the sectors and thus updating S.M.A.R.T's information.

1: https://en.wikipedia.org/wiki/Hard_disk_drive_failure#Modes_of_failure