Way to instantly fill up/use up lots of disk space?

The fastest way to create a file in a Linux system is using fallocate:

fallocate -l 50G file 

From man:

fallocate is used to manipulate the allocated disk space for a file, either to deallocate or preallocate it.
For filesystems which support the fallocate system call, preallocation is done quickly by allocating blocks and marking them as uninitialized, requiring no IO to the data blocks. This is much faster than creating a file by filling it with zeros.
Supported for XFS (since Linux 2.6.38), ext4 (since Linux 3.0), Btrfs (since Linux 3.7) and tmpfs (since Linux 3.5).


Other alternatives include:

  1. to change the alarm thresholds to something near or below the current usage, or
  2. to create a very small test partition with limited inodes, size, or other attributes.

Being able to test things such as running into the root reserved percentage, if any, may also be handy.


  1. fallocate -l 50G big_file

  2. truncate -s 50G big_file

  3. dd of=bigfile bs=1 seek=50G count=0

As those three ways can all fill up a partition quickly.

If you like use dd, usually you can try it with seek. Just set seek=file_size_what_you_need and set count=0. That will tell the system there is a file, and its size is what you set, but the system will not create it actually. And used this way, you can create a file which is bigger than the partition size.


Example, on an ext4 partition with less than 3G available. Use dd to create a 5T file which exists as metadata -- requiring virtually no block space.

df -h . ; dd of=biggerfile bs=1 seek=5000G count=0 ; ls -log biggerfile ; df -h .

Output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda9        42G   37G  2.8G  94% /home
0+0 records in
0+0 records out
0 bytes copied, 4.9296e-05 s, 0.0 kB/s
-rw-rw-r-- 1 5368709120000 Jun 29 13:13 biggerfile
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda9        42G   37G  2.8G  94% /home