conf/164048: /etc/rc.d/hostid is not symlink aware

Dirk-Willem van Gulik dirkx at
Thu Jan 12 08:20:12 UTC 2012

>Number:         164048
>Category:       conf
>Synopsis:       /etc/rc.d/hostid is not symlink aware
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 12 08:20:11 UTC 2012
>Originator:     Dirk-Willem van Gulik
>Release:        FreeBSD 8 & 9
FreeBSD 8.2-RELEASE-p2 FreeBSD 8.2-RELEASE-p2 #0: Tue Dec 27 15:40:46 CET 2011     root at  amd64

/sbin/dhclient-script, /etc/rc.d/hostid and /etc/rc.d/sshd are the only three scripts that write in /etc. In some embedded environments, heavily-audited/secure, PXE boots, NFS root's and in, say, virtualbox or Xen, it can be very nice to have a fully-read only / and/or /etc.

dhclient-script and /etc/rc.d/sshd are both aware of the fact that the destination may be a symlink. /etc/rc.d/hostid is not (yet).

Below is a suggestion. Note that this is an alternative to setting the hostid_file to some place.

Create a read only /etc; put a symlink for all the writable files:

   ln -s /var/run/resolv.conf /etc
   ln -s /var/run/hostid /etc
   ln -s /var/db/
   ln -s /var/db/ssh_host_dsa_key /etc/ssh
   ln -s /var/db/ssh_host_key /etc/ssh
   ln -s /var/db/ssh_host_rsa_key /etc/ssh
   ln -s /var/db/ /etc/ssh
   ln -s /var/db/ /etc/ssh
   ln -s /var/db/ /etc/ssh
reboot - and observe that all works - but that

   cat /etc/hostid

shows it to be empty . Apply below - reboot and see that /var/run/hostid now contains the hostid - visible also as /etc/hostid.

--- /etc/rc.d/hostid	2011-02-17 03:19:40.000000000 +0100
+++ /tmp/hostid	2012-01-12 09:10:09.000000000 +0100
@@ -90,12 +90,15 @@
-	# If ${hostid_file} already exists, we take UUID from there.
-	if [ -r ${hostid_file} ]; then
+	# If ${hostid_file} already exists, we take UUID from there. We use
+	# a -f rather than a -r check as the histid_file may in fact be
+	# a symbolic link.
+	#
+	if [ -f ${hostid_file} ]; then
 		hostid_set `cat ${hostid_file}`
 		# No hostid file, generate UUID.
-		hostid_generate
+		hostid_reset


More information about the freebsd-bugs mailing list