Df and lsblk shows different disk size

Here is the output

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                19.5G     54.5M     18.4G   0% /
tmpfs                     1.8G      1.8M      1.8G   0% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/sda3               162.5G      2.0M    154.2G   0% /home
root@OpenWrt:~# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0 186.3G  0 disk
├─sda1   8:1    0   100M  0 part
├─sda2   8:2    0    20G  0 part /
└─sda3   8:3    0 166.2G  0 part /home

my disk is 200GB and lsblk's result is right when changing to GiB

hi,

it is not really owrt related but anyhow check below:

$:~# df --help
BusyBox v1.36.1 (2023-11-14 13:38:11 UTC) multi-call binary.

Usage: df [-PkmhT] [-t TYPE] [FILESYSTEM]...

Print filesystem usage statistics

        -P      POSIX output format
        -k      1024-byte blocks (default)
        -m      1M-byte blocks
        -h      Human readable (e.g. 1K 243M 2G)
        -T      Print filesystem type
        -t TYPE Print only mounts of this type

$:~# df -k | grep /dev/root
/dev/root               517492    324912    182096  64% /
root@OpenWrt-23.05.2-sda2:~# df -m | grep /dev/root
/dev/root                  505       317       178  64% /

$:~# echo $(( 505 * 1024 )) $(( 505 * 1000 ))
517120 505000

what you can see
a) df represents byte size in blocks
b) size of block varies, -k uses 1024-byte but -m uses 1M-byte block.
c) in generic there is a constant confusion what K/M means, 1024 or 1000, but in disk world it is even worse (manufacturers count with 1000 ...)

if we multiple 505 (coming from -m 1M-block) either with 1024 or 1000 none of them will match exactly with (-k) 517492 ...

so it is more of a rounding, representation problem even within the same tool (df) so unless you use the real byte size numbers there will be always difference between df and lsblk. but never compare -h (human readable) with a fixed block numbers.

1 Like

The "df" command shoes the size of the filesystem, while "lsblk" shows the size of the underlying block device.

The size of a warehouse does not equal the total size of the boxes that you can store inside.

1 Like