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

BrianFum on Monday, August 19, 2019 at 00:24

Thousands of girls online are looking for sex here. Hurry up while registration is free http://2lol.space/x]

YonqVeife on Monday, August 19, 2019 at 13:26

Хак Форум Творческая Лаборатория DedicateT

ShawnCurry on Monday, August 19, 2019 at 17:06

<a href=https://www.altredo.com/forex.aspx>FOREX ROBOT</a> DOUBLE PROFIT
⭐️⭐️⭐️⭐️⭐️
https://www.altredo.com/forex.aspx
Forex Robot Double Profit is new excellent reliable and accurate fully automated forex trading system. Works for any broker Metatrader 4 trading platform. Forex Robot Double Profit has built in maximum spread and slippage filters to ensure that you will only get the highest probability trades. Forex Robot Double Profit can grow the smallest of deposits into huge amounts fully automated.
✅ High win rate
✅ Low Risk
✅ Excellent support
✅ Shows excellent consistency over different market conditions
✅ Takes multiple trades each day
✅ Delivers consistent forex investment returns fully automatically
✅ It is ready to use straight out of the box with the default settings although you may wish to adjust the risk.
<a href=https://www.altredo.com/forex.aspx>Download FOREX ROBOT</a> now!

Michelemible on Tuesday, August 20, 2019 at 14:53

Who can stop Latvian banks killer - Ilmars Rimshevics (Ilmārs Rimšēvičs)?

<b>AS PNB Banka's new shareholders and Management Board announcement</b>

AS PNB Banka’s new shareholders and Management Board believe that the Bank is currently solvent and that the Bank’s liquidity is currently good. AS PNB Banka’s new shareholders had also submitted a plan to inject further capital of €146 million.

<img src="http://img.reitingi.lv/timthumb.php?src=news/0801100153_capture.jpg&w=400&zc=1&q=90">

Within hours of the ECB's and the SRB's decisions on Thursday, the Bank reached out to the ECB and the SRB requesting the full text of their decisions so that their basis can be analyzed. There has been no substantive response by the ECB. The SRB merely stated that it needs to determine which parts of its decision can be disclosed to the bank.

The SRB was asked by the Bank to clarify on what basis it has stated on Thursday evening that the bank will be liquidated under national law. AS PNB Banka’s new shareholders and Management Board understand that the SRB has no decision-making power as regards a liquidation under national law.

AS PNB Banka’s new shareholders and Management Board also note the FCMC's statement on Thursday that its measures are "unexpected". The FCMC will have to explain the basis on which it made a determination of the unavailability of deposits.

AS PNB Banka’s new shareholders and Management Board will vigorously contest any petition for the opening of insolvency proceedings in front of the Latvian courts and in this context will demand that the Latvian courts obtain guidance from the European Court of Justice as to compliance with applicable European law.

AS PNB Banka’s new shareholders and Management Board reserve all rights and remedies on a national and European level as well as their rights pursuant to investment treaties. This includes the investment treaty between the United States of America and Latvia. AS PNB Banka’s new shareholders have therefore written to the US Embassy in Riga.

AS PNB Banka’s new shareholders and Management Board also recall the responsibility of Latvia and the European authorities as regards the credibility and reliability of banking regulation in Latvia. Outside observers (such as the US government) but also the competent Latvian authorities themselves have acknowledged the serious issues in this regard. The competent authorities and the courts should be allowed to discharge fully their responsibility in this regard so as to restore confidence in the system.

The ECB’s assessment of the Bank's financial position needs to be analyzed against the background of the auditor’s and the FCMC’s prior assessments. AS PNB Banka’s new shareholders and Management Board are concerned that the bank is treated differently than all other comparable banks in Latvia and elsewhere in Europe.

AS PNB Banka’s new shareholders and Management Board are convinced that the Bank's continued operations can be ensured and that this will be for the benefit of more than 100,000 Bank's depositors, 500 employees and their families as well as Latvia and its tax revenues.

<a href=http://www.press.lv/post/v-nastoyashhee-likviden-i-platezhesposoben-novye-aktsionery-pnb-banka-reshili-poborotsya-za-pravdu/>Link to the News portal</a>

<a href=http://www.schneider-lengauer.at/hallo-welt/#comment-26638>AS PNB Banka's new shareholders and Management Board announcement</a> b275b4e

