5

I have looked at How do I use OverlayFS? but it doesn't answer my question.

I need to install some third party applications and they require /opt to be writable but the device I am running on has /opt on a readable rootfs. Essentially, I have a directory /opt on a read-only filesystem (lower) and let's say I have a read-write directory /mnt/optw (writable). I would like to merge /opt & /mnt/optw and mount it to /opt.

Is this possible at all?

Raffa
  • 32,237

2 Answers2

2

This can also be achieved through kernel in-built overlayfs module:

# mount -t overlay -o lowerdir=/opt,upperdir=/mnt/optw,workdir=/tmp/opt-overlay overlay /opt

That can be checked to be properly mounted as:

$ mount | tail -1
overlay on /opt type overlay (rw,relatime,lowerdir=/opt,upperdir=/mnt/optw,workdir=/tmp/opt-overlay)
Animesh Sahu
  • 123
  • 6
0

You could bind /mnt/optw to /opt like so:

sudo mount --bind /mnt/optw/ /opt/

This way /opt will be a reflection of /mnt/optw contents and permissions.


To access the contents of the two directories under /opt, mount with aufs like so:

sudo mount -t aufs -o br=/opt/:/mnt/optw/ none /opt/

This way, the two directories are merged and you'll be able to access their contents under /opt/.

Notice:

If you do not have aufs support available on your system, you can add support by installing aufs-tools like so:

sudo apt install aufs-tools

For further reading man aufs.


Edit:

Regarding the OP's comment, The same can be achieved through kernel in-built overlayfs module:

sudo mount -t overlay -o lowerdir=/opt,upperdir=/mnt/optw,workdir=/tmp/optoverlay overlay /opt
Animesh Sahu
  • 123
  • 6
Raffa
  • 32,237
  • But the contents of original /opt are not visible as this straightforward mount. I would like the contents of /opt and /mnt/optw both be visible, ie, merged. I thought we might need something like overlayfs – zenDev120 Mar 29 '20 at 13:39
  • @zenDev120 OK. I will update the answer for that. One moment please – Raffa Mar 29 '20 at 17:06
  • Thanks for the updated comment and that's precisely what I need but my rootfs doesn't have support for aufs but only overlayfs. Do you know if it is possible to achieve similar result with overlayfs? – zenDev120 Mar 30 '20 at 12:34
  • @zenDev120 I updated the answer and added instructions for installing aufs. Best of luck – Raffa Mar 30 '20 at 14:41