mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-30 03:47:02 -05:00
Improve mount waiting + misc doc improvements
Adds user.mergerfs.branch and user.mergerfs.branch_mounts_here Adds .mergerfs.branch and .mergerfs.branch_mounts_here files.
This commit is contained in:
parent
212681ddc5
commit
de2a82800a
26 changed files with 583 additions and 212 deletions
|
|
@ -1,18 +1,20 @@
|
|||
# branches
|
||||
|
||||
The 'branches' argument is a colon (':') delimited list of paths to be
|
||||
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.
|
||||
different filesystems nor does it matter [the filesystem
|
||||
type](../faq/compatibility_and_integration.md/#what-filesystems-can-be-used-as-branches)
|
||||
(within reason). Used and available space metrics 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`
|
||||
Branches currently have two options which can be set. A
|
||||
[mode](#branch-mode) which impacts whether or not the branch is
|
||||
included in a policy calculation and a individual
|
||||
[minfreespace](#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`
|
||||
|
||||
|
||||
### branch mode
|
||||
|
|
@ -29,7 +31,7 @@ delimiters. Example: `/mnt/drive=RW,1234`
|
|||
### minfreespace
|
||||
|
||||
Same purpose and syntax as the [global option](minfreespace.md) but
|
||||
specific to the branch. If not set the global value is used.
|
||||
specific to the branch. Defaults to the global value.
|
||||
|
||||
|
||||
### globbing
|
||||
|
|
@ -43,8 +45,8 @@ apply the glob itself.**
|
|||
# mergerfs /mnt/hdd\*:/mnt/ssd /media
|
||||
```
|
||||
|
||||
The above line will use all mount points in /mnt prefixed with **hdd**
|
||||
and **ssd**.
|
||||
The above line will use all directories in /mnt prefixed with **hdd**
|
||||
as well as **ssd**.
|
||||
|
||||
To have the pool mounted at boot or otherwise accessible from related
|
||||
tools use `/etc/fstab`.
|
||||
|
|
@ -54,4 +56,154 @@ tools use `/etc/fstab`.
|
|||
/mnt/hdd*:/mnt/ssd /media mergerfs minfreespace=16G 0 0
|
||||
```
|
||||
|
||||
**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.
|
||||
**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.
|
||||
|
||||
A convenient way to configure branches is to use
|
||||
[symlinks](../quickstart.md/#etcfstab-w-config-file).
|
||||
|
||||
|
||||
## branch setup
|
||||
|
||||
mergerfs does not require any special setup of branch paths in order
|
||||
to be used however here are some suggestions.
|
||||
|
||||
|
||||
### layout
|
||||
|
||||
When you have a large collection of storage devices, types of storage,
|
||||
and types of interconnects it can be useful to have a verbose naming
|
||||
convention. My preference is to create a directory within `/mnt/` for
|
||||
each major type of storage device and/or interconnect. `hdd` for
|
||||
traditional hard drives; `ssd` for slower SATA based SSDs; `nvme` for
|
||||
M.2 or U.2 NVME SSDs; `remote` for NFS, SMB, sshfs, etc.
|
||||
|
||||
The mount points within those directories are named after the size of
|
||||
the storage and its serial number in the case of physical storage and
|
||||
the hostname and remote filesystem for remote.
|
||||
|
||||
```
|
||||
$ ls -lh /mnt/
|
||||
total 16K
|
||||
drwxr-xr-x 8 root root 4.0K Aug 18 2024 hdd
|
||||
drwxr-xr-x 6 root root 4.0K Oct 8 2024 nvme
|
||||
drwxr-xr-x 3 root root 4.0K Aug 24 2024 remote
|
||||
drwxr-xr-x 3 root root 4.0K Jul 14 2024 ssd
|
||||
|
||||
$ ls -lh /mnt/hdd/
|
||||
total 8K
|
||||
d--------- 2 root root 4.0K Apr 14 15:58 10T-01234567
|
||||
d--------- 2 root root 4.0K Apr 12 20:51 20T-12345678
|
||||
|
||||
$ ls -lh /mnt/nvme/
|
||||
total 8K
|
||||
d--------- 2 root root 4.0K Apr 14 16:00 1T-ABCDEFGH
|
||||
d--------- 2 root root 4.0K Apr 14 23:24 1T-BCDEFGHI
|
||||
|
||||
$ ls -lh /mnt/remote/
|
||||
total 8K
|
||||
d--------- 2 root root 4.0K Apr 12 20:23 foo-sshfs
|
||||
d--------- 2 root root 4.0K Apr 12 20:24 bar-nfs
|
||||
|
||||
# You can find the serial number of a drive using lsblk
|
||||
$ lsblk -d -o NAME,PATH,SIZE,SERIAL
|
||||
NAME PATH SIZE SERIAL
|
||||
sda /dev/sda 9.1T 01234567
|
||||
sdb /dev/sdb 18.2T 12345678
|
||||
nvme0n1 /dev/nvme0n1 953.9G ABCDEFGH
|
||||
nvme1n1 /dev/nvme1n1 953.9G BCDEFGHI
|
||||
```
|
||||
|
||||
|
||||
### permissions and mode
|
||||
|
||||
#### mount points
|
||||
|
||||
To ensure the directory is **only** used as a point to mount another
|
||||
filesystem it is good to lock it down as much as possible. Be sure to
|
||||
do this **before** mounting a filesystem to it.
|
||||
|
||||
```
|
||||
$ sudo chown root:root /mnt/hdd/10T-XYZ
|
||||
$ sudo chmod 0000 /mnt/hdd/10T-XYZ
|
||||
$ sudo setfattr -n user.mergerfs.branch_mounts_here
|
||||
$ sudo chattr +i /mnt/hdd/10T-XYZ
|
||||
```
|
||||
|
||||
The extended attribute `user.mergerfs.branch_mounts_here` is used by
|
||||
the [branches-mount-timeout](branches_mount_timeout.md) option to
|
||||
recognize whether or not a mergerfs branch path points to the intended
|
||||
filesystem.
|
||||
|
||||
The `chattr` is likely to only work on EXT{2,3,4} filesystems but will
|
||||
restrict even `root` from modifying the directory or its content.
|
||||
|
||||
|
||||
#### mounted filesystems
|
||||
|
||||
For those new to Linux, intending to be the primary individual logged
|
||||
into the system, or simply want to simplify permissions it is
|
||||
recommended to set the root of mounted filesystems like `/tmp/` is set
|
||||
to. Owned by `root`, `ugo+rwx` and [sticky
|
||||
bit](https://en.wikipedia.org/wiki/Sticky_bit) set.
|
||||
|
||||
This must be done **after** mounting the filesystem to the target
|
||||
mount point.
|
||||
|
||||
```
|
||||
$ sudo chown root:root /mnt/hdd/10T-SERIALNUM
|
||||
$ sudo chmod 1777 /mnt/hdd/10T-SERIALNUM
|
||||
$ sudo setfattr -n user.mergerfs.branch /mnt/hdd/10T-SERIALNUM
|
||||
```
|
||||
|
||||
|
||||
### formatting
|
||||
|
||||
While even less relevant to mergerfs than the details above the topic
|
||||
does com up regularly with mergerfs users. When it comes to
|
||||
partitioning and formatting it is suggested to keep things
|
||||
simple. Most users of mergerfs will be using the whole drive capacity
|
||||
and as such have a singular partition and filesystem on that
|
||||
partition. Something many people don't realize is that the partition
|
||||
is not necessary and actually can become problematic.
|
||||
|
||||
Rather than creating paritions just format the block device. Let's use
|
||||
`/dev/sda` as an example.
|
||||
|
||||
```
|
||||
$ lsblk -d -o NAME,PATH,SERIAL /dev/sda
|
||||
NAME PATH SERIAL
|
||||
sda /dev/sda 01234567
|
||||
|
||||
$ sudo mkfs.ext4 -m0 -L 01234567 /dev/sda
|
||||
mke2fs 1.47.0 (5-Feb-2023)
|
||||
Discarding device blocks: done
|
||||
Creating filesystem with 262144 4k blocks and 65536 inodes
|
||||
Filesystem UUID: ede8bf96-9aff-464e-a4fb-a4ab8a197cd7
|
||||
Superblock backups stored on blocks:
|
||||
32768, 98304, 163840, 229376
|
||||
|
||||
Allocating group tables: done
|
||||
Writing inode tables: done
|
||||
Creating journal (8192 blocks): done
|
||||
Writing superblocks and filesystem accounting information: done
|
||||
```
|
||||
|
||||
You can then use the serial number as the identifier in `fstab`.
|
||||
|
||||
```
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
LABEL=01234567 /mnt/hdd/10TB-01234567 auto nofail 0 2
|
||||
```
|
||||
|
||||
Benefits of doing it this way?
|
||||
|
||||
* One less thing (partitions) to configure and worry about.
|
||||
* Guarantees alignment of blocks
|
||||
* Makes it easier to use the drive with different enclosures. Some
|
||||
SATA to USB adapters use 4K blocks while the drive itself is using
|
||||
512b. If you create partitions with one block size and move the
|
||||
drive to a controller that uses the other the offset on the device
|
||||
where the filesystem starts will be misinterpreted. It is possible
|
||||
to manually fix this but it isn't well documented and avoidable.
|
||||
|
|
|
|||
48
mkdocs/docs/config/branches_mount_timeout.md
Normal file
48
mkdocs/docs/config/branches_mount_timeout.md
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# branches-mount-timeout
|
||||
|
||||
Default: `0`
|
||||
|
||||
mergerfs is compatible with any path, whether it be a mount point or a
|
||||
directory on your [root
|
||||
filesystem.](https://en.wikipedia.org/wiki/Root_directory) It doesn’t
|
||||
require branch paths to be mounted or to match a specific filesystem
|
||||
at startup, and it operates effectively without needing details about
|
||||
the intended filesystem. This flexibility eliminates the need to
|
||||
manage mount ordering, which is particularly advantageous on modern
|
||||
systems where filesystems are mounted asynchronously, resulting in
|
||||
unpredictable mount sequences. While
|
||||
[systemd](https://www.freedesktop.org/software/systemd/man/latest/systemd.mount.html)
|
||||
offers a way to enforce mount dependencies using the
|
||||
[x-systemd.requires=PATH](https://www.freedesktop.org/software/systemd/man/latest/systemd.mount.html#x-systemd.requires=)
|
||||
option in /etc/fstab, applying this to every branch path is both
|
||||
cumbersome and susceptible to errors.
|
||||
|
||||
`branches-mount-timeout` will cause mergerfs to wait for all branches
|
||||
to become "mounted." The logic to determine "mounted" is as follows.
|
||||
|
||||
1. It is mounted if the branch directory has the extended attribute
|
||||
`user.mergerfs.branch`
|
||||
2. It is mounted if the branch directory contains a file named
|
||||
`.mergerfs.branch`
|
||||
3. It is **not** mounted if the branch directory has the extended
|
||||
attribute `user.mergerfs.branch_mounts_here`
|
||||
4. It is **not** mounted if the branch directory contains
|
||||
a file named `.mergerfs.branch_mounts_here`
|
||||
5. It is mounted if the `st_dev` value of the mergerfs mountpoint is
|
||||
different from the branch path.
|
||||
|
||||
**NOTE:** If on a `systemd` based system and using `fstab` it is a
|
||||
good idea to set the mount option
|
||||
[x-systemd.mount-timeout](https://www.freedesktop.org/software/systemd/man/latest/systemd.mount.html#x-systemd.mount-timeout=)
|
||||
to some value longer than `branches-mount-timeout`.
|
||||
|
||||
|
||||
## branches-mount-timeout-fail
|
||||
|
||||
Default: `false`
|
||||
|
||||
When set to `true` mergerfs will fail entirely after
|
||||
`branches-mount-timeout` expires without all branches being
|
||||
mounted. If set to `false` it will simply ignore the mount status of
|
||||
the branches and continue on. The details will be
|
||||
[logged](../error_handling_and_logging.md).
|
||||
|
|
@ -1,28 +1,16 @@
|
|||
# functions, categories and policies
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
|
||||
## Functions and their Category classifications
|
||||
|
||||
|
|
@ -34,43 +22,61 @@ of the file.
|
|||
| N/A | fchmod, fchown, futimens, ftruncate, fallocate, fgetattr, fsync, ioctl (files), read, readdir, release, statfs, write, copy_file_range |
|
||||
|
||||
In cases where something may be searched for (such as a path to clone)
|
||||
**getattr** will usually be used.
|
||||
`getattr` will usually be used.
|
||||
|
||||
|
||||
## Policies
|
||||
|
||||
See below for [available policies and their descriptions](#policy-descriptions).
|
||||
|
||||
A policy is an algorithm designed to select one or more branches for a
|
||||
function to operate on.
|
||||
|
||||
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.
|
||||
Policies do not actually manage the filesystem or layout. They are
|
||||
strictly responsible for deciding which files or branches will be
|
||||
worked on in relation to the function being performed. Once the branch
|
||||
is chosen other parts of the system does what is necessary to
|
||||
accomplish the function. Such as the cloning of directories between
|
||||
branches.
|
||||
|
||||
When using policies which are based on a branch's available space the
|
||||
branch base path provided is used. Not the full path to the file or
|
||||
directory in question. Meaning that mounts within the branch will not
|
||||
be considered in the space calculations.
|
||||
|
||||
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 but could lead to very odd behavior if
|
||||
used for `chmod` if there were more than one copy of the file. Unless
|
||||
users find this flexibility useful it will likely be removed in the
|
||||
future.
|
||||
|
||||
|
||||
## Filtering
|
||||
|
||||
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
|
||||
Most policies 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](minfreespace.md),
|
||||
whether or not a branch is mounted read-only, and the branch mode
|
||||
(RO,NC,RW). These filters are applied across most policies.
|
||||
|
||||
- No **search** function policies filter.
|
||||
- All **action** function policies filter out branches which are
|
||||
mounted **read-only** or tagged as **RO (read-only)**.
|
||||
- All **create** function policies filter out branches which are
|
||||
mounted **read-only**, tagged **RO (read-only)** or **NC (no
|
||||
create)**, or has available space less than `minfreespace`.
|
||||
- No `search` function policies filter.
|
||||
- All `action` function policies filter out branches which are
|
||||
mounted **read-only** or mode is **RO (read-only)**.
|
||||
- All `create` function policies filter out branches which are
|
||||
mounted **read-only**, mode **RO (read-only)** or **NC (no
|
||||
create)**, or has available space less than
|
||||
[minfreespace](minfreespace.md).
|
||||
|
||||
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
|
||||
`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.
|
||||
branch.
|
||||
|
||||
If **create**, **mkdir**, **mknod**, or **symlink** fail with `EROFS`
|
||||
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
|
||||
|
|
@ -82,16 +88,12 @@ 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`.
|
||||
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
|
||||
|
|
@ -141,5 +143,5 @@ policies is not appropriate.
|
|||
| Category | Policy |
|
||||
| -------- | ------ |
|
||||
| action | epall |
|
||||
| create | epmfs |
|
||||
| create | pfrd |
|
||||
| search | ff |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue