OverlayFS

最後更新: 2022-02-07

介紹

 

OverlayFS

It was introduced in kernel 3.18

Used to merge two filesystems, one read-only(squashfs) and the other writable.

 * The overlay and overlay2 drivers are supported on xfs backing filesystems, but only with d_type=true enabled.

    Use xfs_info to verify that the ftype option is set to 1. To format an xfs filesystem correctly, use the flag -n ftype=1.

Diagram

access -> upper(rw) -> lower(ro)

 

 


Usage

 

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

Options:

lowerdir

can be read-only

upperdir

upperdir is the directory you want to overlay lowerdir with.

If duplicate filenames exist in lowerdir and upperdir, upperdir's version takes precedence.

Only the lists of names from directories are merged.

Other content such as metadata and extended attributes are reported for the upper directory only.

* Changes to the underlying filesystems while part of a mounted overlay filesystem are not allowed. 

   If the underlying filesystem is changed, the behavior of the overlay is undefined, though it will not result in a crash or deadlock.

workdir

It used to prepare files as they are switched between the layers.

on the same filesystem mount as the upper directory

i.e.

mount

/dev/loop0 on /overlay type f2fs (...)
overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)

write-access

the file is first copied from the lower filesystem to the upper filesystem (copy_up).  

Note that creating a hard-link also requires copy_up

Any open files referring to this inode will access the old data and metadata.

Similarly any file locks obtained before copy_up will not apply to the copied up file.

If a file with multiple hard links is copied up, then this will "break" the link. 

Changes will not be propagated to other names referring to the same inode.

 

 

 

 

Creative Commons license icon Creative Commons license icon