I've noticed that on my home Ubuntu server one drive is read only for some reason. Digging up I found that this can happen when hard drives have errors. I used badblocks to check for errors, and indeed I have some damaged sectors.
In most cases the only rational course of action is to try to backup data, remove the HDD and buy a new one. However, this server doesn't have anything I already don't have backed up on multiple places, and I'd like to use it till it dies. I use it for streaming music and running some simple scripts. In any case, it would be a big fuss reinstalling everything.
Is there a way to mark these bad blocks without formatting a hdd?
Best Answer
I assume you are talking about physical bad blocks on a disk and not about corrupted file systems.
To check the physical condition of your disk it's best to install
smartmontools
This works because all modern disks log their health status using a system called S.M.A.R.T.
Use the
smartctrl
command to read out this status. For example to read all attributes from the first disk callWatch out for a line talking about the overall heath status. Once this indicates an error it's very likely that the disk will fail soon.
Other lines you want to check for are the Pending Sector Count and the Reallocated Sectors.
Reallocated lists usually in the raw field the number of bad sectors the disk exchanged for working spare ones. Pending are sectors which might be reallocated in case the next write fails.
You can even trigger self tests of the disk when supported by your model
To force checking of all sectors, use
badblocks
in a mode in which data is written. Beware that even though in general it is safe to run, it will put extra load on your disks, which might cause them to fail. Always have a backup of your data.The output from the
badblocks
command will show you many lines withwhere
If you have fully processed your disk this way, the disk controller should have replaced all bad blocks by working ones and the reallocated count will be increased in the SMART log.