2

I get different output for the same device with df if I call it without arguments or with the device as an argument. Running Ubuntu 14.04.

Without arguments:

➜  ~ df
Filesystem      1K-blocks       Used  Available Use% Mounted on
udev              4046644          4    4046640   1% /dev
tmpfs              811488       2532     808956   1% /run
/dev/sdb1       299337328   39634680  244474080  14% /
/dev/sda1      2884152536 1309806024 1427816876  48% /media/videos
...

With /dev/sdb1 as the argument I get a different result for the same device:

➜  ~ df /dev/sdb1
Filesystem     1K-blocks  Used Available Use% Mounted on
udev             4046644     4   4046640   1% /dev

With /dev/sda1 it seems to work:

➜  ~ df /dev/sda1
Filesystem      1K-blocks       Used  Available Use% Mounted on
/dev/sda1      2884152536 1309806024 1427816876  48% /media/videos

/dev/sdb1 is the where the OS is installed.

Why is the output different for /dev/sdb1 but works for /dev/sda1?

Output from ls

➜  ~  ls -l /dev/sda1 /dev/sdb1
brw-rw---- 1 root disk 8,  1 tammi  5 21:13 /dev/sda1
brw-rw---- 1 root disk 8, 17 tammi  5 21:13 /dev/sdb1

Output from tune2fs

➜  #  tune2fs -l /dev/sda1 | grep 'Last mount' 
Last mounted on:          /media/videos
Last mount time:          Tue Jan  5 21:13:15 2016
➜  #  tune2fs -l /dev/sdb1 | grep 'Last mount'
Last mounted on:          /
Last mount time:          Tue Jan  5 21:13:14 2016
➜  ~  last reboot
reboot   system boot  3.13.0-62-generi Tue Jan  5 21:13 - 02:04 (1+04:51)   

More system info:

➜  ~  uname -svpio
Linux #102-Ubuntu SMP Tue Aug 11 14:29:36 UTC 2015 x86_64 x86_64 GNU/Linux

➜  ~  X=$(df | sed -rn 's,^(/[^ ]*) .*,\1,p') ; echo $X
/dev/sdb1
/dev/sda1

➜  ~  df | grep ^/
/dev/sdb1       299337328   39693968  244414792  14% /
/dev/sda1      2884152536 1309897424 1427725476  48% /media/videos

➜  ~  ls -ld /dev/sdb1 ; ls -ld /dev/sda1
brw-rw---- 1 root disk 8, 17 tammi  5 21:13 /dev/sdb1
brw-rw---- 1 root disk 8, 1 tammi  5 21:13 /dev/sda1

➜  ~  df /dev/sdb1 | tail -1; df /dev/sda1 | tail -1 
udev             4046644     4   4046640   1% /dev
/dev/sda1      2884152536 1309897424 1427725476  48% /media/videos

