Skip to contentSkip to conversation

workaround for buggy GNU df

DISCUSSION Ulli Horlacher 4 participants 6 messages Jun 21, 2024 – Mar 7 Btrfs file system

lore
Share & tools
lore
#0 lore raw

The GNU tool df does not work correctly on btrfs, example:

root@fex:/test/test/test# df -T phoon.png
Filesystem     Type 1K-blocks     Used Available Use% Mounted on
-              -     67107840 16458828  47946692  26% /test/test
root@fex:/test/test/test# grep /test /proc/mounts || echo nope
nope

The mountpoint is wrong, the kernel knows the truth.

Therefore I have written fst:

root@fex:/test/test/test# fst phoon.png
path:       /test/test/test/phoon.png
mountpoint: /
subvolume:  /test/test
volume:     /dev/sdd1
filesystem: btrfs

https://fex.belwue.de/linuxtools/index.html#fst

Signature · 6 lines
Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum TIK
Universitaet Stuttgart         E-Mail: [email protected]
Allmandring 30a                Tel:    ++49-711-68565868
70569 Stuttgart (Germany)      WWW:    https://www.tik.uni-stuttgart.de/
REF:<[email protected]>
#1 lore raw
Quoted 10 lines · Ulli Horlacher

The GNU tool df does not work correctly on btrfs, example:

root@fex:/test/test/test# df -T phoon.png
Filesystem     Type 1K-blocks     Used Available Use% Mounted on
-              -     67107840 16458828  47946692  26% /test/test
root@fex:/test/test/test# grep /test /proc/mounts || echo nope
nope

The mountpoint is wrong, the kernel knows the truth.

How did you get this to happen?

#2 lore raw
Quoted 6 lines · Phillip Susi
Quoted 6 lines

The GNU tool df does not work correctly on btrfs, example:

root@fex:/test/test/test# df -T phoon.png
Filesystem     Type 1K-blocks     Used Available Use% Mounted on
-              -     67107840 16458828  47946692  26% /test/test
Quoted 6 lines
Quoted 4 lines
root@fex:/test/test/test# grep /test /proc/mounts || echo nope
nope

The mountpoint is wrong, the kernel knows the truth.

How did you get this to happen?

Very easy to replicate.  If you call df with a path, it prints the location of the subvolume in the "Mounted As" column.  No other steps necessary.

#3 lore raw
Quoted 10 lines · Remi Gauvin
Quoted 9 lines · Phillip Susi
Quoted 9 lines

The GNU tool df does not work correctly on btrfs, example:

root@fex:/test/test/test# df -T phoon.png
Filesystem     Type 1K-blocks     Used Available Use% Mounted on
-              -     67107840 16458828  47946692  26% /test/test
root@fex:/test/test/test# grep /test /proc/mounts || echo nope
nope
Quoted 9 lines
Quoted 3 lines
Quoted 1 line

The mountpoint is wrong, the kernel knows the truth.

How did you get this to happen?

Very easy to replicate.  If you call df with a path, it prints the location of the subvolume in the "Mounted As" column.  No other steps necessary.

bor@tw:~> df -T /home
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda2 btrfs 39835648 20799988 16982220 56% /home
bor@tw:~> df -T /home/bor
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda2 btrfs 39835648 20799988 16982220 56% /home
bor@tw:~> df -T /home/bor/bin
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda2 btrfs 39835648 20799988 16982220 56% /home
bor@tw:~>

#4 lore raw
Quoted 22 lines · Andrei Borzenkov
Quoted 10 lines · Remi Gauvin
Quoted 9 lines · Phillip Susi
Quoted 9 lines

The GNU tool df does not work correctly on btrfs, example:

root@fex:/test/test/test# df -T phoon.png
Filesystem     Type 1K-blocks     Used Available Use% Mounted on
-              -     67107840 16458828  47946692  26% /test/test
root@fex:/test/test/test# grep /test /proc/mounts || echo nope
nope
Quoted 9 lines
Quoted 3 lines
Quoted 1 line

