Automount overlay for /etc

Hi,

am currently trying to create an overlay for /etc to change the rootfs to read-only in the future.
Using a manual mount command work, adding an entry to fstab work with a manual mount -a.
But it is not mounting automatically during boot up.

fstab entry:

overlay /etc overlay defaults,nofail,lowerdir=/etc,upperdir=/home/root/etc/upper,workdir=/home/root/etc/work 0 0

After trying it with fstab, I found a post in the raspberrypi community where a user tries it with systemd.

[Unit]
Description=/etc overlay mount not really working
Documentation=https://github.com/systemd/systemd/issues/8732 (closed)
Before=local-fs.target
Wants=local-fs.target

[Mount]
What=overlay
Where=/etc
Type=overlay
Options=auto,lowerdir=/etc,upperdir=/home/root/etc/upper,workdir=/home/root/etc/work

[Install]
WantedBy=local-fs-pre.target

This doesnt work either. journalctl shows the following error message:

 mount[242]: mount: /etc: wrong fs type, bad option, bad superblock on overlay, missing codepage or helper program, or ot
her error.

Does anybody have a solution for this problem?
If it is possibly without creating a service or script that calls “mount -a”.

Hi @gandi ,

Thanks for using the Toradex Community.

I found this forum entry on the ubuntu forum.

https://askubuntu.com/questions/839355/howto-mount-drive-as-read-only-with-fstab

I tried it on my end by editing the file with “vi /etc/fstab” and adding “ro” to the 4th column of the boot partition.

You can give this a try and let me know if it had the desired effect.

Best Regards
Kevin

Hi @kevin.tx

thank you for your response. But mounting the rootfs as read-only is not the problem.

After mounting the root partition as read-only, I want to overlay the /etc directory with
a folder on a separate partition. And this does not work at start-up.

BR Martin

Hi,

i found a solution thanks to this thread filesystem - How do I use OverlayFS? - Ask Ubuntu
You have to add a requires option for the overlay to wait until the desired upper
directory is ready to mount.

The additional entries in the fstab file looks like this:

/dev/disk/by-label/Settings   /settings   ext4   defaults   0    2
/dev/disk/by-label/Home       /home       ext4   defaults   0    2
overlay /etc   overlay defaults,x-systemd.requires=/settings,lowerdir=/etc,upperdir=/settings/etc/upper,workdir=/settings/etc/working 0 0

Hi @gandi ,

thanks for the update.

Glad to hear that it works now.

Best Regards
Kevin