Linux Commands Examples

A great documentation place for Linux commands


preallocate space to a file

see also : truncate


fallocate [-n] [-o offset] -l length filename

add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!


fallocate -l 512m /mnt/swap
chmod 600 /mnt/swap
mkswap /mnt/swap


fallocate is used to preallocate blocks to a file. For filesystems which support the fallocate system call, this 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.

As of the Linux Kernel v2.6.31, the fallocate system call is supported by the btrfs, ext4, ocfs2, and xfs filesystems.

The exit code returned by fallocate is 0 on success and 1 on failure.


The length and offset arguments may be followed by binary (2^N) suffixes KiB, MiB, GiB, TiB, PiB and EiB (the "iB" is optional, e.g. "K" has the same meaning as "KiB") or decimal (10^N) suffixes KB, MB, GB, PB and EB.
-h, --help

Print help and exit.

-n, --keep-size

Do not modify the apparent length of the file. This may effectively allocate blocks past EOF, which can be removed with a truncate.

-o, --offset offset

Specifies the beginning offset of the allocation, in bytes.

-l, --length length

Specifies the length of the allocation, in bytes.


The fallocate command is part of the util-linux package and is available from

see also

fallocate, posix_fallocate, truncate


Eric Sandeen <sandeen[:at:]redhat[:dot:]com>
Karel Zak <kzak[:at:]redhat[:dot:]com>

How can this site be more helpful to YOU ?

give  feedback