{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"mergerfs - a featureful union filesystem","text":"
mergerfs is a FUSE based union filesystem geared towards simplifying storage and management of files across numerous commodity storage devices. It is similar to mhddfs, unionfs, and aufs.
"},{"location":"#features","title":"Features","text":"mergerfs logically merges multiple filesystem paths together. It acts as a proxy to the underlying filesystem paths. Combining the behaviors of some functions and being a selector for others.
When the contents of a directory are requested mergerfs combines the list of files from each directory, deduplicating entries, and returns that list.
When a file or directory is created a policy is first run to determine which branch will be selected for the creation.
For functions which change attributes or remove the file the behavior may be applied to all instances found.
Read more about policies here.
"},{"location":"#visualization","title":"Visualization","text":"A + B = C\n/disk1 /disk2 /merged\n| | |\n+-- /dir1 +-- /dir1 +-- /dir1\n| | | | | |\n| +-- file1 | +-- file2 | +-- file1\n| | +-- file3 | +-- file2\n+-- /dir2 | | +-- file3\n| | +-- /dir3 |\n| +-- file4 | +-- /dir2\n| +-- file5 | |\n+-- file6 | +-- file4\n |\n +-- /dir3\n | |\n | +-- file5\n |\n +-- file6\n
"},{"location":"benchmarking/","title":"Benchmarking","text":"Filesystems are complicated. They do many things and many of those are interconnected. Additionally, the OS, drivers, hardware, etc. can all impact performance. Therefore, when benchmarking, it is necessary that the test focuses as narrowly as possible.
For most throughput is the key benchmark. To test throughput dd
is useful but must be used with the correct settings in order to ensure the filesystem or device is actually being tested. The OS can and will cache data. Without forcing synchronous reads and writes and/or disabling caching the values returned will not be representative of the device's true performance.
When benchmarking through mergerfs ensure you only use 1 branch to remove any possibility of the policies complicating the situation. Benchmark the underlying filesystem first and then mount mergerfs over it and test again. If you're experiencing speeds below your expectation you will need to narrow down precisely which component is leading to the slowdown. Preferably test the following in the order listed (but not combined).
nullrw
mode with nullrw=true
. This will effectively make reads and writes no-ops. Removing the underlying device / filesystem from the equation. This will give us the top theoretical speeds.tmpfs
. tmpfs
is a RAM disk. Extremely high speed and very low latency. This is a more realistic best case scenario. Example: mount -t tmpfs -o size=2G tmpfs /tmp/tmpfs
Once you find the component which has the performance issue you can do further testing with different options to see if they impact performance. For reads and writes the most relevant would be: cache.files
, async_read
. Less likely but relevant when using NFS or with certain filesystems would be security_capability
, xattr
, and posix_acl
. If you find a specific system, device, filesystem, controller, etc. that performs poorly contact trapexit so he may investigate further.
Sometimes the problem is really the application accessing or writing data through mergerfs. Some software use small buffer sizes which can lead to more requests and therefore greater overhead. You can test this out yourself by replacing bs=1M
in the examples below with ibs
or obs
and using a size of 512
instead of 1M
. In one example test using nullrw
the write speed dropped from 4.9GB/s to 69.7MB/s when moving from 1M
to 512
. Similar results were had when testing reads. Small writes overhead may be improved by leveraging a write cache but in casual tests little gain was found. More tests will need to be done before this feature would become available. If you have an app that appears slow with mergerfs it could be due to this. Contact trapexit so he may investigate further.
$ dd if=/dev/zero of=/mnt/mergerfs/1GB.file bs=1M count=1024 oflag=nocache conv=fdatasync status=progress\n
"},{"location":"benchmarking/#read-benchmark","title":"read benchmark","text":"$ dd if=/mnt/mergerfs/1GB.file of=/dev/null bs=1M count=1024 iflag=nocache conv=fdatasync status=progress\n
"},{"location":"benchmarking/#other-benchmarks","title":"other benchmarks","text":"If you are attempting to benchmark other behaviors you must ensure you clear kernel caches before runs. In fact it would be a good deal to run before the read and write benchmarks as well just in case.
sync\necho 3 | sudo tee /proc/sys/vm/drop_caches\n
"},{"location":"error_handling/","title":"Error Handling","text":"POSIX filesystem functions offer a single return code meaning that there is some complication regarding the handling of multiple branches as mergerfs does. It tries to handle errors in a way that would generally return meaningful values for that particular function.
"},{"location":"error_handling/#chmod-chown-removexattr-setxattr-truncate-utimens","title":"chmod, chown, removexattr, setxattr, truncate, utimens","text":"While doing this increases the complexity and cost of error handling, particularly step 3, this provides probably the most reasonable return value.
"},{"location":"error_handling/#unlink-rmdir","title":"unlink, rmdir","text":"Older versions of mergerfs would return success if any success occurred but for unlink and rmdir there are downstream assumptions that, while not impossible to occur, can confuse some software.
"},{"location":"error_handling/#others","title":"others","text":"For search functions, there is always a single thing acted on and as such whatever return value that comes from the single function call is returned.
For create functions mkdir
, mknod
, and symlink
which don't return a file descriptor and therefore can have all
or epall
policies it will return success if any of the calls succeed and an error otherwise.
Due to the overhead of getgroups/setgroups mergerfs utilizes a cache. This cache is opportunistic and per thread. Each thread will query the supplemental groups for a user when that particular thread needs to change credentials and will keep that data for the lifetime of the thread. This means that if a user is added to a group it may not be picked up without the restart of mergerfs. In the future this may be improved to allow a periodic or manual clearing of the cache.
While not a bug some users have found when using containers that supplemental groups defined inside the container don't work as expected. Since mergerfs lives outside the container it is querying the host's group database. Effectively containers have their own user and group definitions unless setup otherwise just as different systems would.
Users should mount in the host group file into the containers or use a standard shared user & groups technology like NIS or LDAP.
"},{"location":"known_issues_bugs/#directory-mtime-is-not-being-updated","title":"directory mtime is not being updated","text":"Remember that the default policy for getattr
is ff
. The information for the first directory found will be returned. If it wasn't the directory which had been updated then it will appear outdated.
The reason this is the default is because any other policy would be more expensive and for many applications it is unnecessary. To always return the directory with the most recent mtime or a faked value based on all found would require a scan of all filesystems.
If you always want the directory information from the one with the most recent mtime then use the newest
policy for getattr
.
This is not a bug.
Run in verbose mode to better understand what's happening:
$ mv -v /mnt/pool/foo /mnt/disk1/foo\ncopied '/mnt/pool/foo' -> '/mnt/disk1/foo'\nremoved '/mnt/pool/foo'\n$ ls /mnt/pool/foo\nls: cannot access '/mnt/pool/foo': No such file or directory\n
mv
, when working across devices, is copying the source to target and then removing the source. Since the source is the target in this case, depending on the unlink policy, it will remove the just copied file and other files across the branches.
If you want to move files to one filesystem just copy them there and use mergerfs.dedup to clean up the old paths or manually remove them from the branches directly.
"},{"location":"known_issues_bugs/#cached-memory-appears-greater-than-it-should-be","title":"cached memory appears greater than it should be","text":"Use cache.files=off
and/or dropcacheonclose=true
. See the section on page caching.
NFS generally does not like out of band changes. Take a look at the section on NFS in the remote-filesystems for more details.
"},{"location":"known_issues_bugs/#rtorrent-fails-with-enodev-no-such-device","title":"rtorrent fails with ENODEV (No such device)","text":"Be sure to set cache.files=partial|full|auto-full|per-process or use Linux kernel v6.6 or above. rtorrent and some other applications use mmap to read and write to files and offer no fallback to traditional methods.
"},{"location":"known_issues_bugs/#plex-jellyfin-doesnt-work-with-mergerfs","title":"Plex / Jellyfin doesn't work with mergerfs","text":"It does. If you're trying to put the software's config / metadata / database on mergerfs you can't set cache.files=off (unless you use Linux v6.6 or above) because Plex is using sqlite3 with mmap enabled.
That said it is recommended that config and runtime files be stored on SSDs on a regular filesystem for performance reasons and if you are using HDDs in your pool to help limit spinup.
Other software that leverages sqlite3 which require mmap includes Radarr, Sonarr, Lidarr.
It is recommended that you reach out to the developers of the software you're having troubles with and asking them to add a fallback to regular file IO when mmap is unavailable. It is not only more compatible and resilient but also can be more performant in certain situations.
If the issue is that quick scanning doesn't seem to pick up media then be sure to set func.getattr=newest
, though generally, a full scan will pick up all media anyway.
Please read the docs regarding rename and link.
The problem is that many applications do not properly handle EXDEV
errors which rename
and link
may return even though they are perfectly valid situations which do not indicate actual device, filesystem, or OS errors. The error will only be returned by mergerfs if using a path preserving policy as described in the policy section above. If you do not care about path preservation simply change the mergerfs policy to the non-path preserving version. For example: -o category.create=mfs
Ideally the offending software would be fixed and it is recommended that if you run into this problem you contact the software's author and request proper handling of EXDEV
errors.
Some software have problems with 64bit inode values. The symptoms can include EOVERFLOW errors when trying to list files. You can address this by setting inodecalc
to one of the 32bit based algos as described in the relevant section.
Workaround: Copy the file/directory and then remove the original rather than move.
This isn't an issue with Samba but some SMB clients. GVFS-fuse v1.20.3 and prior (found in Ubuntu 14.04 among others) failed to handle certain error codes correctly. Particularly STATUS_NOT_SAME_DEVICE
which comes from the EXDEV
that is returned by rename
when the call is crossing mount points. When a program gets an EXDEV
it needs to explicitly take an alternate action to accomplish its goal. In the case of mv
or similar it tries rename
and on EXDEV
falls back to a copying the file to the destination and deleting the source. In these older versions of GVFS-fuse if it received EXDEV
it would translate that into EIO
. This would cause mv
or most any application attempting to move files around on that SMB share to fail with a generic IO error.
GVFS-fuse v1.22.0 and above fixed this issue but a large number of systems use the older release. On Ubuntu, the version can be checked by issuing apt-cache showpkg gvfs-fuse
. Most distros released in 2015 seem to have the updated release and will work fine but older systems may not. Upgrading gvfs-fuse or the distro in general will address the problem.
In Apple's MacOSX 10.9 they replaced Samba (client and server) with their own product. It appears their new client does not handle EXDEV
either and responds similarly to older releases of gvfs on Linux.
This is the same issue as with Samba. rename
returns EXDEV
(in our case that will really only happen with path preserving policies like epmfs
) and the software doesn't handle the situation well. This is unfortunately a common failure of software which moves files around. The standard indicates that an implementation MAY choose to support non-user home directory trashing of files (which is a MUST). The implementation MAY also support \"top directory trashes\" which many probably do.
To create a $topdir/.Trash
directory as defined in the standard use the mergerfs-tools tool mergerfs.mktrash
.
There have been a number of kernel issues / bugs over the years which mergerfs has run into. Here is a list of them for reference and posterity.
"},{"location":"known_issues_bugs/#nfs-and-eio-errors","title":"NFS and EIO errors","text":"https://lore.kernel.org/linux-fsdevel/20240228160213.1988854-1-mszeredi@redhat.com/T/
Over the years some users have reported that while exporting mergerfs via NFS, after significant filesystem activity, not only will the NFS client start returning ESTALE and EIO errors but mergerfs itself would start returning EIO errors. The problem was that no one could reliability reproduce the issue. After a string of reports in late 2023 and early 2024 more investigation was done.
In Linux 5.14 new validation was put into FUSE which caught a few invalid situations and would tag a FUSE node as invalid if a check failed. Such checks include invalid file type, changing of type from one request to another, a size greater than 63bit, and the generation of a inode changing while in use.
What happened was that mergerfs was using a different fixed, non-zero value for the generation of all nodes as it was suggested that unique inode + generation pairs are needed for proper integration with NFS. That non-zero value was being sent back to the kernel when a lookup request was made for root. The reason this was hard to track down was because NFS almost uniquely uses an API which can lead to a lookup of the root node that simply won't happen under normal workloads and usage. And that lookup will only happen if child nodes of the root were forgotten but NFS still had a handle to that node and later asked for details about it. It would trigger a set of requests to lookup info on those nodes.
This wasn't a bug in FUSE but mergerfs. However, the incorrect behavior of mergerfs lead to FUSE behave in an unexpected and incorrect manner. It would issue a lookup of the \"parent of a child of the root\" and mergerfs would send the invalid generation value. As a result the kernel would mark the root node as \"bad\" which would then trigger the kernel to issue a \"forget root\" message. In between those it would issue a request for the parent of the root... which doesn't exist.
So the kernel was doing two invalid things. Requesting the parent of the root and then when that failed issuing a forget for the root. These led to chasing after the wrong possible causes.
The change was for FUSE to revert the marking of root node bad if the generation is non-zero and warn about it. It will mark the node bad but not unhash/forget/remove it.
mergerfs in v2.40.1 ensures that generation for root is always 0 on lookup which should work across any kernel version.
"},{"location":"known_issues_bugs/#truncated-files","title":"Truncated files","text":"This was a bug with mmap
and FUSE
on 32bit platforms. Should be fixed in all LTS releases.
There was a bug in the OpenVZ kernel with regard to how it handles ioctl
calls. It was making invalid requests which would lead to crashes due to mergerfs not expecting them.
There was a bug in caching which affects overall performance of mmap
through FUSE
in Linux 4.x kernels. It is fixed in 4.4.10 and 4.5.4.
mergerfs is at its is a proxy and therefore its theoretical max performance is that of the underlying devices. However, given it is a FUSE based filesystem working from userspace there is an increase in overhead relative to kernel based solutions. That said the performance can match the theoretical max but it depends greatly on the system's configuration. Especially when adding network filesystems into the mix there are many variables which can impact performance. Device speeds and latency, network speeds and latency, concurrency and parallel limits of the hardware, read/write sizes, etc.
While some settings can impact performance they are all functional in nature. Meaning they change mergerfs' behavior in some way. As a result there is no such thing as a \"performance mode\".
If you're having performance issues please look over the suggestions below and the benchmarking section.
NOTE: Be sure to read about these features before changing them to understand how functionality will change.
nullrw
or mounting a ram diskreadahead=1024
security_capability
and/or xattr
cache.attr
, cache.entry
, cache.negative_entry
cache.files
)parallel-direct-writes
cache.writeback
cache.statfs
cache.symlinks
cache.readdir
posix_acl
async_read
symlinkify
if your data is largely static and read-onlyIf you come across a setting that significantly impacts performance please contact trapexit so he may investigate further. Please test both against your normal setup, a singular branch, and with nullrw=true
mhddfs had not been updated in over a decade and has known stability and security issues. mergerfs provides a superset of mhddfs' features and offers better performance.
Below is an example of mhddfs and mergerfs setup to work similarly.
mhddfs -o mlimit=4G,allow_other /mnt/drive1,/mnt/drive2 /mnt/pool
mergerfs -o minfreespace=4G,category.create=ff /mnt/drive1:/mnt/drive2 /mnt/pool
aufs is abandoned and no longer available in most Linux distros.
While aufs can offer better peak performance mergerfs provides more configurability and is generally easier to use. mergerfs however does not offer the overlay / copy-on-write (CoW) features which aufs has.
"},{"location":"project_comparisons/#linux-unionfs","title":"Linux unionfs","text":"FILL IN
"},{"location":"project_comparisons/#unionfs-fuse","title":"unionfs-fuse","text":"unionfs-fuse is more like aufs than mergerfs in that it offers overlay / copy-on-write (CoW) features. If you're just looking to create a union of filesystems and want flexibility in file/directory placement then mergerfs offers that whereas unionfs-fuse is more for overlaying read/write filesystems over read-only ones. Largely unionfs-fuse has been replaced by overlayfs.
"},{"location":"project_comparisons/#overlayfs","title":"overlayfs","text":"overlayfs is similar to aufs and unionfs-fuse in that it also is primarily used to layer a read/write filesystem over one or more read-only filesystems. It does not have the ability to spread files/directories across numerous filesystems. It is the successor to unionfs, unionfs-fuse, and aufs and widely used by container platforms such as Docker.
If your usecase is layering a writable filesystem on top of readonly filesystems then you should look first to overlayfs.
"},{"location":"project_comparisons/#raid0-jbod-drive-concatenation-striping","title":"RAID0, JBOD, drive concatenation, striping","text":"With simple JBOD / drive concatenation / stripping / RAID0 a single drive failure will result in full pool failure. mergerfs performs a similar function without the possibility of catastrophic failure and the difficulties in recovery. Drives may fail but all other filesystems and their data will continue to be accessible.
The main practical difference with mergerfs is the fact you don't actually have contiguous space as large as if you used those other technologies. Meaning you can't create a 2TB file on a pool of 2 1TB filesystems.
"},{"location":"project_comparisons/#unraid","title":"UnRAID","text":"UnRAID is a full OS and offers a (FUSE based?) filesystem which provides a union of filesystems like mergerfs but with the addition of live parity calculation and storage. Outside parity calculations mergerfs offers more features and due to the lack of realtime parity calculation can have high peak performance. Some users also prefer an open source solution.
For semi-static data mergerfs + SnapRaid provides a similar solution.
"},{"location":"project_comparisons/#zfs","title":"ZFS","text":"mergerfs is very different from ZFS. mergerfs is intended to provide flexible pooling of arbitrary filesystems (local or remote), of arbitrary sizes, and arbitrary filesystems. Primarily in write once, read many
usecases such as bulk media storage. Where data integrity and backup is managed in other ways. In those usecases ZFS can introduce a number of costs and limitations as described here, here, and here.
DrivePool works only on Windows so not as common an alternative as other Linux solutions. If you want to use Windows then DrivePool is a good option. Functionally the two projects work a bit differently. DrivePool always writes to the filesystem with the most free space and later rebalances. mergerfs does not currently offer rebalance but chooses a branch at file/directory create time. DrivePool's rebalancing can be done differently in any directory and has file pattern matching to further customize the behavior. mergerfs, not having rebalancing does not have these features, but similar features are planned for mergerfs v3. DrivePool has builtin file duplication which mergerfs does not natively support (but can be done via an external script.)
There are a lot of misc differences between the two projects but most features in DrivePool can be replicated with external tools in combination with mergerfs.
Additionally, DrivePool is a closed source commercial product vs mergerfs a ISC licensed open source project.
"},{"location":"project_comparisons/#plan9-binds","title":"Plan9 binds","text":"Plan9 has the native ability to bind multiple paths/filesystems together which can be compared to a simplified union filesystem. Such bind mounts choose files in a \"first found\" in the order they are listed similar to mergerfs' ff
policy. File creation is limited to... FILL ME IN. REFERENCE DOCS.
First ensure you have the latest version installed.
"},{"location":"quickstart/#configuration","title":"Configuration","text":"mergerfs has many options and effectively all of them are functional in nature. What that means is that there is no \"best\" or \"fastest\" configuration. No \"make faster\" options. Everything changes behavior. Sometimes those changes in behavior affect performance.
That said: If you don't already know that you have a special use case then use one of the following option sets as it will cover most casual usecases.
"},{"location":"quickstart/#you-use-linux-v66-or-above","title":"You use Linux v6.6 or above","text":"In previous versions of Linux it was unable to support mmap
if page caching was disabled (ie: cache.files=off
). However, it now will enable page caching if needed for a particular file if mmap is requested.
mmap
is needed by certain software to read and write to a file. However, many software could work without it and fail to have proper error handling. Many programs that use sqlite3 will require mmap
despite sqlite3 working perfectly fine without it (and in some cases can be more performant with regular file IO.)
mmap
(used by rtorrent and many sqlite3 base software)","text":"mmap
","text":"mergerfs -o cache.files=off,dropcacheonclose=false,category.create=mfs /mnt/hdd0:/mnt/hdd1 /media\n
"},{"location":"quickstart/#etcfstab","title":"/etc/fstab","text":"/mnt/hdd0:/mnt/hdd1 /media mergerfs cache.files=off,dropcacheonclose=false,category.create=mfs 0 0\n
"},{"location":"quickstart/#etcfstab-w-config-file","title":"/etc/fstab w/ config file","text":"For more complex setups it can be useful to separate out the config.
"},{"location":"quickstart/#etcfstab_1","title":"/etc/fstab","text":"/etc/mergerfs/branches/media/* /media mergerfs config=/etc/mergerfs/config/media.ini\n
"},{"location":"quickstart/#etcmergerfsconfigmediaini","title":"/etc/mergerfs/config/media.ini","text":"media.inicache.files=off\ncategory.create=mfs\ndropcacheonclose=false\n
"},{"location":"quickstart/#etcmergerfsbranchesmedia","title":"/etc/mergerfs/branches/media/","text":"Create a bunch of symlinks to point to the branch. mergerfs will resolve the symlinks and use the real path.
ls -lh /etc/mergerfs/branches/media/*
lrwxrwxrwx 1 root root 21 Aug 4 2023 hdd00 -> /mnt/hdd/hdd00\nlrwxrwxrwx 1 root root 21 Aug 4 2023 hdd01 -> /mnt/hdd/hdd01\nlrwxrwxrwx 1 root root 21 Aug 4 2023 hdd02 -> /mnt/hdd/hdd02\nlrwxrwxrwx 1 root root 21 Aug 4 2023 hdd03 -> /mnt/hdd/hdd03\n
"},{"location":"quickstart/#systemd-simple","title":"systemd (simple)","text":"/etc/systemd/system/mergerfs-media.service
[Unit]\nDescription=mergerfs /media service\nAfter=local-fs.target network.target\n\n[Service]\nType=simple\nKillMode=none\nExecStart=/usr/bin/mergerfs \\\n -f \\\n -o cache.files=off \\\n -o category.create=mfs \\\n -o dropcacheonclose=false \\\n /mnt/hdd0:/mnt/hdd1 \\\n /media\nExecStop=/bin/fusermount -uz /media\nRestart=on-failure\n\n[Install]\nWantedBy=default.target\n
"},{"location":"quickstart/#systemd-w-setup-script","title":"systemd (w/ setup script)","text":"Since it isn't well documented otherwise: if you wish to do some setup before you mount mergerfs follow this example.
"},{"location":"quickstart/#setup-for-mergerfs","title":"setup-for-mergerfs","text":"/usr/local/bin/setup-for-mergerfs
#!/usr/bin/env sh\n\n# Perform setup\n/bin/sleep 10\n\n# Report back to systemd that things are ready\n/bin/systemd-notify --ready\n
"},{"location":"quickstart/#setup-for-mergerfsservice","title":"setup-for-mergerfs.service","text":"/etc/systemd/system/setup-for-mergerfs.service
[Unit]\nDescription=mergerfs setup service\n\n[Service]\nType=notify\nRemainAfterExit=yes\nExecStart=/usr/local/bin/setup-for-mergerfs\n\n[Install]\nWantedBy=default.target\n
"},{"location":"quickstart/#mergerfs-mediaservice","title":"mergerfs-media.service","text":"/etc/systemd/system/mergerfs-media.service
[Unit]\nDescription=mergerfs /media service\nRequires=setup-for-mergerfs.service\nAfter=local-fs.target network.target prepare-for-mergerfs.service\n\n[Service]\nType=simple\nKillMode=none\nExecStart=/usr/bin/mergerfs \\\n -f \\\n -o cache.files=off \\\n -o category.create=mfs \\\n -o dropcacheonclose=false \\\n /mnt/hdd0:/mnt/hdd1 \\\n /media\nExecStop=/bin/fusermount -uz /media\nRestart=on-failure\n\n[Install]\nWantedBy=default.target\n
"},{"location":"related_projects/","title":"Related Projects","text":""},{"location":"related_projects/#projects-using-mergerfs","title":"Projects using mergerfs","text":"mergerfs can be found in the repositories of many Linux (and maybe FreeBSD) distributions.
Note: Any non-rolling release based distro is likely to have out-of-date versions.
Many users ask about compatibility with remote filesystems. This section is to describe any known issues or quirks when using mergerfs with common remote filesystems.
Keep in mind that, like with caching, it is NOT a good idea to change the contents of the remote filesystem out-of-band. Meaning that you should not change the contents of the underlying filesystems or mergerfs on the server hosting the remote filesystem. Doing so can lead to weird behavior, inconsistency, errors, and even data corruption should multiple programs try to write or read the same data at the same time. This isn't to say you can't do it or that data corruption is likely but it could happen. It is better to always use the remote filesystem. Even on the machine serving it.
"},{"location":"remote_filesystems/#nfs","title":"NFS","text":"NFS is a common remote filesystem on Unix/POSIX systems. Due to how NFS works there are some settings which need to be set in order for mergerfs to work with it.
It should be noted that NFS and FUSE (the technology mergerfs uses) do not work perfectly with one another due to certain design choices in FUSE (and mergerfs.) Due to these issues, it is generally recommended to use SMB when possible. That said mergerfs should generally work as an export of NFS and issues discovered should still be reported.
To ensure compatibility between mergerfs and NFS use the following settings.
mergerfs settings:
noforget
inodecalc=path-hash
NFS export settings:
fsid=UUID
no_root_squash
noforget
is needed because NFS uses the name_to_handle_at
and open_by_handle_at
functions which allow a program to keep a reference to a file without technically having it open in the typical sense. The problem is that FUSE has no way to know that NFS has a handle that it will later use to open the file again. As a result, it is possible for the kernel to tell mergerfs to forget about the node and should NFS ever ask for that node's details in the future it would have nothing to respond with. Keeping nodes around forever is not ideal but at the moment the only way to manage the situation.
inodecalc=path-hash
is needed because NFS is sensitive to out-of-band changes. FUSE doesn't care if a file's inode value changes but NFS, being stateful, does. So if you used the default inode calculation algorithm then it is possible that if you changed a file or updated a directory the file mergerfs will use will be on a different branch and therefore the inode would change. This isn't an ideal solution and others are being considered but it works for most situations.
fsid=UUID
is needed because FUSE filesystems don't have different st_dev
values which can cause issues when exporting. The easiest thing to do is set each mergerfs export fsid
to some random value. An easy way to generate a random value is to use the command line tool uuid
or uuidgen
or through a website such as uuidgenerator.net.
no_root_squash
is not strictly necessary but can lead to confusing permission and ownership issues if root squashing is enabled. mergerfs needs to run certain commands as root
and if root squash is enabled it NFS will tell mergerfs a non-root user is making certain calls.
SMB is a protocol most used by Microsoft Windows systems to share file shares, printers, etc. However, due to the popularity of Windows, it is also supported on many other platforms including Linux. The most popular way of supporting SMB on Linux is via the software Samba.
Samba, and other ways of serving Linux filesystems, via SMB should work fine with mergerfs. The services do not tend to use the same technologies which NFS uses and therefore don't have the same issues. There should not be special settings required to use mergerfs with Samba. However, CIFSD and other programs have not been extensively tested. If you use mergerfs with CIFSD or other SMB servers please submit your experiences so these docs can be updated.
"},{"location":"remote_filesystems/#sshfs","title":"SSHFS","text":"SSHFS is a FUSE filesystem leveraging SSH as the connection and transport layer. While often simpler to setup when compared to NFS or Samba the performance can be lacking and the project is very much in maintenance mode.
There are no known issues using sshfs with mergerfs. You may want to use the following arguments to improve performance but your millage may vary.
-o Ciphers=arcfour
-o Compression=no
More info can be found here.
"},{"location":"remote_filesystems/#other","title":"Other","text":"There are other remote filesystems but none popularly used to serve mergerfs. If you use something not listed above feel free to reach out and I will add it to the list.
"},{"location":"runtime_interfaces/","title":"Runtime Interfaces","text":""},{"location":"runtime_interfaces/#runtime-config","title":"Runtime Config","text":""},{"location":"runtime_interfaces/#mergerfs-pseudo-file","title":".mergerfs pseudo file","text":"<mountpoint>/.mergerfs\n
There is a pseudo file available at the mount point which allows for the runtime modification of certain mergerfs options. The file will not show up in readdir but can be stat'ed and manipulated via {list,get,set}xattrs calls.
Any changes made at runtime are not persisted. If you wish for values to persist they must be included as options wherever you configure the mounting of mergerfs (/etc/fstab).
"},{"location":"runtime_interfaces/#keys","title":"Keys","text":"Use getfattr -d /mountpoint/.mergerfs
or xattr -l /mountpoint/.mergerfs
to see all supported keys. Some are informational and therefore read-only. setxattr
will return EINVAL (invalid argument) on read-only keys.
Same as the command line.
"},{"location":"runtime_interfaces/#usermergerfsbranches","title":"user.mergerfs.branches","text":"Used to query or modify the list of branches. When modifying there are several shortcuts to easy manipulation of the list.
Value Description [list] set +<[list] prepend +>[list] append -[list] remove all values provided -< remove first in list -> remove last in listxattr -w user.mergerfs.branches +</mnt/drive3 /mnt/pool/.mergerfs
The =NC
, =RO
, =RW
syntax works just as on the command line.
[trapexit:/mnt/mergerfs] $ getfattr -d .mergerfs\nuser.mergerfs.branches=\"/mnt/a=RW:/mnt/b=RW\"\nuser.mergerfs.minfreespace=\"4294967295\"\nuser.mergerfs.moveonenospc=\"false\"\n...\n\n[trapexit:/mnt/mergerfs] $ getfattr -n user.mergerfs.category.search .mergerfs\nuser.mergerfs.category.search=\"ff\"\n\n[trapexit:/mnt/mergerfs] $ setfattr -n user.mergerfs.category.search -v newest .mergerfs\n[trapexit:/mnt/mergerfs] $ getfattr -n user.mergerfs.category.search .mergerfs\nuser.mergerfs.category.search=\"newest\"\n
"},{"location":"runtime_interfaces/#file-directory-xattrs","title":"file / directory xattrs","text":"While they won't show up when using getfattr
mergerfs offers a number of special xattrs to query information about the files served. To access the values you will need to issue a getxattr for one of the following:
Found in fuse_ioctl.cpp
:
typedef char IOCTL_BUF[4096];\n#define IOCTL_APP_TYPE 0xDF\n#define IOCTL_FILE_INFO _IOWR(IOCTL_APP_TYPE,0,IOCTL_BUF)\n#define IOCTL_GC _IO(IOCTL_APP_TYPE,1)\n#define IOCTL_GC1 _IO(IOCTL_APP_TYPE,2)\n#define IOCTL_INVALIDATE_ALL_NODES _IO(IOCTL_APP_TYPE,3)\n
https://github.com/trapexit/support
Development and support of a project like mergerfs requires a significant amount of time and effort. The software is released under the very liberal ISC license and is therefore free to use for personal or commercial uses.
If you are a non-commercial user and find mergerfs and its support valuable and would like to support the project financially it would be very much appreciated.
If you are using mergerfs commercially please consider sponsoring the project to ensure it continues to be maintained and receive updates. If custom features are needed feel free to contact me directly.
"},{"location":"support/","title":"Support","text":"Filesystems are complex, as are the interactions software have with them, and therefore difficult to debug. When reporting on a suspected issue please include as much of the below information as possible otherwise it will be difficult or impossible to diagnose. Also please read the documentation as it provides details on many previously encountered questions/issues.
Please make sure you are using the latest release or have tried it in comparison. Old versions, which are often included in distros like Debian and Ubuntu, are not ever going to be updated and the issue you are encountering may have been addressed already.
For commercial support or feature requests please contact me directly.
"},{"location":"support/#information-to-include-in-bug-reports","title":"Information to include in bug reports","text":"mergerfs --version
uname -a
and lsb_release -a
df -h
strace
of the app having problems:strace -fvTtt -s 256 -o /tmp/app.strace.txt <cmd>
strace
of mergerfs while the program is trying to do whatever it is failing to do:strace -fvTtt -s 256 -p <mergerfsPID> -o /tmp/mergerfs.strace.txt
ln
, mv
, cp
, ls
, dd
, etc.libfuse
arguments aren't listed they probably shouldn't be used.root
. mergerfs is designed and intended to be run as root
and may exhibit incorrect behavior if run otherwise.mergerfs.fsck
to audit the filesystem for out of sync permissions.cache.files=off
if you expect applications (such as rtorrent) to use mmap. Enabling dropcacheonclose
is recommended when cache.files=auto-full
.getattr
policy of ff
it's possible those programs will miss an update on account of it returning the first directory found's stat
info and it is a later directory on another mount which had the mtime
recently updated. To fix this you will want to set func.getattr=newest
. Remember though that this is just stat
. If the file is later open
'ed or unlink
'ed and the policy is different for those then a completely different file or directory could be acted on.category
wide policies rather than individual func
's. This will help limit the confusion of tools such as rsync. However, the flexibility is there if needed.EXPERIMENTAL
For some time there has been work to enable passthrough IO in FUSE. Passthrough IO would allow for near native performance with regards to reads and writes (at the expense of certain mergerfs features.) In Linux v6.9 that feature made its way into the kernel however in a somewhat limited form which is incompatible with aspects of how mergerfs currently functions. While work will continue to support passthrough IO in mergerfs this library was created to offer similar functionality in a more limited way.
/usr/lib/mergerfs/preload.so
This preloadable library overrides the creation and opening of files in order to simulate passthrough file IO. It catches the open/creat/fopen calls, has mergerfs do the call, queries mergerfs for the branch the file exists on, reopens the file on the underlying filesystem and returns that instead. Meaning that you will get native read/write performance because mergerfs is no longer part of the workflow. Keep in mind that this also means certain mergerfs features that work by interrupting the read/write workflow, such as moveonenospc
, will no longer work.
Also, understand that this will only work on dynamically linked software. Anything statically compiled will not work. Many GoLang and Rust apps are statically compiled.
The library will not interfere with non-mergerfs filesystems. The library is written to always fallback to returning the mergerfs opened file on error.
While the library was written to account for a number of edgecases there could be some yet accounted for so please report any oddities.
Thank you to nohajc for prototyping the idea.
"},{"location":"tooling/#casual-usage","title":"casual usage","text":"LD_PRELOAD=/usr/lib/mergerfs/preload.so touch /mnt/mergerfs/filename\n
Or run export LD_PRELOAD=/usr/lib/mergerfs/preload.so
in your shell or place it in your shell config file to have it be picked up by all software ran from your shell.
Assume /mnt/fs0
and /mnt/fs1
are pooled with mergerfs at /media
.
All mergerfs branch paths must be bind mounted into the container at the same path as found on the host so the preload library can see them.
NOTE: Since a container can have its own OS setup there is no guarentee that preload.so
from the host install will be compatible with the loader found in the container. If that is true it simply won't work and shouldn't cause any issues.
docker run \\\n -e LD_PRELOAD=/usr/lib/mergerfs/preload.so \\\n -v /usr/lib/mergerfs/preload.so:/usr/lib/mergerfs/preload.so:ro \\\n -v /media:/media \\\n -v /mnt:/mnt \\\n ubuntu:latest \\\n bash\n
or more explicitly
docker run \\\n -e LD_PRELOAD=/usr/lib/mergerfs/preload.so \\\n -v /usr/lib/mergerfs/preload.so:/usr/lib/mergerfs/preload.so:ro \\\n -v /media:/media \\\n -v /mnt/fs0:/mnt/fs0 \\\n -v /mnt/fs1:/mnt/fs1 \\\n ubuntu:latest \\\n bash\n
"},{"location":"tooling/#systemd-unit","title":"systemd unit","text":"Use the Environment
option to set the LD_PRELOAD variable.
[Service]\nEnvironment=LD_PRELOAD=/usr/lib/mergerfs/preload.so\n
"},{"location":"tooling/#misc","title":"Misc","text":"The 'branches' argument is a colon (':') delimited list of paths to be pooled together. It does not matter if the paths are on the same or different filesystems nor does it matter the filesystem type (within reason). Used and available space will not be duplicated for paths on the same filesystem and any features which aren't supported by the underlying filesystem (such as file attributes or extended attributes) will return the appropriate errors.
Branches currently have two options which can be set. A type which impacts whether or not the branch is included in a policy calculation and a individual minfreespace value. The values are set by prepending an =
at the end of a branch designation and using commas as delimiters. Example: /mnt/drive=RW,1234
create
and action
policies. Same as a read-only mounted filesystem would be (though faster to process).create
policies. You can't create on that branch but you can change or delete.Same purpose and syntax as the global option but specific to the branch. If not set the global value is used.
"},{"location":"config/branches/#globbing","title":"globbing","text":"To make it easier to include multiple branches mergerfs supports globbing. The globbing tokens MUST be escaped when using via the shell else the shell itself will apply the glob itself.
# mergerfs /mnt/hdd\\*:/mnt/ssd /media\n
The above line will use all mount points in /mnt prefixed with hdd and ssd.
To have the pool mounted at boot or otherwise accessible from related tools use /etc/fstab
.
# <file system> <mount point> <type> <options> <dump> <pass>\n/mnt/hdd*:/mnt/ssd /media mergerfs minfreespace=16G 0 0\n
NOTE: The globbing is done at mount or when updated using the runtime API. If a new directory is added matching the glob after the fact it will not be automatically included.
"},{"location":"config/cache/","title":"caching","text":""},{"location":"config/cache/#cachefiles","title":"cache.files","text":"Controls how page caching works for mergerfs itself. Not the underlying filesystems.
cache.files=off
: Disables page caching for mergerfs.cache.files=partial
: Enables page caching. Files are cached while open.cache.files=full
: Enables page caching. Files are cached across opens.cache.files=auto-full
: Enables page caching. Files are cached across opens if mtime and size are unchanged since previous open.cache.files=per-process
: Enable page caching (equivalent to cache.files=partial
) only for processes whose 'comm' name matches one of the values defined in cache.files.process-names. If the name does not match the file open is equivalent to cache.files=off
.Generally, enabling the page cache actually harms performance1. In part because it can lead to buffer bloat due to the kernel caching both the underlying filesystem's file content as well as the file through mergerfs. However, if you want to confirm performance differences it is recommended that you perform some benchmark to confirm which option works best for your setup.
Why then would you want to enable page caching if it consumes ~2x the RAM as normal and is on average slower? Because it is the only way to support mmap. mmap
is a way for programs to treat a file as if it is a contiguous RAM buffer which is regularly used by a number of programs such as those that leverage sqlite3. Despite mmap
not being supported by all filesystems it is unfortunately common for software to not have an option to use regular file IO instead of mmap
.
The good thing is that in Linux v6.62 and above FUSE can now transparently enable page caching when mmap is requested. This means it should be safe to set cache.files=off
. However, on Linux v6.5 and below you will need to configure cache.files
as you need.
cache.entry=UINT
: Sets the number of seconds to cache entry queries. Defaults to 1
.The kernel must ask mergerfs about the existence of files. The entry cache caches that those details which limits the number of requests sent to mergerfs.
The risk of setting this value, as with most any cache, is related to out-of-band changes. If the filesystems are changed outside mergerfs there is a risk of files which have been removed continuing to show as available. It will fail gracefully if a phantom file is actioned on in some way so there is little risk in setting the value much higher. Especially if there are no out-of-band changes.
"},{"location":"config/cache/#cachenegative_entry","title":"cache.negative_entry","text":"cache.negative_entry=UINT
: Sets the number of seconds to cache negative entry queries. Defaults to 1
.This is a cache for negative entry query responses. Such as when a file which does not exist is referenced.
The risk of setting this value, as with most any cache, is related to out-of-band changes. If the filesystems are changed outside mergerfs there is a risk of files which have been added outside mergerfs not appearing correctly till the cache entry times out if there had been a request for the same name within mergerfs which didn't exist. This is mostly an inconvenience.
"},{"location":"config/cache/#cacheattr","title":"cache.attr","text":"cache.attr=UINT
: Sets the number of seconds to cache file attributes. Defaults to 1
.This is a cache for file attributes and metadata such as that which is collected by the stat system call which is used when you run commands such as find
or ls -lh
.
As with other caches the risk of enabling the attribute cache is if changes are made to the file out-of-band there could be inconsistencies between the actual file and the cached details which could result in different issues depending on how the data is used. If the simultaneous writing of a file from inside and outside is unlikely then you should be safe. That said any simultaneous, uncoordinated manipulation of a file can lead to unexpected results.
"},{"location":"config/cache/#cachestatfs","title":"cache.statfs","text":"cache.statfs=UINT
: Sets the number of seconds to cache statfs
calls used by policies. Defaults to 0
.A number of policies require looking up the available space of the branches being considered. This is accomplished by calling statfs. This call however is a bit expensive so this cache reduces the overhead by limiting how often the calls are actually made.
This will mean that if the available space of branches changed somewhat rapidly there is a risk of create
or mkdir
calls made within the timeout period ending up on the same branch. This however should even itself out over time.
cache.symlinks=BOOL
: Enable kernel caching of symlink values. Defaults to false
.As of Linux v4.20 there is an ability to cache the value of symlinks so that the kernel does not need to make a request to mergerfs every single time a readlink request is made. While not a common usage pattern, if software very regularly queries symlink values, the use of this cache could significantly improve performance.
mergerfs will not error if the kernel used does not support symlink caching.
As with other caches the main risk in enabling it is if you are manipulating symlinks from both within and without the mergerfs mount. Should the value be changed outside of mergerfs then it will not be reflected in the mergerfs mount till the cached value is invalidated.
"},{"location":"config/cache/#cachereaddir","title":"cache.readdir","text":"cache.readdir=BOOL
: Enable kernel caching of readdir results. Defaults to false
.As of Linux v4.20 it supports readdir caching. This can have a significant impact on directory traversal. Especially when combined with entry (cache.entry
) and attribute (cache.attr
) caching. If the kernel doesn't support readdir caching setting the option to true has no effect. This option is configurable at runtime via xattr user.mergerfs.cache.readdir.
cache.writeback=BOOL
: Enable writeback cache. Defaults to false
.When cache.files
is enabled the default is for it to perform writethrough caching. This behavior won't help improve performance as each write still goes one for one through the filesystem. By enabling the FUSE writeback cache small writes may be aggregated by the kernel and then sent to mergerfs as one larger request. This can greatly improve the throughput for apps which write to files inefficiently. The amount the kernel can aggregate is limited by the size of a FUSE message. Read the fuse_msg_size section for more details.
There is a side effect as a result of enabling writeback caching. Underlying files won't ever be opened with O_APPEND or O_WRONLY. The former because the kernel then manages append mode and the latter because the kernel may request file data from mergerfs to populate the write cache. The O_APPEND change means that if a file is changed outside of mergerfs it could lead to corruption as the kernel won't know the end of the file has changed. That said any time you use caching you should keep from writing to the same file outside of mergerfs at the same time.
Note that if an application is properly sizing writes then writeback caching will have little or no effect. It will only help with writes of sizes below the FUSE message size (128K on older kernels, 1M on newer). Even then its effectiveness might not be great. Given the side effects of enabling this feature it is recommended that its benefits be proved out with benchmarks.
This is not unique to mergerfs and affects all FUSE filesystems. It is something that the FUSE community hopes to investigate at some point but as of early 2025 there are a number of major reworking going on with FUSE which needs to be finished first.\u00a0\u21a9
https://kernelnewbies.org/Linux_6.6#FUSE \u21a9
These are old, deprecated options which may no longer have any function or have been replaced.
cache.files=off
instead.cache.files=full
instead.cache.files=auto-full
instead. (default: false)async_read=true
instead.async_read=false
instead.inodecalc
.export-support=true|false
true
.In theory, this flag should not be exposed to the end user. It is a low-level FUSE flag which indicates whether or not the kernel can send certain kinds of messages to it for the purposes of using it with NFS. mergerfs does support these messages but due to bugs and quirks found in the kernel and mergerfs this option is provided just in case it is needed for debugging.
Given that this flag is set when the FUSE connection is first initiated it is not possible to change during run time.
"},{"location":"config/flush-on-close/","title":"flush-on-close","text":"By default, FUSE would issue a flush before the release of a file descriptor. This was considered a bit aggressive and a feature added to give the FUSE server the ability to choose when that happens.
flush-on-close=always
flush-on-close=never
flush-on-close=opened-for-write
opened-for-write
.For now it defaults to opened-for-write
which is less aggressive than the behavior before this feature was added. It should not be a problem because the flush is really only relevant when a file is written to. Given flush is irrelevant for many filesystems in the future a branch specific flag may be added so only files opened on a specific branch would be flushed on close.
This feature, when enabled, will cause symlinks to be interpreted by mergerfs as their target.
When there is a getattr/stat request for a file mergerfs will check if the file is a symlink and depending on the follow-symlinks
setting will replace the information about the symlink with that of that which it points to.
When unlink'ing or rmdir'ing the followed symlink it will remove the symlink itself and not that which it points to.
follow-symlinks=never
: Behave as normal. Symlinks are treated as such.follow-symlinks=directory
: Resolve symlinks only which point to directories.follow-symlinks=regular
: Resolve symlinks only which point to regular files.follow-symlinks=all
: Resolve all symlinks to that which they point to. Symlinks which do not point to anything are left as is.never
.WARNING: This feature should be considered experimental. There might be edge cases yet found. If you find any odd behaviors please file a ticket on github.
"},{"location":"config/func_readdir/","title":"func.readdir","text":"examples: func.readdir=seq
, func.readdir=cor:4
readdir
has policies to control how it reads directory content.
branches
. This is the default and traditional behavior found prior to the readdir policy introduction. This will be increasingly slower as more branches are added to the pool. Especially if needing to wait for drives to spin up or network filesystems to respond. cosr \"concurrent open, sequential read\" : Concurrently open branch directories using a thread pool and process them in the order defined in branches
. This keeps memory and CPU usage low while also reducing the time spent waiting on branches to respond. Number of threads defaults to the number of logical cores. Can be overwritten via the syntax func.readdir=cosr:N
where N
is the number of threads. cor \"concurrent open and read\" : Concurrently open branch directories and immediately start reading their contents using a thread pool. This will result in slightly higher memory and CPU usage but reduced latency. Particularly when using higher latency / slower speed network filesystem branches. Unlike seq
and cosr
the order of files could change due the async nature of the thread pool. This should not be a problem since the order of files listed in not guaranteed. Number of threads defaults to the number of logical cores. Can be overwritten via the syntax func.readdir=cor:N
where N
is the number of threads. Keep in mind that readdir
mostly just provides a list of file names in a directory and possibly some basic metadata about said files. To know details about the files, as one would see from commands like find
or ls
, it is required to call stat
on the file which is controlled by fuse.getattr
.
The POSIX filesystem API is made up of a number of functions. creat, stat, chown, etc. For ease of configuration in mergerfs, most of the core functions are grouped into 3 categories: action, create, and search. These functions and categories can be assigned a policy which dictates which branch is chosen when performing that function.
Some functions, listed in the category N/A
below, can not be assigned the normal policies because they are directly related to a file which has already been opened.
When using policies which are based on a branch's available space the base path provided is used. Not the full path to the file in question. Meaning that mounts in the branch won't be considered in the space calculations. The reason is that it doesn't really work for non-path preserving policies and can lead to non-obvious behaviors.
NOTE: While any policy can be assigned to a function or category, some may not be very useful in practice. For instance: rand (random) may be useful for file creation (create) but could lead to very odd behavior if used for chmod
if there were more than one copy of the file.
In cases where something may be searched for (such as a path to clone) getattr will usually be used.
"},{"location":"config/functions_categories_and_policies/#policies","title":"Policies","text":"A policy is the algorithm used to choose a branch or branches for a function to work on or generally how the function behaves.
Any function in the create
category will clone the relative path if needed. Some other functions (rename
,link
,ioctl
) have special requirements or behaviors which you can read more about below.
Most policies basically search branches and create a list of files / paths for functions to work on. The policy is responsible for filtering and sorting the branches. Filters include minfreespace, whether or not a branch is mounted read-only, and the branch tagging (RO,NC,RW). These filters are applied across most policies.
minfreespace
.Policies may have their own additional filtering such as those that require existing paths to be present.
If all branches are filtered an error will be returned. Typically EROFS (read-only filesystem) or ENOSPC (no space left on device) depending on the most recent reason for filtering a branch. ENOENT will be returned if no eligible branch is found.
If create, mkdir, mknod, or symlink fail with EROFS
or other fundamental errors then mergerfs will mark any branch found to be read-only as such (IE will set the mode RO
) and will rerun the policy and try again. This is mostly for ext4
filesystems that can suddenly become read-only when it encounters an error.
Policies, as described below, are of two basic classifications. path preserving
and non-path preserving
.
All policies which start with ep
(epff, eplfs, eplus, epmfs, eprand) are path preserving
. ep
stands for existing path
.
A path preserving policy will only consider branches where the relative path being accessed already exists.
When using non-path preserving policies paths will be cloned to target branches as necessary.
With the msp
or most shared path
policies they are defined as path preserving
for the purpose of controlling link
and rename
's behaviors since ignorepponrename
is available to disable that behavior.
A policy's behavior differs, as mentioned above, based on the function it is used with. Sometimes it really might not make sense to even offer certain policies because they are literally the same as others but it makes things a bit more uniform.
Policy Description all Search: For mkdir, mknod, and symlink it will apply to all branches. create works like ff. epall (existing path, all) For mkdir, mknod, and symlink it will apply to all found. create works like epff (but more expensive because it doesn't stop after finding a valid branch). epff (existing path, first found) Given the order of the branches, as defined at mount time or configured at runtime, act on the first one found where the relative path exists. eplfs (existing path, least free space) Of all the branches on which the relative path exists choose the branch with the least free space. eplus (existing path, least used space) Of all the branches on which the relative path exists choose the branch with the least used space. epmfs (existing path, most free space) Of all the branches on which the relative path exists choose the branch with the most free space. eppfrd (existing path, percentage free random distribution) Like pfrd but limited to existing paths. eprand (existing path, random) Calls epall and then randomizes. Returns 1. ff (first found) Given the order of the branches, as defined at mount time or configured at runtime, act on the first one found. lfs (least free space) Pick the branch with the least available free space. lus (least used space) Pick the branch with the least used space. mfs (most free space) Pick the branch with the most available free space. msplfs (most shared path, least free space) Like eplfs but if it fails to find a branch it will try again with the parent directory. Continues this pattern till finding one. msplus (most shared path, least used space) Like eplus but if it fails to find a branch it will try again with the parent directory. Continues this pattern till finding one. mspmfs (most shared path, most free space) Like epmfs but if it fails to find a branch it will try again with the parent directory. Continues this pattern till finding one. msppfrd (most shared path, percentage free random distribution) Like eppfrd but if it fails to find a branch it will try again with the parent directory. Continues this pattern till finding one. newest Pick the file / directory with the largest mtime. pfrd (percentage free random distribution) Chooses a branch at random with the likelihood of selection based on a branch's available space relative to the total. rand (random) Calls all and then randomizes. Returns 1 branch.NOTE: If you are using an underlying filesystem that reserves blocks such as ext2, ext3, or ext4 be aware that mergerfs respects the reservation by using f_bavail
(number of free blocks for unprivileged users) rather than f_bfree
(number of free blocks) in policy calculations. df does NOT use f_bavail
, it uses f_bfree
, so direct comparisons between df output and mergerfs' policies is not appropriate.
fuse_msg_size=UINT
256
FUSE applications communicate with the kernel over a special character device: /dev/fuse
. A large portion of the overhead associated with FUSE is the cost of going back and forth between user space and kernel space over that device. Generally speaking, the fewer trips needed the better the performance will be. Reducing the number of trips can be done a number of ways. Kernel level caching and increasing message sizes being two significant ones. When it comes to reads and writes if the message size is doubled the number of trips are approximately halved.
In Linux v4.20 a new feature was added allowing the negotiation of the max message size. Since the size is in multiples of pages the feature is called max_pages
. There is a maximum max_pages
value of 256 (1MiB) and minimum of 1 (4KiB). The default used by Linux >=4.20, and hardcoded value used before 4.20, is 32 (128KiB). In mergerfs it's referred to as fuse_msg_size to make it clear what it impacts and provide some abstraction.
Since there should be no downsides to increasing fuse_msg_size
, outside a minor increase in RAM usage due to larger message buffers, mergerfs defaults the value to 256. On kernels before v4.20 the value has no effect. The reason the value is configurable is to enable experimentation and benchmarking.
Inodes (st_ino
) are unique identifiers within a filesystem. Each mounted filesystem has device ID (st_dev) as well and together they can uniquely identify a file on the whole of the system. Entries on the same device with the same inode are in fact references to the same underlying file. It is a many to one relationship between names and an inode. Directories, however, do not have multiple links on most systems due to the complexity they add.
FUSE allows the server (mergerfs) to set inode values but not device IDs. Creating an inode value is somewhat complex in mergerfs' case as files aren't really in its control. If a policy changes what directory or file is to be selected or something changes out of band it becomes unclear what value should be used. Most software does not to care what the values are but those that do often break if a value changes unexpectedly. The tool find will abort a directory walk if it sees a directory inode change. NFS can return stale handle errors if the inode changes out of band. File dedup tools will usually leverage device ids and inodes as a shortcut in searching for duplicate files and would resort to full file comparisons should it find different inode values.
mergerfs offers multiple ways to calculate the inode in hopes of covering different usecases.
passthrough
: Passes through the underlying inode value. Mostly intended for testing as using this does not address any of the problems mentioned above and could confuse file deduplication software as inodes from different filesystems can be the same.path-hash
: Hashes the relative path of the entry in question. The underlying file's values are completely ignored. This means the inode value will always be the same for that file path. This is useful when using NFS and you make changes out of band such as copy data between branches. This also means that entries that do point to the same file will not be recognizable via inodes. That does not mean hard links don't work. They will.path-hash32
: 32bit version of path-hash.devino-hash
: Hashes the device id and inode of the underlying entry. This won't prevent issues with NFS should the policy pick a different file or files move out of band but will present the same inode for underlying files that do too.devino-hash32
: 32bit version of devino-hash.hybrid-hash
: Performs path-hash on directories and devino-hash on other file types. Since directories can't have hard links the static value won't make a difference and the files will get values useful for finding duplicates. Probably the best to use if not using NFS. As such it is the default.hybrid-hash32
: 32bit version of hybrid-hash.32bit versions are provided as there is some software which does not handle 64bit inodes well.
While there is a risk of hash collision in tests of a couple of million entries there were zero collisions. Unlike a typical filesystem FUSE filesystems can reuse inodes and not refer to the same entry. The internal identifier used to reference a file in FUSE is different from the inode value presented. The former is the nodeid and is actually a tuple of 2 64bit values: nodeid and generation. This tuple is not client facing. The inode that is presented to the client is passed through the kernel uninterpreted.
From FUSE docs for use_ino
:
Honor the st_ino field in the functions getattr() and fill_dir(). This value is used to fill in the st_ino field in the stat(2), lstat(2), fstat(2) functions and the d_ino field in the readdir(2) function. The filesystem does not have to guarantee uniqueness, however some applications rely on this value being unique for the whole filesystem. Note that this does not affect the inode that libfuse and the kernel use internally (also called the \"nodeid\").
NOTE: As of version 2.35.0 the use_ino option has been removed. mergerfs should always be managing inode values.
"},{"location":"config/link-exdev/","title":"link-exdev","text":"If using path preservation and a link
fails with EXDEV
make a call to symlink
where the target is the oldlink
and the linkpath
is the newpath. The target value is determined by the value of link-exdev
.
link-exdev=passthrough
: Return EXDEV as normal.link-exdev=rel-symlink
: A relative path from the newpath.link-exdev=abs-base-symlink
: An absolute value using the underlying branch.link-exdev=abs-pool-symlink
: An absolute value using the mergerfs mount point.passthrough
.NOTE: It is possible that some applications check the file they link. In those cases, it is possible it will error or complain.
"},{"location":"config/link_cow/","title":"link_cow","text":"link_cow=true|false
false
This feature offers similar functionality to what cow-shell offers.
When enabled if mergerfs is asked to open a file to write and the link count on the file is greater than 1 it will copy the file to a temporary new file and then rename it over the original. This will atomically \"break\" the link. After that it will open the new file.
"},{"location":"config/nfsopenhack/","title":"nfsopenhack","text":"nfsopenhack=off
: No hack applied.nfsopenhack=git
: Apply hack if path includes /.git/
.nfsopenhack=all
: Apply hack on all empty read-only files opened for writing.off
.NFS is not fully POSIX compliant and historically certain behaviors, such as opening files with O_EXCL
, are not or not well supported. When mergerfs (or any FUSE filesystem) is exported over NFS some of these issues come up due to how NFS and FUSE interact.
This hack addresses the issue where the creation of a file with a read-only mode but with a read/write or write only flag. Normally this is perfectly valid but NFS chops the one open call into multiple calls. Exactly how it is translated depends on the configuration and versions of the NFS server and clients but it results in a permission error because a normal user is not allowed to open a read-only file as writable.
Even though it's a more niche situation this hack breaks normal security and behavior and as such is off
by default. If set to git
it will only perform the hack when the path in question includes /.git/
. all
will result in it applying anytime a read-only file which is empty is opened for writing.
nullrw=true|false
false
.Due to how FUSE works there is an overhead to all requests made to a FUSE filesystem that wouldn't exist for an in kernel one. Meaning that even a simple passthrough will have some slowdown. However, generally the overhead is minimal in comparison to the cost of the underlying I/O. By disabling the underlying I/O we can test the theoretical performance boundaries.
By enabling nullrw
mergerfs will work as it always does except that all reads and writes will be no-ops. A write will succeed (the size of the write will be returned as if it were successful) but mergerfs does nothing with the data it was given. Similarly a read will return the size requested but won't touch the buffer.
See the benchmarking section for suggestions on how to test.
"},{"location":"config/options/","title":"Options","text":"These options are the same regardless of whether you use them with the mergerfs
commandline program, in fstab, or in a config file.
posix_fadvise
on it first to instruct the kernel that we no longer need the data and it can drop its cache. Recommended when cache.files=partial|full|auto-full|per-process to limit double caching. (default: false)create
(read below). Enabling this will cause rename and link to always use the non-path preserving behavior. This means files, when renamed or linked, will stay on the same filesystem. (default: false)process-thread-count=-1
) it sets the number of threads reading and processing FUSE messages. When used together it sets the number of threads reading from FUSE. When set to zero it will attempt to discover and use the number of logical cores. If the thread count is set negative it will look up the number of cores then divide by the absolute value. ie. threads=-2 on an 8 core machine will result in 8 / 2 = 4 threads. There will always be at least 1 thread. If set to -1 in combination with process-thread-count
then it will try to pick reasonable values based on CPU thread count. NOTE: higher number of threads increases parallelism but usually decreases throughput. (default: 0)threads
.read-thread-count
refers to the number of threads reading FUSE messages which are dispatched to process threads. -1 means disabled otherwise acts like read-thread-count
. (default: -1)setpriority
man page for more details. (default: -10)readdir
policy. INT value sets the number of threads to use for concurrency. (default: seq)cache.files=per-process
. (default: \"rtorrent|qbittorrent-nox\")cache.files=per-process
(if the process is not in process-names
) or cache.files=off
. (This requires kernel support, and was added in v6.2)NOTE: Options are evaluated in the order listed so if the options are func.rmdir=rand,category.action=ff the action category setting will override the rmdir setting.
NOTE: Always look at the documentation for the version of mergerfs you're using. Not all features are available in older releases.
"},{"location":"config/pin-threads/","title":"pin-threads","text":"Simple strategies for pinning read and/or process threads. If process threads are not enabled then the strategy simply works on the read threads. Invalid values are ignored.
pin-threads=R1L
: All read threads pinned to a single logical CPU.pin-threads=R1P
: All read threads pinned to a single physical CPU.pin-threads=RP1L
: All read and process threads pinned to a single logical CPU.pin-threads=RP1P
: All read and process threads pinned to a single physical CPU.pin-threads=R1LP1L
: All read threads pinned to a single logical CPU, all process threads pinned to a (if possible) different logical CPU.pin-threads=R1PP1P
: All read threads pinned to a single physical CPU, all process threads pinned to a (if possible) different logical CPU.pin-threads=RPSL
: All read and process threads are spread across all logical CPUs.pin-threads=RPSP
: All read and process threads are spread across all physical CPUs.pin-threads=R1PPSP
: All read threads are pinned to a single physical CPU while process threads are spread across all other physical CPUs.Sets the mergerfs and underlying filesystem readahead
values. The value unit is in kibibytes.
readahead=1024
While the max size of messages sent between the kernel and mergerfs is configurable via the fuse_msg_size option that doesn't mean that is the size used by the kernel for read and writes.
Linux has a max read/write size of 2GB. Since the max FUSE message size is just over 1MB the kernel will break up read and write requests with buffers larger than that 1MB.
When page caching is disabled (cache.files=off
), besides the kernel breaking up requests with larger buffers, requests are effectively one for one to mergerfs. A read or write request for X bytes is made to the kernel and a request for X bytes is made to mergerfs. No readahead behavior will occur because there is no page cache available for it to store that data. In FUSE this is referred to as \"direct IO\". Note that \"direct IO\" is not the same as O_DIRECT
.
When page caching is enabled the kernel can and will utilize readahead
. However, there are two values which impact the size of the readahead
requests. The filesystem's readahead
value and the FUSE max_readahead
value. Whichever is lowest is used. The default max_readahead
in mergerfs is maxed out meaning only the filesystem readahead
value is relevant.
Preferably this value would be set by the user externally since it is a generic feature but there is no standard way to do so mergerfs added this feature to make it easier to set.
There is currently no way to set separate values for different branches through mergerfs.
"},{"location":"config/rename-exdev/","title":"rename-exdev","text":"If using path preservation and a rename
fails with EXDEV
:
/branch/a/b/c
to /branch/.mergerfs_rename_exdev/a/b/c
.newpath
to the moved file.The target
value is determined by the value of rename-exdev
.
rename-exdev=passthrough
: Return EXDEV
as normal.rename-exdev=rel-symlink
: A relative path from the newpath
.rename-exdev=abs-symlink
: An absolute value using the mergerfs mount point.passthrough
.NOTE: It is possible that some applications check the file they rename. In those cases it is possible it will error or complain.
NOTE: The reason abs-symlink
is not split into two like link-exdev
is due to the complexities in managing absolute base symlinks when multiple oldpaths
exist.
NOTE: If you're receiving errors from software when files are moved / renamed / linked then you should consider changing the create policy to one which is not path preserving, enabling ignorepponrename
, or contacting the author of the offending software and requesting that EXDEV
(cross device / improper link) be properly handled.
rename
and link
are arguably the most complicated functions to create in a union filesystem. rename
only works within a single filesystem or device. If a rename can't be done due to the source and destination paths existing on different mount points it will return -1 with errno = EXDEV (cross device / improper link). So if a rename
's source and target are on different filesystems within the pool it creates an issue.
Originally mergerfs would return EXDEV whenever a rename was requested which was cross directory in any way. This made the code simple and was technically compliant with POSIX requirements. However, many applications fail to handle EXDEV at all and treat it as a normal error or otherwise handle it poorly. Such apps include: gvfsd-fuse v1.20.3 and prior, Finder / CIFS/SMB client in Apple OSX 10.9+, NZBGet, Samba's recycling bin feature.
As a result a compromise was made in order to get most software to work while still obeying mergerfs' policies. Below is the basic logic.
The removals are subject to normal entitlement checks. If the unlink fails it will fail silently.
The above behavior will help minimize the likelihood of EXDEV being returned but it will still be possible.
link uses the same strategy but without the removals.
"},{"location":"config/statfs/","title":"statfs / statvfs","text":"statfs=base
: Aggregate details from all branches using their base directory.statfs=full
: Aggregate details using the full path of the file requested. Limiting it to only branches where the file exists.base
. statvfs normalizes the source filesystems based on the fragment size and sums the number of adjusted blocks and inodes. This means you will see the combined space of all sources. Total, used, and free. The sources however are dedupped based on the filesystem so multiple sources on the same drive will not result in double counting its space. Other filesystems mounted further down the tree of the branch will not be included when checking the mount's stats.
"},{"location":"config/statfs/#statfs_ignore","title":"statfs_ignore","text":"Modifies how statfs
works. Will cause it to ignore branches of a certain mode.
statfs_ignore=none
: Include all branches.statfs_ignore=ro
: Ignore available space for branches mounted as read-only or have a mode RO
or NC
.statfs_ignore=nc
: Ignore available space for branches with a mode of NC
.none
.symlinkify=true|false
false
.Due to the levels of indirection introduced by mergerfs and the underlying technology FUSE there can be varying levels of performance degradation. This feature will turn non-directories which are not writable into symlinks to the original file found by the readlink
policy after the mtime and ctime are older than the timeout.
WARNING: The current implementation has a known issue in which if the file is open and being used when the file is converted to a symlink then the application which has that file open will receive an error when using it. This is unlikely to occur in practice but is something to keep in mind.
WARNING: Some backup solutions, such as CrashPlan, do not backup the target of a symlink. If using this feature it will be necessary to point any backup software to the original filesystems or configure the software to follow symlinks if such an option is available. Alternatively, create two mounts. One for backup and one for general consumption.
"},{"location":"config/terminology/","title":"Terminology","text":"branch
: A base path used in the pool. Keep in mind that mergerfs does not work on devices or even filesystems but on paths. It can accomidate for multiple paths pointing to the same filesystem.pool
: The mergerfs mount. The union of the branches. The instance of mergerfs. You can have as many pools as you wish.relative path
: The path in the pool relative to the branch and mount.function
: A filesystem call (open, unlink, create, getattr, rmdir, etc.)category
: A collection of functions based on basic behavior (action, create, search).policy
: The algorithm used to select a file or files when performing a function.path preservation
: Aspect of some policies which includes checking the path for which a file would be created.There are multiple thread pools used in mergerfs to provide parallel behaviors.
"},{"location":"config/threads/#read-thread-count","title":"read-thread-count","text":"The number of threads used to read (and possibly process) messages from the kernel.
read-thread-count=0
: Create a thread pool sized to the number of logical CPUs.read-thread-count=N
where N>0
: Create a thread pool of N
threads.read-thread-count=N
where N<0
: Create a thread pool of CPUCount / -N
threads.read-thread-count=-1
where process-thread-count=-1
: Creates 2
read threads and max(2,CPUCount-2)
process threads.0
.When process-thread-count=-1
(the default) this option sets the number of threads which read and then process requests from the kernel.
When process-thread-count
is set to anything else mergerfs will create two thread pools. A \"read\" thread pool which just reads from the kernel and hands off requests to the \"process\" thread pool.
Generally, only 1 or 2 \"read\" threads are necessary.
"},{"location":"config/threads/#process-thread-count","title":"process-thread-count","text":"When enabled this sets the number of threads in the message processing pool.
process-thread-count=-1
: Process thread pool is disabled.process-thread-count=0
: Create a thread pool sized to the number of logical CPUs.process-thread-count=N
where N>0
: Create a thread pool of N
threads.process-thread-count=N
where N<-1
: Create a thread pool of CPUCount / -N
threads.-1
.process-thread-queue-depth=N
where N>0
: Sets the number of outstanding requests that a process thread can have to N. If requests come in faster than can be processed and the max queue depth hit then queuing the request will block in order to limit memory growth.process-thread-queue-depth=0
: Sets the queue depth to the thread pool count.0
.xattr=passthrough
: Passes through all requests to underlying file.xattr=noattr
: mergerfs receives the request but returns NOATTR
.xattr=nosys
: Tells the kernel to reject all xattr
requests.passthrough
.Runtime extended attribute support can be managed via the xattr
option. By default it will passthrough any xattr calls. Given xattr support is rarely used and can have significant performance implications mergerfs allows it to be disabled at runtime. The performance problems mostly comes when file caching is enabled. The kernel will send a getxattr
for security.capability
before every single write. It doesn't cache the responses to any getxattr
. This might be addressed in the future but for now mergerfs can really only offer the following workarounds.
noattr
will cause mergerfs to short circuit all xattr calls and return ENOATTR where appropriate. mergerfs still gets all the requests but they will not be forwarded on to the underlying filesystems. The runtime control will still function in this mode.
nosys
will cause mergerfs to return ENOSYS
for any xattr call. The difference with noattr
is that the kernel will cache this fact and itself short circuit future calls. This is more efficient than noattr
but will cause mergerfs' runtime control via the hidden file to stop working.
Yes. They are completely unrelated pieces of software that just happen to work well together.
"},{"location":"faq/compatibility_and_integration/#does-mergerfs-support-cow-copy-on-write-writes-to-read-only-filesystems","title":"Does mergerfs support CoW / copy-on-write / writes to read-only filesystems?","text":"Not in the sense of a filesystem like BTRFS or ZFS nor in the overlayfs or aufs sense. It does offer a cow-shell like hard link breaking (copy to temp file then rename over original) which can be useful when wanting to save space by hardlinking duplicate files but wish to treat each name as if it were a unique and separate file.
If you want to write to a read-only filesystem you should look at overlayfs. You can always include the overlayfs mount into a mergerfs pool.
"},{"location":"faq/compatibility_and_integration/#can-mergerfs-run-via-docker-podman-kubernetes-etc","title":"Can mergerfs run via Docker, Podman, Kubernetes, etc.","text":"Yes. With Docker you'll need to include --cap-add=SYS_ADMIN --device=/dev/fuse --security-opt=apparmor:unconfined
or similar with other container runtimes. You should also be running it as root or given sufficient caps to change user and group identity as well as have root like filesystem permissions.
Keep in mind that you MUST consider identity when using containers. For example: supplemental groups will be picked up from the container unless you properly manage users and groups by sharing relevant /etc files or by using some other means to share identity across containers. Similarly, if you use \"rootless\" containers and user namespaces to do uid/gid translations you MUST consider that while managing shared files.
Also, as mentioned by hotio, with Docker you should probably be mounting with bind-propagation
set to slave
.
Unless you're doing something more niche the average user is probably best off using mfs
for category.create
. It will spread files out across your branches based on available space. Use mspmfs
if you want to try to colocate the data a bit more. You may want to use lus
if you prefer a slightly different distribution of data if you have a mix of smaller and larger filesystems. Generally though mfs
, lus
, or even rand
are good for the general use case. If you are starting with an imbalanced pool you can use the tool mergerfs.balance to redistribute files across the pool. That said \"balancing\" really should not be needed. There is really no inherent issue with being unbalanced. \"Optimal\" layout is related to usage patterns and most people don't have patterns that are performance sensitive or specific enough to do anything about. Additionally, the balance tool is very simplistic and was not written to be as serious tool that accounts for edge cases.
If you really wish to try to colocate files based on directory you can set func.create
to epmfs
or similar and func.mkdir
to rand
or eprand
depending on if you just want to colocate generally or on specific branches. Either way the need to colocate is rare. For instance: if you wish to remove the device regularly and want the data to predictably be on that device or if you don't use backup at all and don't wish to replace that data piecemeal. In which case using path preservation can help but will require some manual attention. Colocating after the fact can be accomplished using the mergerfs.consolidate tool. If you don't need strict colocation which the ep
policies provide then you can use the msp
based policies which will walk back the path till finding a branch that works.
Ultimately there is no correct answer. It is a preference or based on some particular need. mergerfs is very easy to test and experiment with. I suggest creating a test setup and experimenting to get a sense of what you want.
epmfs
is the default category.create
policy because ep
policies are not going to change the general layout of the branches. It won't place files/dirs on branches that don't already have the relative branch. So it keeps the system in a known state. It's much easier to stop using epmfs
or redistribute files around the filesystem than it is to consolidate them back.
Depends on what features you want. Generally speaking, there are no \"wrong\" settings. All settings are feature related. The best bet is to read over the available options and choose what fits your situation. If something isn't clear from the documentation please reach out and the documentation will be improved.
For the average person the settings described in the Quick Start are sufficient.
"},{"location":"faq/configuration_and_policies/#why-are-all-my-files-ending-up-on-1-filesystem","title":"Why are all my files ending up on 1 filesystem?!","text":"Did you start with empty filesystems? Did you explicitly configure a category.create
policy? Are you using an existing path
/ path preserving
policy?
The default create policy is epmfs
. That is a path preserving algorithm. With such a policy for mkdir
and create
with a set of empty filesystems it will select only 1 filesystem when the first directory is created. Anything, files or directories, created in that first directory will be placed on the same branch because it is preserving paths.
This may catch new users off guard but this policy is the safest policy to start with as it will not change the general layout of the underlying filesystems. If you do not care about path preservation (most shouldn't) and wish your files to be spread across all your filesystems change to mfs
or similar policy. If you do want path preservation you'll need to perform the manual act of creating paths on the filesystems you want the data to land on before transferring your data.
TL;DR: You really can't. Not through mergerfs alone.
mergerfs is a proxy. Not a cache. It proxies calls between client software and underlying filesystems. If a client does an open
, readdir
, stat
, etc. it must translate that into something that makes sense across N filesystems. For readdir
that means running the call against all branches and aggregating the output. For open
that means finding the file to open and doing so. The only way to find the file to open is to scan across all branches and sort the results and pick one. There is no practical way to do otherwise. Especially given so many mergerfs users expect out of band changes to \"just work.\"
The best way to limit spinup of drives is to limit their usage at the client level. Meaning keeping software from interacting with the filesystem all together.
"},{"location":"faq/limit_drive_spinup/#what-if-you-assume-no-out-of-band-changes-and-cache-everything","title":"What if you assume no out of band changes and cache everything?","text":"This would require a significant rewrite of mergerfs. Everything is done on the fly right now and all those calls to underlying filesystems can cause a spinup. To work around that a database of some sort would have to be used to store ALL metadata about the underlying filesystems and on startup everything scanned and stored. From then on it would have to carefully update all the same data the filesystems do. It couldn't be kept in RAM because it would take up too much space so it'd have to be on a SSD or other storage device. If anything changed out of band it would break things in weird ways. It could rescan on occasion but that would require spinning up everything. It could put file watches on every single directory but that probably won't scale (there are millions of directories in my system for example) and the open files might keep the drives from spinning down. Something as \"simple\" as keeping the current available free space on each filesystem isn't as easy as one might think given reflinks, snapshots, and other block level dedup technologies.
Even if all metadata (including xattrs) is cached some software will open files (media like videos and audio) to check their metadata. Granted a Plex or Jellyfin scan which may do that is different from a random directory listing but is still something to consider. Those \"deep\" scans can't be kept from waking drives.
"},{"location":"faq/limit_drive_spinup/#what-if-you-only-query-already-active-drives","title":"What if you only query already active drives?","text":"Let's assume that is plausible (it isn't because some drives actually will spin up if you ask if they are spun down... yes... really) you would have to either cache all the metadata on the filesystem or treat it like the filesystem doesn't exist. The former has all the problems mentioned prior and the latter would break a lot of things.
"},{"location":"faq/limit_drive_spinup/#is-there-anything-that-can-be-done-where-mergerfs-is-involved","title":"Is there anything that can be done where mergerfs is involved?","text":"Yes, but whether it works for you depends on your tolerance for the complexity.
Remember too that while it may be a tradeoff you're willing to live with there is decent evidence that spinning down drives puts increased wear on them and can lead to their death earlier than otherwise.
"},{"location":"faq/recommendations_and_warnings/","title":"Recommendations and Warnings","text":""},{"location":"faq/recommendations_and_warnings/#what-should-mergerfs-not-be-used-for","title":"What should mergerfs NOT be used for?","text":"mhddfs manages running as root
by calling getuid() and if it returns 0
then it will chown the file. Not only is that a race condition but it doesn't handle other situations. Rather than attempting to simulate POSIX ACL behavior the proper way to manage this is to use seteuid and setegid, in effect, becoming the user making the original call, and perform the action as them. This is what mergerfs does and why mergerfs should always run as root.
In Linux setreuid syscalls apply only to the thread. glibc hides this away by using realtime signals to inform all threads to change credentials. Taking after Samba, mergerfs uses syscall(SYS_setreuid,...)
to set the callers credentials for that thread only. Jumping back to root
as necessary should escalated privileges be needed (for instance: to clone paths between filesystems).
For non-Linux systems, mergerfs uses a read-write lock and changes credentials only when necessary. If multiple threads are to be user X then only the first one will need to change the processes credentials. So long as the other threads need to be user X they will take a readlock allowing multiple threads to share the credentials. Once a request comes in to run as user Y that thread will attempt a write lock and change to Y's credentials when it can. If the ability to give writers priority is supported then that flag will be used so threads trying to change credentials don't starve. This isn't the best solution but should work reasonably well assuming there are few users.
"},{"location":"faq/reliability_and_scalability/","title":"Reliability and Scalability","text":""},{"location":"faq/reliability_and_scalability/#is-mergerfs-production-ready","title":"Is mergerfs \"production ready?\"","text":"Yes.
mergerfs has been around for over a decade and used by many users on their systems. Typically running 24/7 with constant load.
At least a few companies are believed to use mergerfs in production environments. A number of NAS focused operating systems includes mergerfs as a solution for pooling filesystems.
Most serious issues (crashes or data corruption) have been due to kernel bugs. All of which are fixed in stable releases.
"},{"location":"faq/reliability_and_scalability/#how-well-does-mergerfs-scale","title":"How well does mergerfs scale?","text":"Users have reported running mergerfs on everything from OpenWRT routers and Raspberry Pi SBCs to multi-socket Xeon enterprise servers.
Users have pooled everything from USB thumb drives to enterprise NVME SSDs to remote filesystems and rclone mounts.
The cost of many calls can be O(n)
meaning adding more branches to the pool will increase the cost of certain functions but there are a number of caches and strategies in place to limit overhead where possible.
Yes. See also the option inodecalc
for how inode values are calculated.
What mergerfs does not do is fake hard links across branches. Read the section \"rename & link\" for how it works.
Remember that hardlinks will NOT work across devices. That includes between the original filesystem and a mergerfs pool, between two separate pools of the same underlying filesystems, or bind mounts of paths within the mergerfs pool. The latter is common when using Docker or Podman. Multiple volumes (bind mounts) to the same underlying filesystem are considered different devices. There is no way to link between them. You should mount in the highest directory in the mergerfs pool that includes all the paths you need if you want links to work.
"},{"location":"faq/technical_behavior_and_limitations/#how-does-mergerfs-handle-moving-and-copying-of-files","title":"How does mergerfs handle moving and copying of files?","text":"This is a very common mistaken assumption regarding how filesystems work. There is no such thing as \"move\" or \"copy.\" These concepts are high level behaviors made up of numerous independent steps and not individual filesystem functions.
A \"move\" can include a \"copy\" so lets describe copy first.
When an application copies a file from source to destination it can do so in a number of ways but the basics are the following.
open
the source file.create
the destination file.read
a chunk of data from source and write
to destination. Continue till it runs out of data to copy.stat
) such as ownership (chown
), permissions (chmod
), timestamps (utimes
), extended attributes (getxattr
, setxattr
), etc.close
source and destination files.\"move\" is typically a rename(src,dst)
and if that errors with EXDEV
(meaning the source and destination are on different filesystems) the application will \"copy\" the file as described above and then it removes (unlink
) the source.
The rename(src,dst)
, open(src)
, create(dst)
, data copying, metadata copying, unlink(src)
, etc. are entirely distinct and separate events. There is really no practical way to know that what is ultimately occurring is the \"copying\" of a file or what the source file would be. Since the source is not known there is no way to know how large a created file is destined to become. This is why it is impossible for mergerfs to choose the branch for a create
based on file size. The only context provided when a file is created, besides the name, is the permissions, if it is to be read and/or written, and some low level settings for the operating system.
All of this means that mergerfs can not make decisions when a file is created based on file size or the source of the data. That information is simply not available. At best mergerfs could respond to files reaching a certain size when writing data or when a file is closed.
Related: if a user wished to have mergerfs perform certain activities based on the name of a file it is common and even best practice for a program to write to a temporary file first and then rename to its final destination. That temporary file name will typically be random and have no indication of the type of file being written.
"},{"location":"faq/technical_behavior_and_limitations/#does-ficlone-or-ficlonerange-work","title":"Does FICLONE or FICLONERANGE work?","text":"Unfortunately not. FUSE, the technology mergerfs is based on, does not support the clone_file_range
feature needed for it to work. mergerfs won't even know such a request is made. The kernel will simply return an error back to the application making the request.
Should FUSE gain the ability mergerfs will be updated to support it.
"},{"location":"faq/technical_behavior_and_limitations/#why-do-i-get-an-out-of-space-no-space-left-on-device-enospc-error-even-though-there-appears-to-be-lots-of-space-available","title":"Why do I get an \"out of space\" / \"no space left on device\" / ENOSPC error even though there appears to be lots of space available?","text":"First make sure you've read the sections above about policies, path preservation, branch filtering, and the options minfreespace, moveonenospc, statfs, and statfs_ignore.
mergerfs is simply presenting a union of the content within multiple branches. The reported free space is an aggregate of space available within the pool (behavior modified by statfs and statfs_ignore). It does not represent a contiguous space. In the same way that read-only filesystems, those with quotas, or reserved space report the full theoretical space available.
Due to path preservation, branch tagging, read-only status, and minfreespace settings it is perfectly valid that ENOSPC
/ \"out of space\" / \"no space left on device\" be returned. It is doing what was asked of it: filtering possible branches due to those settings. Only one error can be returned and if one of the reasons for filtering a branch was minfreespace then it will be returned as such. moveonenospc is only relevant to writing a file which is too large for the filesystem it's currently on.
It is also possible that the filesystem selected has run out of inodes. Use df -i
to list the total and available inodes per filesystem.
If you don't care about path preservation then simply change the create
policy to one which isn't. mfs
is probably what most are looking for. The reason it's not default is because it was originally set to epmfs
and changing it now would change people's setup. Such a setting change will likely occur in mergerfs 3.
Are you using ext2/3/4? With reserve for root? mergerfs uses available space for statfs calculations. If you've reserved space for root then it won't show up.
You can remove the reserve by running: tune2fs -m 0 <device>
When file caching is enabled in any form (cache.files!=off
) it will issue getxattr
requests for security.capability
prior to every single write. This will usually result in performance degradation, especially when using a network filesystem (such as NFS or SMB.) Unfortunately at this moment, the kernel is not caching the response.
To work around this situation mergerfs offers a few solutions.
security_capability=false
. It will short circuit any call and return ENOATTR
. This still means though that mergerfs will receive the request before every write but at least it doesn't get passed through to the underlying filesystem.xattr=noattr
. Same as above but applies to all calls to getxattr. Not just security.capability
. This will not be cached by the kernel either but mergerfs' runtime config system will still function.xattr=nosys
. Results in mergerfs returning ENOSYS
which will be cached by the kernel. No future xattr calls will be forwarded to mergerfs. The downside is that also means the xattr based config and query functionality won't work either.mmap
it's probably simpler to just disable it altogether. The kernel won't send the requests when caching is disabled.It's almost always a permissions issue. Unlike mhddfs and unionfs-fuse, which runs as root and attempts to access content as such, mergerfs always changes its credentials to that of the caller. This means that if the user does not have access to a file or directory than neither will mergerfs. However, because mergerfs is creating a union of paths it may be able to read some files and directories on one filesystem but not another resulting in an incomplete set.
Whenever you run into a split permission issue (seeing some but not all files) try using mergerfs.fsck tool to check for and fix the mismatch. If you aren't seeing anything at all be sure that the basic permissions are correct. The user and group values are correct and that directories have their executable bit set. A common mistake by users new to Linux is to chmod -R 644
when they should have chmod -R u=rwX,go=rX
.
If using a network filesystem such as NFS or SMB (Samba) be sure to pay close attention to anything regarding permissioning and users. Root squashing and user translation for instance has bitten a few mergerfs users. Some of these also affect the use of mergerfs from container platforms such as Docker.
"},{"location":"faq/technical_behavior_and_limitations/#why-use-fuse-why-not-a-kernel-based-solution","title":"Why use FUSE? Why not a kernel based solution?","text":"As with any solution to a problem, there are advantages and disadvantages to each one.
A FUSE based solution has all the downsides of FUSE:
But FUSE also has a lot of upsides:
No. Normally mount.fuse
is needed to get mergerfs (or any FUSE filesystem to mount using the mount
command but in vendoring the libfuse library the mount.fuse
app has been renamed to mount.mergerfs
meaning the filesystem type in fstab
can simply be mergerfs
. That said there should be no harm in having it installed and continuing to using fuse.mergerfs
as the type in /etc/fstab
.
If mergerfs
doesn't work as a type it could be due to how the mount.mergerfs
tool was installed. Must be in /sbin/
with proper permissions.
After a lot of testing over the years, splicing always appeared to at best, provide equivalent performance, and in some cases, worse performance. Splice is not supported on other platforms forcing a traditional read/write fallback to be provided. The splice code was removed to simplify the codebase.
"},{"location":"faq/usage_and_functionality/","title":"Usage and Functionality","text":""},{"location":"faq/usage_and_functionality/#can-mergerfs-be-used-with-filesystems-which-already-have-data-are-in-use","title":"Can mergerfs be used with filesystems which already have data / are in use?","text":"Yes. mergerfs is really just a proxy and does NOT interfere with the normal form or function of the filesystems, mounts, paths it manages. A userland application that is acting as a man-in-the-middle. It can't do anything that any other random piece of software can't do.
mergerfs is not a traditional filesystem that takes control over the underlying block device. mergerfs is not RAID. It does not manipulate the data that passes through it. It does not shard data across filesystems. It merely shards some behavior and aggregates others.
"},{"location":"faq/usage_and_functionality/#can-filesystems-be-removed-from-the-pool-without-affecting-them","title":"Can filesystems be removed from the pool without affecting them?","text":"Yes. See previous question's answer.
"},{"location":"faq/usage_and_functionality/#can-mergerfs-be-removed-without-affecting-the-data","title":"Can mergerfs be removed without affecting the data?","text":"Yes. See the previous question's answer.
"},{"location":"faq/usage_and_functionality/#can-filesystems-be-moved-to-another-pool","title":"Can filesystems be moved to another pool?","text":"Yes. See the previous question's answer.
"},{"location":"faq/usage_and_functionality/#can-filesystems-be-part-of-multiple-pools","title":"Can filesystems be part of multiple pools?","text":"Yes.
"},{"location":"faq/usage_and_functionality/#how-do-i-migrate-data-into-or-out-of-the-pool-when-addingremoving-filesystems","title":"How do I migrate data into or out of the pool when adding/removing filesystems?","text":"You don't need to. See the previous question's answer.
"},{"location":"faq/usage_and_functionality/#how-do-i-remove-a-filesystem-but-keep-the-data-in-the-pool","title":"How do I remove a filesystem but keep the data in the pool?","text":"Nothing special needs to be done. Remove the branch from mergerfs' config and copy (rsync) the data from the removed filesystem into the pool. The same as if it were you transfering data from one filesystem to another.
If you wish to continue using the pool while performing the transfer simply create a temporary pool without the filesystem in question and then copy the data. It would probably be a good idea to set the branch to RO
prior to doing this to ensure no new content is written to the filesystem while performing the copy.
Yes, however, it's not recommended to use the same file from within the pool and from without at the same time (particularly writing). Especially if using caching of any kind (cache.files, cache.entry, cache.attr, cache.negative_entry, cache.symlinks, cache.readdir, etc.) as there could be a conflict between cached data and not.
"},{"location":"setup/build/","title":"Build","text":"NOTE: Prebuilt packages can be found at and recommended for most users: https://github.com/trapexit/mergerfs/releases
NOTE: Only tagged releases are supported. master
and other branches should be considered works in progress.
First, get the code from github.
$ git clone https://github.com/trapexit/mergerfs.git\n$ # or\n$ wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ver>.tar.gz\n
"},{"location":"setup/build/#debian-ubuntu","title":"Debian / Ubuntu","text":"$ cd mergerfs\n$ sudo tools/install-build-pkgs\n$ make deb\n$ sudo dpkg -i ../mergerfs_<version>_<arch>.deb\n
"},{"location":"setup/build/#rhel-centos-rocky-fedora","title":"RHEL / CentOS / Rocky / Fedora","text":"$ su -\n# cd mergerfs\n# tools/install-build-pkgs\n# make rpm\n# rpm -i rpmbuild/RPMS/<arch>/mergerfs-<version>.<arch>.rpm\n
"},{"location":"setup/build/#generic","title":"Generic","text":"Have git, g++, make, python installed.
$ cd mergerfs\n$ make\n$ sudo make install\n
"},{"location":"setup/build/#build-options","title":"Build options","text":"$ make help\nusage: make\n\nmake USE_XATTR=0 - build program without xattrs functionality\nmake STATIC=1 - build static binary\nmake LTO=1 - build with link time optimization\n
"},{"location":"setup/installation/","title":"Installation","text":"If you are using a non-rolling release Linux distro such as Debian or Ubuntu then you are almost certainly going to have an old version of mergerfs installed if you use the \"official\" package. For that reason we provide packages for major stable released distros.
Before reporting issues or bugs please be sure to upgrade to the latest release to confirm they still exist.
All provided packages can be found at https://github.com/trapexit/mergerfs/releases
"},{"location":"setup/installation/#debian","title":"Debian","text":"Most Debian installs are of a stable branch and therefore do not have the most up to date software. While mergerfs is available via apt
it is suggested that users install the most recent version available from the releases page.
wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs_<ver>.debian-<rel>_<arch>.deb\nsudo dpkg -i mergerfs_<ver>.debian-<rel>_<arch>.deb\n
"},{"location":"setup/installation/#apt","title":"apt","text":"sudo apt install -y mergerfs\n
"},{"location":"setup/installation/#ubuntu","title":"Ubuntu","text":"Most Ubuntu installs are of a stable branch and therefore do not have the most up to date software. While mergerfs is available via apt
it is suggested that users install the most recent version available from the releases page.
wget https://github.com/trapexit/mergerfs/releases/download/<version>/mergerfs_<ver>.ubuntu-<rel>_<arch>.deb\nsudo dpkg -i mergerfs_<ver>.ubuntu-<rel>_<arch>.deb\n
"},{"location":"setup/installation/#apt_1","title":"apt","text":"sudo apt install -y mergerfs\n
"},{"location":"setup/installation/#raspberry-pi-os","title":"Raspberry Pi OS","text":"The same as Debian or Ubuntu.
"},{"location":"setup/installation/#fedora","title":"Fedora","text":"Get the RPM from the releases page.
wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ver>.fc<rel>.<arch>.rpm\nsudo rpm -i mergerfs-<ver>.fc<rel>.<arch>.rpm\n
"},{"location":"setup/installation/#centos-rocky","title":"CentOS / Rocky","text":"Get the RPM from the releases page.
wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ver>.el<rel>.<arch>.rpm\nsudo rpm -i mergerfs-<ver>.el<rel>.<arch>.rpm\n
"},{"location":"setup/installation/#archlinux","title":"ArchLinux","text":"pacman -S mergerfs
Static binaries are provided for situations where native packages are unavailable.
Get the tarball from the releases page.
wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-static-linux_<arch>.tar.gz\nsudo tar xvf mergerfs-static-linux_<arch>.tar.gz -C /\n
"},{"location":"setup/upgrade/","title":"Upgrade","text":"mergerfs can be upgraded live by mounting on top of the previous instance. Simply install the new version of mergerfs and follow the instructions below.
Run mergerfs again or if using /etc/fstab
call for it to mount again. Existing open files and such will continue to work fine though they won't see runtime changes since any such change would be the new mount. If you plan on changing settings with the new mount you should / could apply those before mounting the new version.
$ sudo mount /mnt/mergerfs\n$ mount | grep mergerfs\nmedia on /mnt/mergerfs type mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)\nmedia on /mnt/mergerfs type mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)\n
A problem with this approach is that the underlying instance will continue to run even if the software using it stop or are restarted. To work around this you can use a \"lazy umount\". Before mounting over top the mount point with the new instance of mergerfs issue: umount -l <mergerfs_mountpoint>
. Or you can let mergerfs do it by setting the option lazy-umount-mountpoint=true
.