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?


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

sudo apt-get 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 call

sudo smartctl --all /dev/sda

Watch 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.

SMART overall-health self-assessment test result: PASSED

Other lines you want to check for are the Pending Sector Count and the Reallocated Sectors.

  5 Reallocated_Sector_Ct   0x0033   100   100   036    Pre-fail  Always       -       48
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       2

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

sudo smartctl -t long /dev/sda

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.

sudo badblocks -svvn -c 262144 /dev/sda

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.

  • 1
    what is the influence of -c or the number of blocks which are tested at a time or in other words why do you such a large value compared to the default of 64? – greole Sep 5 '14 at 15:26
  • 2
    default block-size of 1024 bytes multiplied by the default of 64 blocks at a time leads to only 64k processed on each request. With modern disks having a throughput of up to 150 MiB/s this introduces more overhead than I feel comfortable with. I want to give the drive the chance to process the data in the most efficient way without waiting for the data on the bus. – user228505 Dec 8 '14 at 12:20
  • Says: /dev/sda is apparently in use by the system; it's not safe to run badblocks! – Dims Mar 24 '16 at 20:09
  • 1
    @Dims It tells you to not run this on an actively mounted disk. Unmount the disk first. In your case it might be your system drive. So boot to a rescue system first. – user228505 Mar 26 '16 at 7:09
  • 1
    @Dims There is -force option if you want to run it anyways. i.e. sudo badblocks -svvn -c 262144 /dev/sda -force – ADR May 13 '16 at 17:35

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.