{"id":354,"date":"2017-12-28T12:25:57","date_gmt":"2017-12-28T12:25:57","guid":{"rendered":"https:\/\/mellowhost.com\/blog\/?p=354"},"modified":"2017-12-28T12:28:37","modified_gmt":"2017-12-28T12:28:37","slug":"identifying-file-inode-by-sector-block-number-in-linux","status":"publish","type":"post","link":"https:\/\/mellowhost.com\/blog\/identifying-file-inode-by-sector-block-number-in-linux.html","title":{"rendered":"Identifying File \/ Inode by Sector \/ Block Number in Linux"},"content":{"rendered":"<p>I had an interesting problem earlier today. While running r1soft backup, dmesg was throwing some I\/O like the following:<\/p>\n<blockquote><p>Dec 28 09:28:43 ssd1 kernel: [36701.752626] end_request: I\/O error, dev vda, sector 331781632<br \/>\nDec 28 09:28:43 ssd1 kernel: [36701.755400] end_request: I\/O error, dev vda, sector 331781760<br \/>\nDec 28 09:28:43 ssd1 kernel: [36701.758286] end_request: I\/O error, dev vda, sector 331781888<br \/>\nDec 28 09:28:43 ssd1 kernel: [36701.760992] end_request: I\/O error, dev vda, sector 331780864<\/p><\/blockquote>\n<p>They didn&#8217;t go out after multiple file system checks. That left me no choice other than finding what&#8217;s actually in that sector. I could see the sector numbers was increasing by 128 up 10 sequential logs. That makes to understand it could be a specific account causing the errors.<\/p>\n<p>EXT file system comes with an interesting tool called debugfs. This can be used on mounted file system and can be used to track down IO related issues. Although, you require to do some calculation first to convert sector to block number of a specific partition before you can use debugfs.<\/p>\n<p>The lowest sector number in the log was &#8216;331780864&#8217;. First I tracked down the partition where this sector lies. This can be done using fdisk -lu \/dev\/disk (Make sure to use -u, to ensure fdisk returns the sector numbers instead of cylinder number)<\/p>\n<blockquote><p>#fdisk -lu \/dev\/vda<\/p>\n<p>Disk \/dev\/vda: 1342.2 GB, 1342177280000 bytes<br \/>\n16 heads, 63 sectors\/track, 2600634 cylinders, total 2621440000 sectors<br \/>\nUnits = sectors of 1 * 512 = 512 bytes<br \/>\nSector size (logical\/physical): 512 bytes \/ 512 bytes<br \/>\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<br \/>\nDisk identifier: 0x0002f013<\/p>\n<p>Device Boot Start End Blocks Id System<br \/>\n\/dev\/vda1 * 2048 411647 204800 83 Linux<br \/>\n\/dev\/vda2 411648 205211647 102400000 83 Linux<br \/>\n\/dev\/vda3 205211648 209307647 2048000 82 Linux swap \/ Solaris<br \/>\n\/dev\/vda4 209307648 2621439999 1206066176 83 Linux<\/p><\/blockquote>\n<p>Now, find the Start Number &lt; Our Sector number to detect which block contains our desired sector. In our case, it is \/dev\/vda4. Once done, we need to numeric sector number specifically for this partition, which can be done by subtracting our sector number with start number of the partition. In our case:<\/p>\n<blockquote><p>331780864 &#8211;\u00a0209307648 =\u00a0122473216<\/p><\/blockquote>\n<p>That means, our sector lies in\u00a0122473216th sector of \/dev\/vda4.<\/p>\n<p>Now find the block size by tune2fs:<\/p>\n<blockquote><p># tune2fs -l \/dev\/vda4 | grep Block<br \/>\nBlock count: 301516544<br \/>\nBlock size: 4096<br \/>\nBlocks per group: 32768<\/p><\/blockquote>\n<p>In our case, it is 4096.<\/p>\n<p>Now determine the size of the sectors by bytes. This is shown in fdisk output:<\/p>\n<blockquote><p>Sector size (logical\/physical): 512 bytes \/ 512 bytes<\/p><\/blockquote>\n<p>From the two relations block\/bytes and sector\/bytes, find sector\/block : 512 \/ 4096 = .125<\/p>\n<p>Now, calculate the block number of\u00a0122473216th sector:\u00a0122473216 x .125 =\u00a015309152<\/p>\n<p>We can now use debugfs to determine what file we have on that block number as following:<\/p>\n<blockquote><p>debugfs \/dev\/vda4<\/p><\/blockquote>\n<p>On the debug prompt, type:<\/p>\n<blockquote><p>debugfs: icheck\u00a015309152<\/p>\n<p><em>Block\u00a0\u00a0 Inode number<br \/>\n15309152\u00a0 \u00a02611435<\/em><\/p><\/blockquote>\n<p>This will show the inode number of the desired file. Use the inode number to run:<\/p>\n<blockquote><p>debugfs: ncheck 15309152<\/p>\n<p>Inode\u00a0\u00a0 Pathname<br \/>\n15309152 \/lost+found\/#29938847<\/p><\/blockquote>\n<p>This will show you the desired file that is actually causing the issue. In my case, I could find files that were corrupted in some old fsck, were stored in lost+found and they were missing magic number\/incomplete files. Once I had deleted all the files from lost+found, my issue was resolved. Viola!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had an interesting problem earlier today. While running r1soft backup, dmesg was throwing some I\/O like the following: Dec 28 09:28:43 ssd1 kernel: [36701.752626] end_request: I\/O error, dev vda, sector 331781632 Dec 28 09:28:43 ssd1 kernel: [36701.755400] end_request: I\/O error, dev vda, sector 331781760 Dec 28 09:28:43 ssd1 kernel: [36701.758286] end_request: I\/O error, dev &hellip; <a href=\"https:\/\/mellowhost.com\/blog\/identifying-file-inode-by-sector-block-number-in-linux.html\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Identifying File \/ Inode by Sector \/ Block Number in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[169,12,20,21,150,25],"tags":[172,171,170],"_links":{"self":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/354"}],"collection":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/comments?post=354"}],"version-history":[{"count":3,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/354\/revisions"}],"predecessor-version":[{"id":357,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/354\/revisions\/357"}],"wp:attachment":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/media?parent=354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/categories?post=354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/tags?post=354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}