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:
  ER -- ST COUNT  LBA_48  LH LM LL DV DC
  -- -- -- == -- == == == -- -- -- -- --
  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
72047552
72047553
72047554
72047555
72047556
72047557
72047558
72047559
72047560

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

Explanation:

  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 (13)


Comments

PlatonDic on Saturday, July 20, 2019 at 16:00

<img src="https://c.radikal.ru/c18/1907/fa/6b30e6001d99.jpg">
ТЕРСЕНОВ АРХИМЕД АРИСТОТЕЛЕВИЧ дата рождения 26 октября 1981. родился в Грузии жил с юных лет в с. Шпаковское (ныне г.Михаиловск) Ставропольский край. На данный момент проживает в Греции

WillieQualo on Saturday, July 20, 2019 at 19:23

http://xn--80atdlk.xn----7sbafcvrd1a5e1e.xn--80adxhks Дешевые авиабилеты Корла - Москва, авиабилеты, авиабилеты москва, авиабилеты дешево, авиабилеты онлайн, купить авиабилеты, авиабилеты официальный сайт

Atrohin56 on Sunday, July 21, 2019 at 05:20

Здравствуйте.

Возможно устранить ошибку AL15 https://prom-electric.ru/articles/1/1329/ на danfoss fc202?
Буду благодарен за любые ответы.

PlatonDic on Sunday, July 21, 2019 at 05:24

<img src="https://b.radikal.ru/b16/1907/d3/52bc0d92f732.jpg">
ТЕРСЕНОВ АРХИМЕД АРИСТОТЕЛЕВИЧ дата рождения 26.10.1981. родился в Грузии жил с юных лет в с. Шпаковское (ныне г.Михаиловск) Ставропольский край. На данный момент проживает в Греции

Zlata96UKRLew on Sunday, July 21, 2019 at 11:03

Hi! I'm Zlata, living in Ukraine. To be honest, I live in a village and we have no job. I get about $110 a month. It is very little ((
That's why I can do it for a little money:
- Send you hot photos and videos
- send you a video of sex with an ex-boyfriend (if you don't put it out there!)
- Make a hot webcast, such as Skype
Also ready to come to you in any country for your money.
I will not leave my contacts here. Find me just on the site http://bestgirls.iseekyou.today/?utm_source=5c167d5db0354&track=Zlata96&click_id=Zlata96 my nickname is Zlata96

<a href=http://v.ht/SexMamba><img src="https://i.yapx.ru/EukHN.jpg"></a>


==========================
Привет! Я Злата, живу в Украине. Скажу честно, я живу в деревне и работы у нас нет. Я получаю в месяц примерно $110. Это очень мало((
По этому я могу за небольшие деньги:
- прислать тебе горячие фото и видео
- прислать тебе видео секса с бывшим парнем (если вы не будете выкладывать его!)
- сделать горячую ВЕБ-трансляцию , например в скайп
Так же готова приехать к вам в любую страну за ваши деньги.
Свои контакты тут не оставлю. Найти меня просто на сайте http://bestgirls.iseekyou.today/?utm_source=5c167d5db0354&track=Zlata96&click_id=Zlata96 мой ник Zlata96

PotapDic on Sunday, July 21, 2019 at 16:11

<img src="https://a.radikal.ru/a23/1907/01/3394cbb45861.jpg">
ТЕРСЕНОВ АРХИМЕД АРИСТОТЕЛЕВИЧ дата рождения 26.10.1981. родился в Грузии жил с юных лет в с. Шпаковское (ныне г.Михаиловск) Ставропольский край. На данный момент проживает в Греции

Irvintit on Sunday, July 21, 2019 at 23:23

Joyce Sherman died on October 16, 2001 <a href=http://mrhs.tech>RedCoin</a> Also confirm out Serengeti Exclusive Gallery featuring cats omnium gatherum, floral designs, spring, summer and adrift, tee and Sweatshirt Shoppe, denim delights, Serengeti exclusives, be destroyed glean exhibition, respite observation and winter wonderland

FrankjAb on Monday, July 22, 2019 at 01:43

PotapDic on Monday, July 22, 2019 at 06:04

<img src="https://b.radikal.ru/b33/1907/e9/556b6d0cfa0d.jpg">
ТЕРСЕНОВ АРХИМЕД АРИСТОТЕЛЕВИЧ дата рождения 26 октября 1981. родился в Грузии жил с юных лет в с. Шпаковское (ныне г.Михаиловск) Ставропольский край. На данный момент проживает в Греции

Irvintit on Monday, July 22, 2019 at 06:05

Online coupons from Serengeti are similar to to printable coupons in that you can immediately apply spondulix savings to your purchase <a href=https://tmtn.tech>RedCoin</a> Sherman 2000 Nominated Annie First-rate Singular Acquirement on the side of Music in an Vivacious Main attraction Forming for: The Tigger Talking picture (2000)

Irvintit on Monday, July 22, 2019 at 14:11

Attractions such as the, South Texas Art Museum, The Texas Glory Aquarium, the U <a href=https://rstock.tech>RedCoin</a> Sherman John Williams 1972 Nominated Oscar Trounce Music, Primitive Ado against: Bedknobs and Broomsticks (1971)

Irvintit on Monday, July 22, 2019 at 22:03

Test shy away from regularly in behalf of updates ahead your arrival <a href=https://ofstock.tech>OfStock</a> Trust yourself more than anything else - granted you are using online culture tips in return students it is signal that you charge your abilities to dig your lessons

StevenLat on Tuesday, July 23, 2019 at 04:48

Buy Etsy knitting picture, drawing, figure, pattern, https://www.etsy.com/shop/SoEasyPattern picture, illustration, design, toys pattern, PDF pattern clothing, yarnart jeans, Amigurumi toys, geometric cross stitch, animals cross stitch, felt toys pattern, baby cross stitch, boho cross stitch, Wedding cross stitch, Disney Princes, Birds cross stitch,food cross stitch, floral cross stitch, modern cross stitch, nature cross stitch

Add a comment

Name:
Email: (optional, not displayed to public)
URL:

Comment: