Identifying file associated with a bad sector on ext2/ext3/ext4

Monday, April 16, 2018

I got some SMART warnings about a bad sector on my hard drive, and I wanted to know which specific file had the bad sector.

First, I looked at the SMART logs to see where the problem was:

# smartctl -x /dev/sdd

  After command completion occurred, registers were:
  -- -- -- == -- == == == -- -- -- -- --
  40 -- 51 00 08 00 00 04 4b 5b c0 40 00  Error: UNC at LBA = 0x044b5bc0 = 72047552


fdisk -l is useful for looking at the partition info and sector size:

# fdisk -l /dev/sdd
Disk /dev/sdd: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x54afc7e9

Device     Boot Start        End    Sectors  Size Id Type
/dev/sdd1        2048 3907029167 3907027120  1.8T 83 Linux

Then I used badblocks to look around that physical sector for more bad sectors. My sector size is 512 bytes, shown above; also, badblocks takes the end sector number first, followed by the start sector:

# badblocks -b 512 /dev/sdd 72047570 72047540

Finally, debugfs is useful for finding which files are on those blocks.


  1. First, find the logical filesystem block number by computing (physical sector - partition start sector) * (physical sector size / filesystem block size). In my case, this would be (72047552 − 2048) * (512 / 4096) = 9005688. Since there are 9 contiguous sectors affected, the bad area stretches into block 9005689 as well.
  2. Use testb to see whether there is actually anything there. If not, then no data is lost.
  3. Use icheck to find the inode corresponding to those blocks. Luckily (?), both bad blocks are associated with the same inode here.
  4. Finally, use ncheck to find the pathname(s) associated with the inode.
# debugfs /dev/sdd1
debugfs 1.43.5 (04-Aug-2017)
debugfs:  testb 9005688
Block 9005688 marked in use
debugfs:  testb 9005689
Block 9005689 marked in use
debugfs:  icheck 9005688
Block   Inode number
9005688 105518423
debugfs:  icheck 9005689
Block   Inode number
9005689 105518423
debugfs:  ncheck 105518423
Inode   Pathname
105518423       /drz/rdiff-backup/artanis/var/lib/pgsql/data/base/21595/26720

Here, it was just a backup file, so once I swap out the hard drive or reallocate the sector, the next backup cycle will fix the lost data.

Tags: linux | Posted at 22:57 | Comments (7)


Aborahreuts on Friday, May 24, 2019 at 03:02

Хэлоу, если вы играете на ставках,
<a href=>чемпионат прогнозов футбол</a> советую вам контакты надежных аналитиков
они всегда грабят букмекеров, и помогут вам заработать на ставках реальные
финансы прогнозы составляют каждый день! контакты этой сообщества дальше по ссылке: и если скажите что вы от Луиса то получите хорошие бонусы!

Alexzoose on Friday, May 24, 2019 at 03:23

Hi savings lover!

What can you buy online? Yes, almost everything! So, for everything you can get a significant percentage of cashback from our service!

Our regular users know that using a <a href=>cashback service cashback service</a> you can not only profitably buy clothes and equipment, but also save money on purchases of household chemicals, cosmetics and the mass of other categories of goods. And with us you can get a cashback with each order of your favorite food!

We are constantly expanding our list of partners among online stores, choosing the most popular of them, so that you don’t have to limit yourself to choosing!

Choose from thousands of brands and a million products of various categories! And, of course, get cashback from each order! Visit our website right now and reduce your spending on purchases!

Save up to 40% from each purchase !. Use <a href=>cashback service cashback service</a>s. Introducing the largest <a href=>cashback service cashback service</a> in the world!
- 2078 popular online cashback stores
- 969 stores with increased cashback
Today, bank cards are not only a way to store money and non-cash payments, but also a very interesting financial instrument, opening a number of convenient and profitable functions for their owners.
Cashback has become a favorite subject in many of the features of related cards.
Fast cash withdrawal in a convenient way!

Williamswate on Friday, May 24, 2019 at 10:55

<a href=>Magnetic Blocks</a>

Williamswate on Friday, May 24, 2019 at 23:17

<a href=>Magnetic Blocks</a>

Mariawar on Saturday, May 25, 2019 at 01:56

<a href=>Cемена конопли в интернет-магазине Cannado</a>

Tomaskam on Saturday, May 25, 2019 at 13:17

Tomaskam on Saturday, May 25, 2019 at 19:57

Add a comment

Email: (optional, not displayed to public)