How to find the location of the file on hard drive in the terms of sector
Nov 07, 2006 4 Replies
N
Nutty
Hello to all,
Can anyone please help me out.........
Suppose i create one file and store that file on the hard drive. Is it possible to find the location of the file on hard drive in the terms of sector. Like the file is stored at the sectors 33,34 ...
PLEASE HELP ME...
Thanks and Regards, Nutty
Didn't find your answer? Ask the community — no account required.
S
Stephane CHAZELAS
2006-11-7, 05:15(-08), Nutty:
[...]
If the filesystem is ext2/ext3, see the debugfs command.
You can then issue a stat /path/to/file
That will give you the block numbers.
That will give you an offset from the start of the partition in blocks (stats command to get the block size).
You can use fdisk to find out about where the partition starts and the (at least logical) geometry of the disk.
debugfs: stats [...] Block size: 4096 [...] ~$ sudo dd if=/dev/hda7 bs=4096 skip=751206 count=1 | od -c | head -3
1+0 records in
1+0 records out
4096 bytes (4.1 kB) copied, 7.8941e-05 seconds, 51.9 MB/s
0000000 r o o t : x : 0 : 0 : r o o t :
0000020 / r o o t : / b i n / b a s h \n
0000040 d a e m o n : x : 1 : 1 : d a e ~$ sudo fdisk -lu /dev/hda | grep hda7 /dev/hda7 17543043 31214294 6835626 83 Linux ~$ sudo dd if=/dev/hda bs=512 skip=$((751206*8+17543043)) count=8 | od -c | head
-3
8+0 records in
8+0 records out
4096 bytes (4.1 kB) copied, 0.00174803 seconds, 2.3 MB/s
0000000 r o o t : x : 0 : 0 : r o o t :
0000020 / r o o t : / b i n / b a s h \n
0000040 d a e m o n : x : 1 : 1 : d a e
Stéphane
T
Tauno Voipio
Before you proceed with the questions for the Linux internals, please DO GET a book of the general organization of the kernel, read and understand it.
My favourite for starters:
Daniel Pierre Bovet, Marco Cesati, Understanding the Linux Kernel, 3rd ed, O'Reilly, ISBN 0-596-00565-2.
This book explains also the file system general organization. The exact response to your question depends on the partitioning of the disk and the file system type and parameters.
Tauno Voipio
tauno voipio (at) iki fi
M
Michael Schnell
You can't tell unless you know the file system used.
There are many file systems Linux can use. Some are even compressed and maybe a file can start in the middle of a sector. Moreover even if you know where a file starts it can get very complicated to find where it continues, as with nearly all file systems files can get segmented.
-Michael
I
Iwo Mergler
You may want to look at the source code of 'LILO'. When invoked, Lilo finds out the list of blocks (sectors) which correspond to the kernel image.
It supports a lot of filesystems.
Kind regards,
Iwo
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.