Linux Initramfs – Is Making /etc Directory Read-Only a Bad Idea

embeddedetcinitramfsreadonly

I have an embedded system setup built using buildroot and using initramfs. It runs on compact flash device where I have created separate ext3 partitions to mount /etc/ and /var directories as well as custom directory to store data. I am not entirely certain if this is a good idea or not, but I need access to sytem log output and also need to be able to modify files in /etc as they require a static IP address to be configured here. Once the /etc/network/interfaces file has been edited to set the IP, I have no further need to manually edit anything in /etc so I was wondering if making this mount as read only when the devices are out in the field is a good idea or whether it is possible that other applications on my system need to write to any files in /etc ? I run a fairly minimal system, really just dropbear and busybox are running (as well as my custom controller application that controls the devices). I have looked around on various forums and sites and this idea does not seem too controversial, but my knowledge is fairly limited. I realise I could just try mounting it as read only, but it seems possible that things could break silently so is it a bad idea??

Best Answer

A read-only /etc is increasingly common on embedded devices. A rarely-changing /etc is also increasingly common on desktop and server installations, with files like /etc/mtab and /etc/resolv.conf located on another filesystem and symbolically linked in /etc (so that files in /etc need to be modified when installing software or when the computer's configuration changes, but not when mounting a USB drive or connecting in a laptop to a different network).

The emerging standard is to have a tmpfs filesystem mounted on /run and symbolic links in /etc like

/etc/mtab -> /run/mtab
/etc/resolv.conf -> /etc/resolvconf/run/resolv.conf

Existing or embedded systems may have the tmpfs mounted on a different location such as /dev/shm or /lib/init/rw or /var/run.

The problem with making /etc read-only is that this locks the set of files that you'll ever be able to modify.

A different approach that avoids this problem is to make the root filesystem an initramfs. This is an archive that's stored next to the kernel image and loaded by the bootloader. It is unpacked into RAM and becomes the root of the root of the filesystem. If you're going to let the initramfs stick around, it shouldn't be too big (because it's using up precious RAM), but a BusyBox binary plus some configuration files may be an acceptable use of RAM.

Another approach is to have a read-only root filesystem plus a union mount of a read-write filesystem.

Related Question