Overlay filesystem

Overlayfs has been in the Linux kernel since 3.18.

From the initial kernel commit:

Overlayfs allows one, usually read-write, directory tree to be overlaid onto another, read-only directory tree. All modifications go to the upper, writable layer. This type of mechanism is most often used for live CDs but there is a wide variety of other uses.
The implementation differs from other "union filesystem" implementations in that after a file is opened all operations go directly to the underlying, lower or upper, filesystems. This simplifies the implementation and allows native performance in these cases.

Installation

Overlayfs is enabled in the default kernel and the overlay module is automatically loaded upon issuing a mount command.

Usage

To mount an overlay use the following mount options:

# mount -t overlay overlay -o lowerdir=/lower,upperdir=/upper,workdir=/work /merged
Note: The working directory (workdir) needs to be an empty directory on the same filesystem as the upper directory.
  • The lower directory can be read-only or could be an overlay itself.
  • The upper directory is normally writable.
  • The workdir is used to prepare files as they are switched between the layers.

The lower directory can actually be a list of directories separated by :, all changes in the merged directory are still reflected in upper.

Example:

# mount -t overlay overlay -o lowerdir=/lower1:/lower2:/lower3,upperdir=/upper,workdir=/work /merged
Note: The order of lower directories is the rightmost is the lowest, thus the upper directory is on top of the first directory in the left-to-right list of lower directories; NOT on top of the last directory in the list, as the order might seem to suggest.

The above example will have the order:

/upper
/lower1 
/lower2
/lower3

To add an overlayfs entry to /etc/fstab use the following format:

/etc/fstab
overlay ''/merged'' overlay noauto,x-systemd.automount,lowerdir=''/lower'',upperdir=''/upper'',workdir=''/work'' 0 0

The noauto and x-systemd.automount mount options are necessary to prevent systemd from hanging on boot because it failed to mount the overlay. The overlay is now mounted whenever it is first accessed and requests are buffered until it is ready. See fstab#Automount with systemd.

Read-only overlay

Sometimes, it is only desired to create a read-only view of the combination of two or more directories. In that case, it can be created in an easier manner, as the directories upper and are not required:

# mount -t overlay overlay -o lowerdir=/lower1:/lower2 /merged

When is not specified, the overlay is automatically mounted as read-only.

gollark: Under clause 6.7i that was invalidated; if that's not enough I WILL rebind language.
gollark: I am invalidating this statement using clause 6.7i.
gollark: ddg! TCP/IP
gollark: Oh bees it has become sentient.
gollark: What?

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.