YonqVeife on Tuesday, August 20, 2019 at 21:48

Хакерский Форум Творческая Лаборатория DedicateT

DennisJoync on Wednesday, August 21, 2019 at 08:08

Wall Sticker USA. We make wall stickers for your home z https://wallsticker.us/ Cartoons, Portaits, SuperHeroes, ArtDecor, Childroom, Traveling, Quotes, Sport, Brand and Logos, Computer Games, Anime

ShawnCurry on Wednesday, August 21, 2019 at 08:12

<a href=https://www.altredo.com/forex.aspx>FOREX ROBOT</a> DOUBLE PROFIT
⭐️⭐️⭐️⭐️⭐️
https://www.altredo.com/forex.aspx
Forex Robot Double Profit is new excellent reliable and accurate fully automated forex trading system. Works for any broker Metatrader 4 trading platform. Forex Robot Double Profit has built in maximum spread and slippage filters to ensure that you will only get the highest probability trades. Forex Robot Double Profit can grow the smallest of deposits into huge amounts fully automated.
✅ High win rate
✅ Low Risk
✅ Excellent support
✅ Shows excellent consistency over different market conditions
✅ Takes multiple trades each day
✅ Delivers consistent forex investment returns fully automatically
✅ It is ready to use straight out of the box with the default settings although you may wish to adjust the risk.
<a href=https://www.altredo.com/forex.aspx>Download FOREX ROBOT</a> now!

esifgesqx on Wednesday, August 21, 2019 at 09:51

ОТЕЧЕСТВЕННЫЕ СЫРЫ КРУПНЫМ И МЕЛКИМ ОПТОМ
В наш ассортимент включены десятки разновидностей сыра на любой вкус по ценам производителей

сыры производства маслосырзавода «Порховский» (Россия) – «Аланталь», «Российский», «Пошехонский», «Костромской», «Голландский» и т.п.;
белорусские сыры «Тильзитер», «Монастырский», «Пошехонский», «Солнечный», «Черный принц» и другие
Приглашаем к обоюдовыгодному сотрудничеству все заинтересованные предприятия и организации любого масштаба, ведь мы реализуем сыр мелким оптом, крупными оптовыми партиями, на самых выгодных и комфортных для заказчиков условиях.
Поставки продукции производятся со склада компании, расположенного на территории Москвы.

http://best-cheese.ru

Calvinshoug on Wednesday, August 21, 2019 at 14:01

Pre-eminent сhildrens porno clips PTHC CP

http://freetexthost.com/sd41adw1k1

freetexthost.com/sd41adw1k1

https://cutit.org/30Gu6

cutit.org/30Gu6

nub on Thursday, August 22, 2019 at 09:38

Whenever you are searching on something inviting, trial this out


https://testpage.arpsolutions.com.br/wp/2019/08/12/life-after-hobbies-2/

ShawnCurry on Thursday, August 22, 2019 at 22:14

<a href=https://www.altredo.com/forex.aspx>FOREX ROBOT</a> DOUBLE PROFIT
⭐️⭐️⭐️⭐️⭐️
https://www.altredo.com/forex.aspx
Forex Robot Double Profit is new excellent reliable and accurate fully automated forex trading system. Works for any broker Metatrader 4 trading platform. Forex Robot Double Profit has built in maximum spread and slippage filters to ensure that you will only get the highest probability trades. Forex Robot Double Profit can grow the smallest of deposits into huge amounts fully automated.
✅ High win rate
✅ Low Risk
✅ Excellent support
✅ Shows excellent consistency over different market conditions
✅ Takes multiple trades each day
✅ Delivers consistent forex investment returns fully automatically
✅ It is ready to use straight out of the box with the default settings although you may wish to adjust the risk.
<a href=https://www.altredo.com/forex.aspx>Download FOREX ROBOT</a> now!

nub on Friday, August 23, 2019 at 01:58

If you are looking for something intriguing, inhibit this observable


https://aticruz.com/circumstance-home-entertainment-recommendations-3/

LucasamaRo on Friday, August 23, 2019 at 03:30

SPECIAL OFFER !!!

<a href=http://tiny.cc/z62lbz>buy viagra</a> online no prescription

LINK ---> http://tiny.cc/z62lbz

Add a comment

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

Comment: