How to mark bad blocks unusable?

Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
jackcq

How to mark bad blocks unusable?

Post by jackcq »

I have this old faulty 2TB disk, which I want to use as a data dump. Yes, I know it has some bad blocks and I know, it can completely fail anytime.
That's why I don't plan to write anything important to it, at least nothing I haven't backed up anywhere else. My question is how do I manage to blacklist the
bad blocks I already identified to make sure no data gets written to them accidentally?

I created an EXT4 volume spanning the whole drive and ran badbblocks:
~ # badblocks -v /dev/sdd1
Checking blocks 0 to 1953513559
Checking for bad blocks (read-only test): 1351620412
1351620413
1351620414
1351620415
done
Pass completed, 4 bad blocks found. (4/0/0 errors)
As far as I know, that just identifies the bad blocks, but does not mark them, right? Is there any way to do it?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
WharfRat

Re: How to mark bad blocks unusable?

Post by WharfRat »

As far as I know the list displayed should have been written to the bad block inode so they will not be allocated to a file or directory.

However you should double-check that with the dumpe2fs -b option.
User avatar
Fred Barclay
Level 12
Level 12
Posts: 4185
Joined: Sat Sep 13, 2014 11:12 am
Location: USA primarily

Re: How to mark bad blocks unusable?

Post by Fred Barclay »

According to http://linux-sys-adm.com/how-to-check-f ... ntu-linux/ you could
1. Rerun badblocks but pipe the output into a text file:

Code: Select all

sudo badblocks -v /dev/sdd1 > ~/badblocks.txt
2. Run fsdisk with the text file as input:

Code: Select all

sudo fsck -C -t ext4 -l ~/badblocks.txt /dev/sdd1
I would probably wait for a second opinion though before running this. I checked the fsck manpage, and while this looks correct I've never used fsck before and I might be wrong.
Cheers!
Fred
Image
"Once you can accept the universe as matter expanding into nothing that is something, wearing stripes with plaid comes easy."
- Albert Einstein
jackcq

Re: How to mark bad blocks unusable?

Post by jackcq »

WharfRat wrote:As far as I know the list displayed should have been written to the bad block inode so they will not be allocated to a file or directory.

However you should double-check that with the dumpe2fs -b option.
Thanks for the hint, but as I feared, badblocks only displays the bad blocks and does not actually block/blacklist them. Confirmed with dumpe2fs as you suggested.
jackcq

Re: How to mark bad blocks unusable?

Post by jackcq »

Fred Barclay wrote: 2. Run fsdisk with the text file as input:

Code: Select all

sudo fsck -C -t ext4 -l ~/badblocks.txt /dev/sdd1
I would probably wait for a second opinion though before running this. I checked the fsck manpage, and while this looks correct I've never used fsck before and I might be wrong.
Cheers!
Fred
This looks really promising, but for some reason it does not work for me:
# fsck -C -t ext4 -l /home/carl/badblocks.txt /dev/sdd1
fsck from util-linux 2.27.1
fsck: the -l option can be used with one device only -- ignore
e2fsck 1.42.13 (17-May-2015)
e2fsck: need terminal for interactive repairs
e2fsck 1.42.13 (17-May-2015)
e2fsck: need terminal for interactive repairs
With /home/carl/badblocks.txt being the output file from the badblocks command. No idea why it complains about "can be used with one device only. It's not like /dev/sdd1 is
more than one device (and yes I tried /dev/sdd - without the 1 - as well).
WharfRat

Re: How to mark bad blocks unusable?

Post by WharfRat »

Your best bet is to run fsck.ext4 with the -c option.

According to the man page
-c This option causes e2fsck to use badblocks(8) program to do a read-only scan of the device in order to find any bad blocks. If any bad blocks are found, they are added to the bad block inode to prevent them from being allocated to a file or directory. If this option is specified twice, then the bad block scan will be done using a non-destructive read-write test.
I never used badblocks directly so I was under the impression that it was badblocks that wrote to the bad block inode, but it's now apparent that it's fsck that does that :?
jackcq

Re: How to mark bad blocks unusable?

Post by jackcq »

WharfRat wrote: I never used badblocks directly so I was under the impression that it was badblocks that wrote to the bad block inode, but it's now apparent that it's fsck that does that :?
Thank you, that seems to have worked. However, I am confused because the result seems different compared to running badblocks directly:
~ # dumpe2fs -b /dev/sdc1
dumpe2fs 1.42.13 (17-May-2015)
337905103
compared to:
~ # badblocks -v /dev/sdd1
Checking blocks 0 to 1953513559
Checking for bad blocks (read-only test): 1351620412
1351620413
1351620414
1351620415
done
Pass completed, 4 bad blocks found. (4/0/0 errors)
And yes, it is the same device ... depending on the order order I plug in usb devices.
Maybe the first result is inodes the other blocks? I'll carefully start copying data, using checksums and I'll see if I'll get any errors.
WharfRat

Re: How to mark bad blocks unusable?

Post by WharfRat »

jackcq,

It is strange that you got different results from fsck and when running badblocls directly

I'm befuddled myself and have no explanation for the disparity.

Have you run smartctl on that device to see what it has to say as far as recorded errors and its overall health assessment :?:

If you're that unsure about that disk then perhaps it's not a good idea to use it for backups.
jackcq

Re: How to mark bad blocks unusable?

Post by jackcq »

WharfRat wrote:jackcq,

It is strange that you got different results from fsck and when running badblocls directly

I'm befuddled myself and have no explanation for the disparity.

Have you run smartctl on that device to see what it has to say as far as recorded errors and its overall health assessment :?:

If you're that unsure about that disk then perhaps it's not a good idea to use it for backups.
Smartctrl reports "Disk is OK, 8 bad sectors (39° C / 102° F)".

I still think that one result might be inodes while the other is blocks. I remember, when I ran the fsck, it found the bad
blocks at around 80%. The drive has 1,953,513,559 blocks, concluding that block 337,905,103 would be fairly
at the beginning and not at 80%.

I also learnt that the SATA-USB adapter I've been using is not to be trusted. When I started copying data to the drive, I had
random checksum failures. So I attached the drive directly to the internal SATA bus and managed to copy over like 800GBs
which all read back fine according to md5sum.

Of course the drive is still faulty. I removed it from my system like 5 years ago for that reason. And of course you're right,
that I shouldn't use it for backups. However, I'm not going to backup anything important to that drive, mostly old video
files (tv-shows from my sat receiver) that I've already watched and most likely won't watch again, or stuff that's already
backed up on another drive and on bd-r.

I still haven't found any good way to store large amounts of data, bd-rs are too small, the media is fairly expensive and
can deteriorate, external drives can fail and aren't cheap either. So I backup important data using double backups
with both and on a NAS drive. The only reason why I dug out that old disk again, is because the space was getting low
and the alternative would have been to delete stuff.
Mute Ant

Re: How to mark bad blocks unusable?

Post by Mute Ant »

If your 8 bad sectors stays at 8 it's just a sign of the hard drive firmware doing its job. They have already been remapped by the drive, replaced by working spares. Some people consider any bad-sector imperfection to be a sign of impending doom, disk-wise, but I don't. There's lots of other drive-related failures that can take out the whole store with no SMART warning at all.
Locked

Return to “Storage”