26

I'm running badblocks to check for bad segments on an external drive, and it's been about an hour and it has not yet finished. Now, I need to go and consider cancelling. Is this somehow risky? Should I avoid this?

Clearly, I will need to start again from scratch; I just want to know if this is somehow risky to abort midway.

bahamat
  • 39,666
  • 4
  • 75
  • 104

1 Answers1

32

From examining the source code, I find that:

If you didn't specify -n or -w, badblocks doesn't write to the disk at all, so you're safe interrupting it.

If you specified -w, badblocks has already overwritten the filesystem, so it's much too late to worry about interrupting the process.

If you specified -n, badblocks uses a signal handler to prevent the program from exiting with the disk in an inconsistent state, so it is safe to press ctrl-c.

Kyle Jones
  • 15,015
  • Can there be an inconsistent state if there is no filesystem on the device? I assume that in write mode badblocks would have damaged all filesystem metadata structures already, so is there still room for inconsistency? – phunehehe Jul 26 '12 at 06:44
  • 1
    @phunehehe: There may be non-overwritten blocks on the device; but given that badblocks will start at the beginning of the disk, it's a moot point, as there won't be any partition table, thus technically making the disk "unformatted". (An unformatted disk is not required to be filled with zeroes - the content is undefined) – Piskvor left the building Jul 26 '12 at 08:38
  • But I supposed that means there is no risk of inconsistency? Because everything is basically gone already. – phunehehe Jul 26 '12 at 09:02
  • Is this correct also when badblocks is used by calling e2fsck -cc? From man page: "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." and "If this option is specified twice, then the bad block scan will be done using a non-destructive read-write test." – lumbric Jun 24 '18 at 19:03