Bug 137271 - [rc.d] Cannot update /etc/host.conf when root filesystems mount read-only
Summary: [rc.d] Cannot update /etc/host.conf when root filesystems mount read-only
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: conf (show other bugs)
Version: unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-rc mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-30 18:00 UTC by admin
Modified: 2016-05-13 11:24 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description admin 2009-07-30 18:00:04 UTC
if root filesystem mount read-only (nfs, or etc), when machine boot I see
Generating host.conf.
eval: cannot create /etc/host.conf: Read-only file system
eval: cannot create /etc/host.conf: Read-only file system
eval: cannot create /etc/host.conf: Read-only file system
========
in file /etc/rc.d/nsswitch I see:
router# grep -R generate_host_conf *
rc.d/nsswitch:generate_host_conf()
rc.d/nsswitch:          generate_host_conf /etc/nsswitch.conf /etc/host.conf

filename for host.conf is hardcoded =(

Fix: 

may be add variable into /etc/defaults/rc.conf?
How-To-Repeat: boot with / mounted read-only
Comment 1 Efstratios Karatzas <gpf.kira@gmail.com> 2010-01-28 21:18:00 UTC
Hi!

Not sure if this belongs in the PR database, but I have a couple of quick fixes.

fix a)
step 1:

append the following line to your /etc/rc.conf file

sudo echo "nsswitch_host_conf=\"/usr/local/etc/host.conf\" " >> /etc/rc.conf

You can of course change the pathname to whatever you desire, as well
as the variable name as long as it begins with a "nsswitch_" prefix

step 2:
goto /etc/rc.d/nsswitch

As you can see, in lines 93, 94 & and 97 the "/etc/host.conf" is hardcoded
Replace it with the variable defined in /etc/rc.conf

For example, line 93 becomes
if [ ! -f $nsswitch_host_conf -o \

etc. So no more hardcoding!

*But* I really doubt that changing the location of system
configuration files is
a wise thing to do. I would avoid this solution and go with the
solution b instead.

fix b)
Just boot with read/write partition / so you can make /etc/host.conf a
symbolic link
to /usr/local/etc/host.conf or some other path of your picking. Then change to
read only mode for the partition. Makes more sense and seems a lot safer.
Hope this helps.

Cheers

-- 

Efstratios "GPF" Karatzas
Comment 2 Gavin Atkinson freebsd_committer freebsd_triage 2010-04-10 10:14:30 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-rc

Over to -rc maintainers
Comment 3 Ruben Kerkhof 2016-04-30 20:40:42 UTC
This is still and issue. Can't we just get rid of /etc/rc.d/nsswitch? Nothing in the tree seems to need /etc/host.conf.
Comment 4 Jilles Tjoelker freebsd_committer 2016-05-01 20:18:21 UTC
As /etc/host.conf has no longer been used since FreeBSD 5.0, perhaps the time has come to remove /etc/rc.d/nsswitch. A /etc/host.conf file is only needed to run binaries from FreeBSD 4.x or older with a non-default name resolution order (the hard-coded default was generally DNS, then /etc/hosts).

There is no point in changing the pathname since the old binaries refer to /etc/host.conf. A host.conf in a different location would be useless.

In any case, the error is written but ignored. The system boots regardless of it.
Comment 5 Warner Losh freebsd_committer 2016-05-01 20:40:13 UTC
One can do the 'diskless' setup that NanoBSD does (where a /etc mfs is done, populated from /conf/base/etc), or one can have a symlink to some place writable.
Comment 6 Ruben Kerkhof 2016-05-13 11:24:14 UTC
Yes, one can work around it by symlinking /etc/host.conf to somewhere writeable. If you're doing that you might as well remove the nsswitch script if nothing needs host.conf

But this is one more thing to customize. I agree with Jilles, perhaps it's time to remove /etc/rc.d/nsswitch. FreeBSD 4 went EOL 9 years ago. People who want to run FreeBSD binaries with a custom host resolution order can easily create /etc/host.conf themselves. Hopefully they still know how to do that since host.conf isn't documented as far as I can tell.