➜  ~  df | sed -rn 's,^(/[^ ]*) .*,<\1>,p'
</dev/sdb1>
</dev/sda1>
mjuopperi
  • 123
  • 1
  • 4
  • Did you notice that the output of `df /dev/sdb1` is identical to the first line of the `df` output? – D34DM347 Jan 05 '16 at 20:01
  • Yes, but the output of `df /dev/sda1`is identical to `df` and I'm calling `df /dev/sdb1` the exact same way. – mjuopperi Jan 05 '16 at 21:15
  • It almost looks like you have a space in your command so you are issuing something like `df /dev/ sdb1` instead of `df /dev/sdb1`. – Zoredache Jan 05 '16 at 22:45
  • Please provide output from `ls -l /dev/sda1 /dev/sdb1`. My thinking is that device `/dev/sdb1` either doesn't exist on your running system (but did exist in the initramfs) or that it exists but points to a different device than for the initramfs. – roaima Jan 05 '16 at 23:06
  • @roaima Added to original question for better formatting. Copy pasted directly from terminal. – mjuopperi Jan 06 '16 at 22:47
  • @Zoredache That's not it. I copied and pasted the commands from terminal and I rewrote my command multiple times because I initially suspected a typo. – mjuopperi Jan 06 '16 at 22:49
  • Thank you for `ls -l ...`. Please could I now have output from these two commands: `tune2fs -l /dev/sda1 | grep 'Last mount'` and `tune2fs -l /dev/sdb1 | grep 'Last mount'`. Do they match your expectation? – roaima Jan 06 '16 at 22:56
  • When you execute `df`, you get a list of all the devices, and that is normal. Your question should be "Why do I get different results when executing `df /dev/sda1` and `df /dev/sdb1`? When I execute `df /dev/sda1` it recognizes that /dev/sda1 is a block device containing a filesystem and outputs the result for that filesystem, but when I execute `df /dev/sdb1` I get the results for the filesystem /dev containing the special file /dev/sdb1." You seem to want the first behavior, I feel that the second is normal, but I think we can agree that there should not be two different behaviors. – Law29 Jan 06 '16 at 23:07
  • @Law29 the behaviour is documented explicitly in the man page. – roaima Jan 06 '16 at 23:33
  • @roaima Added output from that to the question. Looks good to me. Both mounted at the time of last boot. – mjuopperi Jan 07 '16 at 00:06
  • @roaima so the results for `df /dev/sdb1` seem to be a bug. – Law29 Jan 07 '16 at 07:36
  • @Law29 reluctantly I might have to agree. But it doesn't seem to be a reasonable bug, in that the behaviour shouldn't even need to take different code paths depending on the device name – roaima Jan 07 '16 at 08:14
  • @mjuopperi just to recapitulate all this, could you execute `uname -svpio ; X=$(df | sed -rn 's,^(/[^ ]*) .*,\1,p') ; df | grep ^/ ; echo ; df $X ; for i in $X ; do ls -ld $i ; df $i ; done` Hope that formatting goes through else I'll make this an answer. Just for the record, on my machine one is actually a symlink, and I still don't get /dev. – Law29 Jan 07 '16 at 19:27
  • @Law29 I split that up to single commands because at least the for loop was not playing nice for some reason. Hopefully I got it right. Added to original question. – mjuopperi Jan 07 '16 at 21:40
  • @mjuopperi maybe there's a connection between the two bizarre behaviors. I may very well be wrong here, it's just to be quite certain, but can you try `df | sed -rn 's,^(/[^ ]*) .*,<\1>,p'`? – Law29 Jan 08 '16 at 07:27
  • @Law29 added to question. – mjuopperi Jan 08 '16 at 13:51
  • Well really I don't know. On my machine this works. If this was my machine and I had several hours to identify the problem, at this point I would probably `strace` the two invocations and look for the differences. – Law29 Jan 08 '16 at 22:04

1 Answers1

0

Use mountpoint instead of filesystem for this.

So going by what you have here:

Filesystem      1K-blocks       Used  Available Use% Mounted on
udev              4046644          4    4046640   1% /dev
tmpfs              811488       2532     808956   1% /run
/dev/sdb1       299337328   39634680  244474080  14% /
/dev/sda1      2884152536 1309806024 1427816876  48% /media/videos

If you want to properly query /dev/sda1 you should use:

df /media/videos

If you want to properly query /dev/sdb1 you should use:

df /

What I believe is happening is that when you do df /dev/sdb1 it's interpreting it as df /dev, which is the mount for udev. As for df /dev/sda1 working - I'm going to have file that in the "heck if I know" bin. Seems like a bug.

To further test things - if you try the below you'll notice that both will fail:

df tmpfs
df udev
Bradley Forney
  • 246
  • 2
  • 5
  • 1
    I think you're right. `df /dev/sdb1` and `df /dev` return the same value and using the mount points work. – mjuopperi Apr 01 '16 at 06:00