Что такое overlay linux

Overlay filesystem

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.

Overlayfs has been in the Linux kernel since 3.18.

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 .

# 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.

Читайте также:  Jetbrains toolbox linux установка

The above example will have the order:

/upper /lower1 /lower2 /lower3

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

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 work are not required:

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

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

See also

Источник

Overlay filesystem (Русский)

Состояние перевода: На этой странице представлен перевод статьи Overlay filesystem. Дата последней синхронизации: 27 мая 2020. Вы можете помочь синхронизировать перевод, если в английской версии произошли изменения.

Overlayfs позволяет накладывать одно дерево каталогов (обычно доступное в режиме «чтение-запись») на другое, но с доступом только для чтения. Все изменения переходят на верхний слой с возможностью записи. Данная схема чаще всего используется с Live CD, но существует и множество других применений. Данная реализация отличается от других каскадно-объединённых файловых систем тем, что после открытия файла все операции направляются непосредственно в базовую, «нижнюю» или «верхнюю» файловую систему, что упрощает реализацию и не ухудшает производительность в данных случаях.

Overlayfs доступен в ядре Linux с версии 3.18.

Читайте также:  Hp print for linux

Установка

Overlayfs включён в ядре по умолчанию, а модуль overlay автоматически подгружается после ввода команды монтирования.

Использование

Используйте следующие аргументы mount для монтирования overlay:

# mount -t overlay overlay -o lowerdir=/lower,upperdir=/upper,workdir=/work /merged 

Примечание: Рабочий каталог ( workdir ) должен быть пустым и находиться в той же точке монтирования файловой системы, что и верхний каталог.

Нижняя директория может быть списком каталогов, разделённых : , все изменения в каталоге merged по-прежнему будут отражаться в upper .

# mount -t overlay overlay -o lowerdir=/lower1:/lower2:/lower3,upperdir=/upper,workdir=/work /merged 

Примечание: Порядок монтирования папок lowerdir : слева-направо/сверху-вниз. То есть крайняя левая папка из списка будет смонтирована как самый верхний слой из lowerdir , а крайняя правая папка, соответственно, как самый нижний слой.

Таким образом порядок слоёв из вышеупомянутого примера будет следующим:

/upper /lower1 /lower2 /lower3

Используйте следующий формат, чтобы добавить запись overlayfs в /etc/fstab :

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

Параметры монтирования noauto и x-systemd.automount необходимы для предотвращения зависания systemd при загрузке, например, из-за ошибки монтирования overlay. Также overlay теперь будет монтироваться при первом обращении, а запросы будут буферизироваться до готовности самого overlay. Для получения дополнительной информации смотрите раздел Fstab (Русский)#Автоматическое монтирование с systemd.

Overlay только для чтения

Иногда необходимо создать представление из комбинации двух или более каталогов, доступное только для чтения. В этом случае его можно создать более простым способом, так как каталоги upper и work не обязательны:

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

Когда upperdir не указан, overlay автоматически монтируется только для чтения.

Смотрите также

Источник

Оцените статью
Adblock
detector