Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I was trying to figure this out but found myself clueless: How can I figure out the name of the device (e.g. /dev/sdb2) for a given file/inode? e.g.

[root@serv07 /]# ls -i /etc/passwd
38357228 /etc/passwd

Now, I know that inode 38357228 (or passwd) resides on /dev/sda2 but how can I figure that out for any given/random file(s)? Any help would be useful. Cheers!!

share|improve this question

3 Answers 3

up vote 3 down vote accepted

You can use df

df -P filename

will give you something like:

Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/root      280496152 31269088 235090852  12% /

-P is --portability to get POSIX output

Just to be convenient:

df -P filename | awk 'NR==2{print $1}'

Will give you just the device

share|improve this answer
    
that did the job nicely. Thanks! –  MacUsers Mar 14 '12 at 19:05

You can get the mount point for a given file with stat:

$ stat -c '%m' /etc/fstab
/

You can use this to look up what is mounted there using /proc/mounts

awk '$2 == "/"'  /proc/mounts
share|improve this answer
    
I don't see any %m format option in my version of stat; tried on RHEL/CentOS and Ubuntu - none of them has that. What distro are you on? Cheers! –  MacUsers Mar 14 '12 at 19:04

You can use the stat command. See this question on Stack Exchange for the gory details:

http://stackoverflow.com/questions/4309882/device-number-in-stat-command-output

share|improve this answer
    
thanks for the useful link. Cheers!! –  MacUsers Mar 14 '12 at 19:23

Your Answer

 
discard

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.