3

I'm in the process of configuring raspbian jessie to run as read-only. Only /tmp is writable and the system is configured to write DHCP ip information in /tmp.

Everything is working fine except /etc/resolv.conf. It just doesn't get updated during boot.

I have tried using a symbolic link. rm /etc/resolv.conf touch /tmp/resolv.conf ln -s /tmp/resolv.conf /etc/resolv.conf

But because /tmp is emptied on reboot, /tmp/resolve.conf can't be updated because it doesn't exist.

So I tried creating the file during boot.

touch /tmp/resolv.conf in /etc/rc.local

The file gets created, but only after dhclient runs, because there are no DNS entries in it. If I run dhclient after the system has booted it writes the DNS servers to the file successfully.

How can I make resolv.conf work on a read-only file system?

  • 1
    How do you make the system as read-only? By the way, there are other things that might want to write to disk, the logging system being one of them. – schaiba Jan 11 '16 at 14:55
  • I made the system read-only by editing /etc/fstab. I took care of any programs that want to write to the disk. Currently my problem is resolv.conf. – aristosv Jan 11 '16 at 15:01
2

From the dhclient-script man pages,

Hooks

When it starts, the client script first defines a shell function, make_resolv_conf , which is later used to create the /etc/resolv.conf file. To override the default behaviour, redefine this function in the enter hook script.

On after defining the make_resolv_conf function, the client script checks for the presence of an executable /etc/dhcp/dhclient-enter-hooks script, and if present, it invokes the script inline, using the Bourne shell '.' command. The entire environment documented under OPERATION is available to this script, which may modify the environment if needed to change the behaviour of the script. If an error occurs during the execution of the script, it can set the exit_status variable to a nonzero value, and /sbin/dhclient-script will exit with that error code immediately after the client script exits.

So you should be able to edit /etc/dhcp/dhclient-enter-hooks and add entries in there to create /tmp/resolv.conf with the correct permissions if it doesn't exist, removing and re-creating the symlink if necessary.

Checking on Debian, there appears to be a dhclient-enter-hooks.d directory with script pieces in it, so you might be able to just add something there, depending on your distribution / version of dhclient (Raspbian in this case).

1

Check out https://wiki.debian.org/ReadonlyRoot#resolv.conf. It recommends using the resolvconf package. As you've already fiddled with your software, it may require some undoing to get it work properly, but it's a well thought out solution to this problem and more.

-2

This did it

rm /etc/resolv.conf ln -s /tmp/resolv.conf /etc/resolv.conf sed -i 's/\/etc\/resolv.conf/\/tmp\/resolv.conf/g' /sbin/dhclient-script

  • 2
    You are changing files behind the back of the package manager. That's not recommended and can lead to surprises even in read-only systems. – Ferenc Wágner Jan 12 '16 at 9:58
  • 1
    I agree with @FerencWágner - this is specifically what the hooks are there to avoid. – EightBitTony Jan 12 '16 at 10:15
  • Of course I would prefer doing it the proper way. But I don't have that much experience with Linux and I can't re-discover the wheel. Any chance there's a guide somewhere on how to do this? – aristosv Jan 12 '16 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.