1

I have OpenWRT installed on some of my routers and to add additional storage for settings as well as programs that might be installed on the router and maybe logs, OpenWRT recommends you plug storage into it and use an overlayfs.

I also have a SBC where I just mount an external drive overtop of my home directory on boot to store the home directory externally off of the SD Card that the bootloader and OS are installed on; since the storage on the external drive is more reliable than the SD Card, despite running slower.

What is the difference between these two strategies? They are both basically Single Board computers with Linux, and when the external drive fails to mount, in both cases we're left with a directory full of the content of the original directory, where the drive would have been mounted before.

The only think I can think of that is different, is that the settings directory for OpenWRT (/etc) is being mounted on the external drive, where this is not the case on the SBC.

1 Answer 1

4

and when the external drive fails to mount, in both cases we're left with a directory full of the content of the original directory, where the drive would have been mounted before.

I'd say that's the big difference here.

Regular mounts are fully opaque. That is, once you mount something over a directory, the previous contents of that directory become inaccessible by path – it is exclusively switched over to the new filesystem.1

So in your /etc example, OpenWrt would need to ensure that all of the original contents of /etc are copied to the HDD before actually mounting it on /etc.

Regular mounts are completely fine if the original directory can be just kept empty until the mount happens, e.g. /home is commonly a regular mount. On general Linux systems, regular mounts work for most purposes because services can be easily configured to delay start until after something is mounted. Normally mount points are kept completely empty to reduce confusion when it fails to mount.

Overlayfs, on the other hand, is meant to be used with some pre-existing contents as if it were "transparent". There are still the same issues if it ever fails to mount, but to a lesser extent, because all of the original content doesn't need to be duplicated over to the new storage (upper) – it is still read directly from the original location (lower), while only new writes are directed to the new storage.

So overlayfs is useful for /etc or /usr or even the whole / in OpenWrt because it allows the original read-only /etc to contain some initial contents, and then after mounting the overlay, /etc still has the same contents (plus whatever is overlayed) – and this still works even if the new 'upper' storage is completely empty, i.e. without having to do the dance of "mount HDD to temporary place; check if empty; copy all of /etc there; wait until it is read from slow flash and copied to slow HDD; umount from temporary place; now mount on /etc".

It is less useful for /home since nothing needs /home at that point anyway.


1 (Except, any programs still holding open handles to files in the original directory will continue having that, even after the original directory is over-mounted. So if a program starts writing to /var/log/something and then you mount /var/log from external storage – the program will not automatically be switched over.)

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.