7

When I execute the df command without parameters, I get the following list of file systems:

Filesystem     1K-blocks     Used Available Use% Mounted on
devtmpfs         8112420        0   8112420   0% /dev
tmpfs            8123692     5732   8117960   1% /dev/shm
tmpfs            8123692    11908   8111784   1% /run
tmpfs            8123692        0   8123692   0% /sys/fs/cgroup
/dev/dm-1      293457920 85102676 208355244  29% /
/dev/sda1        1038336   192912    845424  19% /boot
tmpfs            1624740        0   1624740   0% /run/user/0

However, if I specify a file name, such as /, the file system for the corresponding mount point is displayed under a different name:

Filesystem                                            1K-blocks     Used Available Use% Mounted on
/dev/mapper/luks-609eee17-f9f4-446d-b399-1d5a6d7ddb9c 293457920 85102812 208355108  30% /

I also couldn't find any option that might influence this behavior.

How can I make sure that the same name is displayed for the file system in both cases?

2 Answers 2

12

The output you’re seeing with no parameters is the result of special handling of device names ending in UUIDs:

   if (process_all
       && has_uuid_suffix (dev_name)
       && (resolved_dev = canonicalize_filename_mode (dev_name, CAN_EXISTING)))

This is explained in the comment just above:

On some systems, dev_name is a long-named symlink like /dev/disk/by-uuid/828fc648-9f30-43d8-a0b1-f7196a2edb66 pointing to a much shorter and more useful name like /dev/sda1. It may also look like /dev/mapper/luks-828fc648-9f30-43d8-a0b1-f7196a2edb66 and point to /dev/dm-0. When process_all is true and dev_name is a symlink whose name ends with a UUID use the resolved name instead.

Device names are processed in this way only when all devices are shown, that it to say when df is invoked without arguments (other than options). Furthermore, this processing can’t be disabled, so you can’t ask df with no arguments to show the longer device name instead of the short one.

If you want similar behaviour in both situations, you’d have to post-process the output; something like

df . | awk '{ "readlink " $1 " > /dev/null && readlink -f " $1 | getline replacement; if (replacement != "") $1 = sprintf("%-" length($1) "s", replacement) } 1'

Another possibility is to use findmnt instead of df:

findmnt --df

produces results similar to df, but without post-processing UUID-suffixed device names, and

findmnt --df -T /

works similarly to df / (and works for any kind of file, same as df).

0
5

The result is not the same on all systems.

The behavior depends on the distribution used, maybe the version of coreutils, and/or partly on whether LVM, LUKS, configuration or another system is in use.

On my Debian system with LUKS and LVM, I get the same output for both commands for /.

/dev/mapper/myroot--vg-root ...

It seems to be specific with your setup in your case and as Stephen Kitt has already explained here.

Here you can see if you want to make a one-liner, a custom script, with and or an alias .

Or/and use of findmnt --df or findmnt --df --json to leverage a widely supported parsable format instead.


Use df -P

From @Stephen Kitt comment:

df -P - It’s just a format specifier, it doesn’t influence the device names shown.

... Maybe df in Ubuntu behaves similarly if entries in the Filesystem column are long; maybe you just didn't experience this because yours are relatively short. I don't know, this is not important. What is important is df is a POSIX tool and should follow the specification. But the specification explicitly states.

...

Historical df implementations vary considerably in their default output. It was therefore necessary to describe the default output in a loose manner to accommodate all known historical implementations and to add a portable option (-P) to provide information in a portable format....

-P, --portability use the POSIX output format


More sources:

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.