3 # Copyright (c) 1999 Matt Dillon
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 # $FreeBSD: src/etc/rc.d/diskless,v 1.25 2003/02/15 16:34:14 jhay Exp $
28 # $DragonFly: src/etc/rc.d/diskless,v 1.7 2007/05/13 22:25:41 swildner Exp $
32 # REQUIRE: initdiskless rcconf mountcritlocal
33 # BEFORE: addswap random
35 if [ -r /etc
/rc.subr
]; then
40 dlv
=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
41 [ ${dlv:=0} -eq 0 ] && exit 0
45 # Provide a function for normalizing the mounting of memory filesystems.
49 /sbin
/mount_tmpfs
-s $1 tmpfs
$2
52 # If there is a global system configuration file, suck it in.
54 if [ -r /etc
/rc.subr
]; then
57 elif [ -r /etc
/defaults
/rc.conf
]; then
58 .
/etc
/defaults
/rc.conf
60 elif [ -r /etc
/rc.conf
]; then
64 # Try to mount root r/w. If a workable /etc/fstab is present
65 # this may give us a RW mount.
69 if (echo "" |
dd of
=/var
/.diskless
2> /dev
/null
); then
70 echo "diskless: /var is writable"
72 echo "+++ mount_md of /var"
73 mount_md
${varsize:=16M} /var
76 if [ ! -d /var
/db
]; then
80 # Now we need the rest of our mounts, particularly /usr
82 mount
-a # chown and chgrp are in /usr
86 echo "+++ populate /var using /etc/mtree/BSD.var.dist"
87 /usr
/sbin
/mtree
-deU -f /etc
/mtree
/BSD.var.dist
-p /var
> /dev
/null
88 case ${sendmail_enable} in
92 /usr
/sbin
/mtree
-deU -f /etc
/mtree
/BSD.sendmail.dist
-p / > /dev
/null
96 echo "+++ create log files based on the contents of /etc/newsyslog.conf"
97 LOGFILES
=`/usr/bin/awk '$1 != "#" { printf "%s ", $1 } ' /etc/newsyslog.conf`
98 if [ -n "$LOGFILES" ]; then
99 /usr
/bin
/touch $LOGFILES
102 echo "+++ create lastlog"
103 /usr
/bin
/touch /var
/log
/lastlog
105 # XXX make sure to create one dir for each printer as requested by lpd
107 # If we do not have a writable /tmp, create a memory
108 # filesystem for /tmp. If /tmp is a symlink (e.g. to /var/tmp,
109 # then it should already be writable).
111 if (echo "" |
dd of
=/tmp
/.diskless
2> /dev
/null
); then
112 echo "diskless: /tmp is writable"
115 echo "*** /tmp is a symlink to a non-writable area!"
116 echo "dropping into shell, ^D to continue anyway."
119 mount_md
${tmpsize:=10M} /tmp
124 # generate our hostname
126 if [ -z "`hostname -s`" ]; then
127 hostname
=`/usr/bin/kenv dhcp.host-name`
129 echo "Hostname is $hostname"
132 # if the info is available via dhcp/kenv
133 # build the resolv.conf
135 if [ ! -e /etc
/resolv.conf
]; then
136 echo domain
`/usr/bin/kenv dhcp.domain-name` > /etc
/resolv.conf
138 set `/usr/bin/kenv dhcp.domain-name-servers`
139 for ns
in `IFS=','; echo $*`; do
140 echo nameserver
$ns >> /etc
/resolv.conf
;