The mountpoint is wrong, the kernel knows the truth.

How did you get this to happen?

Very easy to replicate.  If you call df with a path, it prints the location of the subvolume in the "Mounted As" column.  No other steps necessary.

Quoted 9 lines

bor@tw:~> df -T /home
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda2 btrfs 39835648 20799988 16982220 56% /home
bor@tw:~> df -T /home/bor
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda2 btrfs 39835648 20799988 16982220 56% /home
bor@tw:~> df -T /home/bor/bin
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda2 btrfs 39835648 20799988 16982220 56% /home

You have no subvolumes in /home, therefore no problems with df output. Try:

framstag@watschel:~: btrfs sub create tmp/test
Create subvolume 'tmp/test'

framstag@watschel:~: df -H tmp/test

Filesystem      Size  Used Avail Use% Mounted on
-               199G  154G   44G  78% /local/home/framstag/tmp/test

framstag@watschel:~: fst tmp/test

Path:       /local/home/framstag/tmp/test
Mountpoint: /local
Subvolume:  /local/home/framstag/tmp/test
Volume:     /dev/sdc3
Filesystem: btrfs
Signature · 6 lines
Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum TIK
Universitaet Stuttgart         E-Mail: [email protected]
Allmandring 30a                Tel:    ++49-711-68565868
70569 Stuttgart (Germany)      WWW:    https://www.tik.uni-stuttgart.de/
REF:<[email protected]>
#5 lore raw
In reply to Ulli Horlacher
Quoted 22 lines · Ulli Horlacher

The GNU tool df does not work correctly on btrfs, example:

root@fex:/test/test/test# df -T phoon.png
Filesystem     Type 1K-blocks     Used Available Use% Mounted on
-              -     67107840 16458828  47946692  26% /test/test
root@fex:/test/test/test# grep /test /proc/mounts || echo nope
nope

The mountpoint is wrong, the kernel knows the truth.

Therefore I have written fst:

root@fex:/test/test/test# fst phoon.png
path:       /test/test/test/phoon.png
mountpoint: /
subvolume:  /test/test
volume:     /dev/sdd1
filesystem: btrfs
Quoted 1 line

https://fex.belwue.de/linuxtools/index.html#fst

I have now extended fst to fstat :

framstag@fex:/local/test/.snapshot/.latest/test: fstat zz

      File: "zz"
 Directory: /local/test/.snapshot/2025-09-05_1917.test/test
      Size: 40 B

Allocation: 4 kB
Type: regular file
Mode: rw-r--r--
UID: root
GID: root
Device: /dev/sde1
FS-Type: btrfs
Mountpoint: /local (rw)
Subvolume: /local/test/.snapshot/2025-09-05_1917.test (ro)

     Inode: 5107
     Links: 1
    Access: 2025-06-18 10:22:51
    Modify: 2024-05-20 02:02:08
    Change: 2024-06-03 10:58:22
     Birth: 2024-06-03 10:58:22

fstat also shows the btrfs subvolume and its rw/ro status.

framstag@fex:/local/test/.snapshot/.latest/test: df --version df (GNU coreutils) 9.4

framstag@fex:/local/test/.snapshot/.latest/test: df -T .
Filesystem Type 1K-blocks Used Available Use% Mounted on
- - 1073740800 82884012 989711428 8% /local/test/.snapshot/2025-09-05_1917.test

framstag@fex:/local/test/.snapshot/.latest/test: grep /local /proc/mounts /dev/sde1 /local btrfs rw,relatime,space_cache,user_subvol_rm_allowed,subvolid=5,subvol=/ 0 0

==> df cannot handle btrfs!

https://fex.belwue.de/fstools/fstat.html

Signature · 6 lines
Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum TIK
Universitaet Stuttgart         E-Mail: [email protected]
Allmandring 30a                Tel:    ++49-711-68565868
70569 Stuttgart (Germany)      WWW:    https://www.tik.uni-stuttgart.de/
REF:<[email protected]>