LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to find physical location of a file on the HDD? (https://www.linuxquestions.org/questions/linux-general-1/how-to-find-physical-location-of-a-file-on-the-hdd-679215/)

CJS 10-26-2008 06:35 PM

How to find physical location of a file on the HDD?
 
How would I find which physical sectors on the HDD a file occupies? I noticed that when I do:
Code:

ls -i
It will give me the index number of the file, but then could I use that to find where the file is on the HDD? Thanks in advance.

raskin 10-26-2008 06:51 PM

What is the location of the file? There is inode (file metadata), extra xattr nodes (usually none), and data blocks. If your file is rather big (I think no FS has default block size of more than 16*1024 bytes on a HDD less than 1TB), it will have to be split. With some luck the fragments will be one near other on the disk, but there is some additional information in every block (like a pointer to the next block of the file).

I think GRUB is a good place to see FS read-only implementations

CJS 01-18-2009 10:14 AM

In case anyone else is interested, I did find a solution to my question, so I thought I would post it. It turns out you can use the "filefrag" command to find the physical location of a file:
Code:

filefrag -v myfile.txt
It gives an output like:
Code:

Checking myfile.txt
Filesystem type is: ef53
Filesystem cylinder groups is approximately 115
Blocksize of file myfile.txt is 4096
File size of myfile.txt is 121460 (30 blocks)
First block: 2209841
Last block: 2212769
Discontinuity: Block 7 is at 2211636 (was 2209847)
Discontinuity: Block 11 is at 2211645 (was 2211639)
Discontinuity: Block 13 is at 2211925 (was 2211647)
Discontinuity: Block 14 is at 2211931 (was 2211925)
Discontinuity: Block 19 is at 2211966 (was 2211935)
Discontinuity: Block 26 is at 2212669 (was 2211972)
Discontinuity: Block 29 is at 2212769 (was 2212671)
myfile.txt: 8 extents found, perfection would be 1 extent

4096 * 2209841 = 9,051,508,736, so that means the file starts about 9 GB into the partition.


All times are GMT -5. The time now is 11:15 AM.