Thursday, 30 June 2011

Read only root and dhclient

To make my read only root viable I have a separate /var directory and /tmp mapped to /var/tmp

In my quest to get my read only root I encountered a problem with the dhclient trying to write to resolv.conf - unfortunately what the standard dhclient does is create a new /etc/resolv.conf.dhclient-new then uses mv to overwrite the existing resolv.conf.

I'm not a great fan of hacking debian scripts as 2 years down the line an upgrade will nuke said script and then I'm back to square one. My solution was to unlock the root fs for a short time during the dhclient magic.

I already had two existing scripts in /usr/local/sbin called lock and unlock which basically run:

lock:
mount -o remount,ro /
and unlock:
mount -o remount,rw /
Add some symlinks in /etc/dhcp/dhclient-enter-hooks.d/ and  /etc/dhcp/dhclient-exit-hooks.d/ as follows:
ln -s /usr/local/sbin/unlock /etc/dhcp/dhclient-enter-hooks.d/aunlock
ln -s /usr/local/sbin/unlock /etc/dhcp/dhclient-exit-hooks.d/zlock
I guessed that the dhclient script runs the hooks in alphabetical order and it seems to be the case, but I could not find any definitive proof for this.

No comments:

Post a Comment