How to Preallocate Disk Space in aria2?
Configuring aria2 to pre-allocate disk space before starting a large download helps prevent disk fragmentation and ensures that your storage media has sufficient room for the files before investing time and bandwidth. This article explains the benefits of pre-allocation, details the specific command-line options and configuration settings required to enable it, and compares the available allocation methods to help you choose the best one for your file system.
Why Pre-allocate Disk Space?
When downloading large files, especially via BitTorrent or multi-connection HTTP/FTP, data blocks are often written out of order. Without pre-allocation, this leads to heavy file fragmentation, which can degrade storage performance. Pre-allocation reserves the entire file size on the disk immediately when the download begins, ensuring a contiguous block of space and catching “disk full” errors before the download actually wastes your bandwidth.
The Standard Pre-allocation Command
To tell aria2 to allocate disk space before starting a download, you
use the --file-allocation option followed by your chosen
allocation method.
The basic command structure looks like this:
aria2c --file-allocation=falloc "URL"Available Allocation Methods
aria2 supports several different methods for reserving disk space. Choosing the right one depends heavily on your operating system and file system:
none: No pre-allocation occurs. Space is allocated on the fly as data arrives. This is the default setting.prealloc: Allocates the space before the download begins. This method physically writes zeroes to the disk to reserve the space. While highly compatible, it can take a significant amount of time for exceptionally large files.trunc: Uses theftruncate()system call to create a sparse file. It is nearly instantaneous, but it does not actually reserve physical blocks on all file systems, meaning you could still run out of disk space later.falloc: Uses theposix_fallocate()system call. It allocates the actual physical disk space almost instantly without writing dummy data. This is the highly recommended method for modern Linux file systems (like ext4, xfs, and btrfs).
Making Pre-allocation Permanent
If you do not want to type the command every time, you can add this
behavior to your global aria2 configuration file (usually located at
~/.config/aria2/aria2.conf or
~/.aria2/aria2.conf).
Open your configuration file and add the following line:
file-allocation=falloc
Note for Windows Users: The
fallocmethod is not supported on Windows. If you are using Windows with an NTFS file system,preallocis the safest choice for true allocation, though it will take some time to initialize large files. Alternatively,trunccan be used for instant startup if you are certain you have enough disk space.