linux:debian:map-lba
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| linux:debian:map-lba [2022/10/01 06:23] – oscar | linux:debian:map-lba [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Map LBA to File ====== | ||
| - | You might see something like this on your console / dmesg: | ||
| - | < | ||
| - | [ 394.051961] end_request: | ||
| - | [ 394.055674] Buffer I/O error on device sda3, logical block 8800768 | ||
| - | </ | ||
| - | In this situation you can use the following assumptions: | ||
| - | * The bad sector / LBA is 128999424 (L) | ||
| - | * The bad block is 8800768 in the filesystem on sda3 (b) | ||
| - | |||
| - | ===== How to: ===== | ||
| - | For this example, I'll be using the following information. The second line of the output above was not provided, we need to calculate the logical block offset first. | ||
| - | |||
| - | **Bad LBA = 0x0a8ae67d = 176875133** | ||
| - | |||
| - | ===Find out the partition=== | ||
| - | < | ||
| - | $ sudo fdisk -lu /dev/sda | ||
| - | |||
| - | Disk /dev/sda: 500.1 GB, 500107862016 bytes | ||
| - | 255 heads, 63 sectors/ | ||
| - | Units = sectors of 1 * 512 = 512 bytes | ||
| - | Disk identifier: 0x030818eb | ||
| - | |||
| - | | ||
| - | / | ||
| - | / | ||
| - | / | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | Therefore this LBA is on partition: /dev/sda4 | ||
| - | |||
| - | ===Get block size of the partition=== | ||
| - | < | ||
| - | $ sudo tune2fs -l /dev/sda4 | grep Block | ||
| - | Block count: | ||
| - | Block size: 4096 | ||
| - | Blocks per group: | ||
| - | </ | ||
| - | This partition has block size: 4096 | ||
| - | ===Calculate the block=== | ||
| - | < | ||
| - | b = (int)(((L-S)*512)/ | ||
| - | |||
| - | where: | ||
| - | |||
| - | b = File System block number | ||
| - | B = File system block size in bytes | ||
| - | L = LBA of bad sector | ||
| - | S = Starting sector of partition as shown by fdisk -lu | ||
| - | </ | ||
| - | Denotes the integer part (round it DOWN to a whole number). | ||
| - | < | ||
| - | b = (int)((176875133-172376127) * 512 / 4096) | ||
| - | b = (int)562375.75 | ||
| - | b = 562375 | ||
| - | </ | ||
| - | The block on this partition corresponding to this LBA is: 562375 | ||
| - | ===Identify the file=== | ||
| - | Use debugfs to locate the inode stored in this block, and the file that contains that inode: | ||
| - | < | ||
| - | $ sudo debugfs | ||
| - | |||
| - | debugfs 1.41.9 (22-Aug-2009) | ||
| - | debugfs: | ||
| - | debugfs: | ||
| - | Block 562375 marked in use | ||
| - | debugfs: | ||
| - | Block Inode number | ||
| - | 562375 | ||
| - | debugfs: | ||
| - | Inode | ||
| - | 132344 | ||
| - | debugfs: | ||
| - | </ | ||
| - | Or if the block appears not in use anymore: | ||
| - | < | ||
| - | $ sudo debugfs | ||
| - | debugfs 1.41.9 (22-Aug-2009) | ||
| - | debugfs: | ||
| - | debugfs: | ||
| - | Block 562375 not in use | ||
| - | debugfs: | ||
| - | </ | ||
| - | |||
linux/debian/map-lba.1664605383.txt.gz · Last modified: by oscar
