On an Android Nougat (7.1.1) set top box, du
and df
of my /data
partition are very different:
$ adb shell du -sh /data
1.0G /data
$ adb shell df -H /data
Filesystem Size Used Avail Use% Mounted on
/dev/block/sda9 10G 10G 469M 96% /data
I don’t think that anything else is mounted under /data
:
$ adb shell mount | grep "\/data"
/dev/block/sda9 on /data type ext4 (rw,seclabel,nosuid,nodev,relatime,discard,noauto_da_alloc,data=ordered)
$ adb shell mount | grep "sda9"
/dev/block/sda9 on /data type ext4 (rw,seclabel,nosuid,nodev,relatime,discard,noauto_da_alloc,data=ordered)
lsof
indicates to me that there are dozens of processes holding hundreds of small deleted files of the sort
init 1 root 3w CHR 1,11 0t0 14517 /dev/__kmsg__ (deleted)
ueventd 391 root 3w CHR 1,11 0t0 14593 /dev/__kmsg__ (deleted)
. . .
main 756 root mem unknown /dev/ashmem/dalvik-large object space allocation (deleted)
main 756 root mem unknown /dev/ashmem/dalvik-large object space allocation (deleted)
. . .
omm.times 3934 system mem unknown /dev/ashmem/dalvik-mark sweep sweep array free buffer (deleted)
omm.times 3934 system mem unknown /dev/ashmem/dalvik-mark sweep sweep array free buffer (deleted)
Using busybox
, results are different (df
shows much less usage), but there is still a large discrepancy between du
and df
:
$ adb shell busybox du -sh /data
389.4M /data
$ adb shell busybox df -h /data
Filesystem Size Used Available Use% Mounted on
/dev/block/bootdevice/by-name/userdata
9.7G 8.6G 1.1G 89% /data
And using toybox
, the results are similar to busybox
:
$ adb shell toybox du -sh /data
389M /data
$ adb shell toybox df -h /data
Filesystem Size Used Avail Use% Mounted on
/dev/block/sda9 10G 8.6G 1.1G 89% /data
It think that it's important to note that these numbers remain similar after a reboot.
Also, I wish to note that I cannot OTA update this device's Android due to running out of disk space, even though the OTA image is only about 1GB in size. This fact leads me to believe that the results of df
are accurate in terms of actual available disk space.
All adb commands are run as root i.e., I did adb root
before executing them. But at risk of making this question be too verbose, here's everything run at the adb prompt:
$ adb shell
Z:/ # whoami
root
Z:/ # du -sh /data
389M /data
Z:/ # df -h /data
Filesystem Size Used Avail Use% Mounted on
/dev/block/sda9 10G 8.6G 1.1G 89% /data
10.197.12.14:/ # busybox du -sh /data
389.4M /data
Z:/ # busybox df -h /data
Filesystem Size Used Available Use% Mounted on
/dev/block/bootdevice/by-name/userdata
9.7G 8.6G 1.1G 89% /data
Z:/ # toybox du -sh /data
389M /data
Z:/ # toybox df -h /data
Filesystem Size Used Avail Use% Mounted on
/dev/block/sda9 10G 8.6G 1.1G 89% /data
Z:/ #
A user in comments has asked for the following:
Z:/ # while read num; do (( sum += num )); done <<< $(find /data -type f -exec stat -c%b {} +); expr $sum / 2048
393
I understand that du
reports free space by scanning reachable nodes, and that this could therefore mean that my file system is corrupt. However, unfortunately, this is for devices in the field, and I don’t want to have to (and don’t think I can) run fsck
or e2fsck
.
What might be causing the huge difference between du
and df
on this device, and how might this problem be resolved? I’m happy to provide further logs.
df
anddu
mostly differ somewhat (see here why) but not that much. There seems to be some problem with yourdu
binary. Use a different one. See here what you should expect: How disk space is used on Android device?df
can report the "free space" (aka "Disk Free") normally – whiledu
can only sum up what the user has access to. Nothing broken, works as designed. Try both as root, see the screenshot by @alecxs