Linux – mount overlayFS as Read-Write FS

cfilesystemslinuxopenwrt

I want to mount my RO Filesystem using overlayFS – in order to use two layers FS (Lowerdir and Upperdir).

I tried the following mounting command –

mount -t overlayfs -o lowerdir=/,upperdir=/overlay "overlayfs:/overlay" /mnt && root=/mnt

That mounted /mnt as overlayFS, but set it as RO.

I tried the following in order to mount it as RW (meaning the Upperdir is RW) –

mount -t overlayfs -o rw,lowerdir=/,upperdir=/overlay "overlayfs:/overlay" /mnt && root=/mnt

Still no good.

Some general information –

I would like to mount the R/W FS as UBIFS, my RO FS is SquashFS
I'm working on openWRT
Thanks everyone!

Best Answer

You're missing workdir=:

Directories

Overlaying mainly involves directories. If a given name appears in both upper and lower filesystems and refers to a non-directory in either, then the lower object is hidden - the name refers only to the upper object.

Where both upper and lower objects are directories, a merged directory is formed.

At mount time, the two directories given as mount options lowerdir and upperdir are combined into a merged directory:

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

The workdir needs to be an empty directory on the same filesystem as upperdir.

Then whenever a lookup is requested in such a merged directory, the lookup is performed in each actual directory and the combined result is cached in the dentry belonging to the overlay filesystem. If both actual lookups find directories, both are stored and a merged directory is created, otherwise only one is stored: the upper if it exists, else the lower.

Only the lists of names from directories are merged. Other content such as metadata and extended attributes are reported for the upper directory only. These attributes of the lower directory are hidden.

Multiple lower layers

Multiple lower layers can now be given using the the colon : as a separator character between the directory names. For example:

mount -t overlay overlay -olowerdir=/lower1:/lower2:/lower3 /merged

As the example shows, upperdir= and workdir= may be omitted. In that case the overlay will be read-only.

The specified lower directories will be stacked beginning from the rightmost one and going left. In the above example lower1 will be the top, lower2 the middle and lower3 the bottom layer.

Related Question