2

I have an empty ext4 formated hard disk and would like to create a single file that takes up all available disk space. And I would like to know the size of this file before creating it.

My approach was to run 'df -k' to get the available space and then to use fallocate to allocate the file. However, I am not able to create a file of the size equal to the available space 'df -k' reports. Fallocate fails and creates a file smaller then expected.

Here‘s my output (translated):

#df -k /media/hlx24
FileSystem     1K-Blocks Used Available Avail% Mounted on
/dev/sdx       7813225344   94232 7813114728    1% /media/hlx24

#fallocate -l 8000629481472 /media/hlx24/test.dat
fallocate: fallocate failed: Insufficient disk space

# df -k /media/hlx24
FileSystem     1K-Blocks Used Available Avail% Mounted on
/dev/sdx       7813225344 7813208960         0  100% /media/hlx24

# ls -l /media/hlx24
Total 7813114744
drwx------ 2 root root         16384 Mär 15 17:33 lost+found
-rw-r--r-- 1 root root 8000628617216 Mär 23 16:41 test.dat

Seems like there is some metadata / overhead not taken into account by df. Any idea how to tackle this?

Filesystem was created with: mkfs.ext4 -m 0 -i 67108864 -O ^has_journal /dev/sdx

0 Answers0