Networking – Updating /etc/resolv.conf on a Read-Only Filesystem

busyboxfilesystemsnetworking

I currently have a busybox based embedded linux system. The filesystem is a readonly mounted jffs2 filesystem. One problem I've run into is that /etc/resolv.conf can't be updated by DHCP.

Is it possible to use a different file than /etc/resolv.conf, say /tmp/resolv.conf (/tmp is mounted as tmpfs).

Or am I being overly paranoid in mounting JFFS2 as read only? The root filesystem is read only because I don't want to wear out the flash.

Best Answer

You can use a symlink, I just tried this to be sure. Since the stuff in /tmp is impermanent, that means you will have to create the file at boot before dhcpcd runs.

touch /tmp/dhcpcd.resolv.conf
ln -s /tmp/dhcpcd.resolv.conf /etc/resolv.conf

I included the ln bit by way of illustration but note that you don't have to create the symlink every time at boot; just put in your RO system once, and (again) make sure the /tmp file it links to is created before anything tries to access it.

Symlinks share their permissions with the file they link to, and even if the filesystem they are on is RO, as long as the file they link to is not, writing will work.

Related Question