Gentoo Archives: gentoo-user

From: John Covici <covici@××××××××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Re: e2fsck -c when bad blocks are in existing file?
Date: Tue, 08 Nov 2022 21:52:36
Message-Id: m34jv95d2h.wl-covici@ccs.covici.com
In Reply to: RE: [gentoo-user] Re: e2fsck -c when bad blocks are in existing file? by Laurence Perkins
1 On Tue, 08 Nov 2022 12:55:51 -0500,
2 Laurence Perkins wrote:
3 >
4 >
5 >
6 > >-----Original Message-----
7 > >From: Grant Edwards <grant.b.edwards@×××××.com>
8 > >Sent: Tuesday, November 8, 2022 6:28 AM
9 > >To: gentoo-user@l.g.o
10 > >Subject: [gentoo-user] Re: e2fsck -c when bad blocks are in existing file?
11 > >
12 > >On 2022-11-08, Michael <confabulate@××××××××.com> wrote:
13 > >> On Tuesday, 8 November 2022 03:31:07 GMT Grant Edwards wrote:
14 > >>> I've got an SSD that's failing, and I'd like to know what files
15 > >>> contain bad blocks so that I don't attempt to copy them to the
16 > >>> replacement disk.
17 > >>>
18 > >>> According to e2fsck(8):
19 > >>>
20 > >>> -c This option causes e2fsck to use badblocks(8) program to do
21 > >>> a read-only scan of the device in order to find any bad blocks. If
22 > >>> any bad blocks are found, they are added to the bad block inode to
23 > >>> prevent them from being allocated to a file or directory. If this
24 > >>> option is specified twice, then the bad block scan will be done
25 > >>> using a non-destructive read-write test.
26 > >>>
27 > >>> What happens when the bad block is _already_allocated_ to a file?
28 > >
29 > >> Previously allocated to a file and now re-allocated or not, my
30 > >> understanding is with spinning disks the data in a bad block stays
31 > >> there unless you've dd'ed some zeros over it. Even then read or write
32 > >> operations could fail if the block is too far gone.[1] Some data
33 > >> recovery applications will try to read data off a bad block in
34 > >> different patterns to retrieve what's there. Once the bad block is
35 > >> categorized as such it won't be used by the filesystem to write new data to it again.
36 > >
37 > >Thanks. I guess I should have been more specific in my question.
38 > >
39 > >What does e2fsck -c do to the filesystem structure when it discovers a bad block that is already allocated to an existing inode?
40 > >
41 > >Is the inode's chain of block groups left as is -- still containing the bad block that (according to the man page) "has been added to the bad block inode"? Presumably not, since a block can't be allocated to two different inodes.
42 > >
43 > >Is the "broken" file split into two chunks (before/after the bad
44 > >block) and moved to the lost-and-found?
45 > >
46 > >Is the man page's description only correct when the bad block is currently unallocated?
47 > >
48 > >--
49 > >Grant
50 >
51 > If I recall correctly, it will add any unreadable blocks to its internal list of bad sectors, which it will then refuse to allocate in the future.
52 >
53 > I don't believe it will attempt to move the file to elsewhere until it is written since:
54 > A) what would you then put in that block? You don't know the contents.
55 > B) Moving the file around would make attempts to recover the data from that bad sector significantly more difficult.
56 >
57 > This is, however, very unlikely to come up on a modern disk since most of them automatically remap failed sectors at the hardware level (also on write, for the same reasons). So the only time it would matter is if you have a disk that's more than about 20 years old, or one that's used up all its spare sectors...
58 >
59 > Unless, of course, you're resurrecting the old trick of marking a section of the disk as "bad" so the FS won't touch it, and then using it for raw data of some kind...
60 >
61 > You can, of course, test it yourself to be certain with a loopback file and a fake "badblocks" that just outputs your chosen list of bad sectors and then see if any of the data moves. I'd say like a 2MB filesystem and write a file full of 00DEADBEEF, then make a copy, blacklist some sectors, and hit it with your favorite binary diff command and see what moved. This is probably recommended since there could be differences between the behaviour of different versions of e2fsck.
62
63 Maybe its time for spinwrite -- new version coming out soon, but it
64 might save your bacon.
65
66 --
67 Your life is like a penny. You're going to lose it. The question is:
68 How do
69 you spend it?
70
71 John Covici wb2una
72 covici@××××××××××.com