Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way I can see which sectors of the hard disk a given file occupies?

The filesystem is ext3 or ext4 on Linux.

share|improve this question
Of course there is a way but it is not exactly what one would call "easy". What are you trying to accomplish? – msw Jun 22 '10 at 5:08
I'm performing an operation that requires reading a large amount of input data, and I want to pinpoint the cause of some anomalies in the performance of the reading. I want to know whether there is a correlation between the read performance and the physical layout of the input files on disk. This requires knowing what the physical layout of the input files is on the disk. – HighCommander4 Jun 22 '10 at 7:22
up vote 2 down vote accepted

If you are looking for blocks for file /tmp/squiggle/smurf.tgz, in the /tmp/ filesystem, mounted from /dev/sdg4, you would type:

# debugfs /dev/sdg4
> bmap /squiggle/smurf.tgz 0
> bmap /squiggle/smurf.tgz 1
> bmap /squiggle/smurf.tgz 2
> bmap /squiggle/smurf.tgz 3

Is that what you're looking for?

share|improve this answer
Yes, this seems to be what I'm looking for. I have a couple of follow-up questions: 1) Is there a way to do this without root privileges? 2) Can this be scripted, or can these numbers be queried programmatically? – HighCommander4 Jun 22 '10 at 7:23
It should be scriptable. I'd say piping your commands in on stdin would probably do the trick. Be very careful with that though, as you can do a LOT of damage to a filesystem with debugfs. As for doing this without root priv's, I don't know, but I suspect not. The filesystem is intended to be an abstraction that hides those details from the user. – Slartibartfast Jun 23 '10 at 2:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.