Port EST driver from NetBSD, as it has better support for newer CPUs
[dragonfly.git] / etc / rc.d / diskless
blobeea065df1b53b13b51c0d16c15fed1fd125fd071
1 #!/bin/sh
3 # Copyright (c) 1999 Matt Dillon
4 # All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
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
25 # SUCH DAMAGE.
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.5 2005/11/19 21:47:32 swildner Exp $
31 # PROVIDE: diskless
32 # REQUIRE: initdiskless rcconf mountcritlocal
33 # BEFORE: addswap random
35 if [ -r /etc/rc.subr ]; then
36 . /etc/rc.subr
37 dummy_rc_command "$1"
40 dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
41 [ ${dlv:=0} -eq 0 ] && exit 0
43 name="diskless2"
45 # Provide a function for normalizing the mounting of memory
46 # filesystems. This should allow the rest of the code here to remain
47 # as close as possible between 5-current and 4-stable.
48 # $1 = size
49 # $2 = mount point
50 # $3 = (optional) bytes-per-inode
51 mount_md() {
52 if [ -n "$3" ]; then
53 bpi="-i $3"
55 /sbin/mdmfs $bpi -s $1 -M md $2
58 # If there is a global system configuration file, suck it in.
60 if [ -r /etc/rc.subr ]; then
61 . /etc/rc.subr
62 load_rc_config $name
63 elif [ -r /etc/defaults/rc.conf ]; then
64 . /etc/defaults/rc.conf
65 source_rc_confs
66 elif [ -r /etc/rc.conf ]; then
67 . /etc/rc.conf
70 # If we do not have a writable /var, create a memory
71 # filesystem for /var. We don't have /usr yet so
72 # use mkdir instead of touch to test. We want mount
73 # to record its mounts so we have to make sure /var/db
74 # exists before doing the mount -a.
76 if (/bin/mkdir /var/.diskless 2> /dev/null); then
77 rmdir /var/.diskless
78 else
79 echo "+++ mount_md of /var"
80 mount_md ${varsize:=32m} /var
83 if [ ! -d /var/db ]; then
84 mkdir /var/db
87 # Now we need the rest of our mounts, particularly /usr
89 mount -a # chown and chgrp are in /usr
91 # Populate /var
93 echo "+++ populate /var using /etc/mtree/BSD.var.dist"
94 /usr/sbin/mtree -deU -f /etc/mtree/BSD.var.dist -p /var > /dev/null
95 case ${sendmail_enable} in
96 [Nn][Oo][Nn][Ee])
99 /usr/sbin/mtree -deU -f /etc/mtree/BSD.sendmail.dist -p / > /dev/null
101 esac
103 echo "+++ create log files based on the contents of /etc/newsyslog.conf"
104 LOGFILES=`/usr/bin/awk '$1 != "#" { printf "%s ", $1 } ' /etc/newsyslog.conf`
105 if [ -n "$LOGFILES" ]; then
106 /usr/bin/touch $LOGFILES
109 echo "+++ create lastlog"
110 /usr/bin/touch /var/log/lastlog
112 # Make sure our aliases database is uptodate, the aliases may have
113 # been overriden in /conf.
115 /usr/bin/newaliases
117 # XXX make sure to create one dir for each printer as requested by lpd
119 # If we do not have a writable /tmp, create a memory
120 # filesystem for /tmp. If /tmp is a symlink (e.g. to /var/tmp,
121 # then it should already be writable).
123 if (/bin/mkdir /tmp/.diskless 2> /dev/null); then
124 rmdir /tmp/.diskless
125 else
126 if [ -h /tmp ]; then
127 echo "*** /tmp is a symlink to a non-writable area!"
128 echo "dropping into shell, ^D to continue anyway."
129 /bin/sh
130 else
131 mount_md ${tmpsize:=20480} /tmp
132 chmod 01777 /tmp
136 if sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
137 # we have DEVFS, no worries...
138 true
139 elif (/bin/mkdir /dev/.diskless 2> /dev/null); then
140 # if /dev is writable assume it has already been populated
141 # via rc.diskless1
143 rmdir /dev/.diskless
144 else
145 (cd /; find -x dev | cpio -o -H newc) > /tmp/dev.tmp
146 mount_md 4096 /dev 512
147 (cd /; cpio -i -H newc -d < /tmp/dev.tmp)
148 rm -f /tmp/dev.tmp
151 # generate our hostname
153 if [ -z "`hostname -s`" ]; then
154 hostname=`/bin/kenv dhcp.host-name`
155 hostname $hostname
156 echo "Hostname is $hostname"
159 # if the info is available via dhcp/kenv
160 # build the resolv.conf
162 if [ ! -e /etc/resolv.conf ]; then
163 echo domain `/bin/kenv dhcp.domain-name` > /etc/resolv.conf
165 set `/bin/kenv dhcp.domain-name-servers`
166 for ns in `IFS=','; echo $*`; do
167 echo nameserver $ns >> /etc/resolv.conf;
168 done