Deleted Added
full compact
var (126744) var (127345)
1#!/bin/sh
2#
3# Copyright (c) 1999 Matt Dillon
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:

--- 10 unchanged lines hidden (view full) ---

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.
26#
1#!/bin/sh
2#
3# Copyright (c) 1999 Matt Dillon
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:

--- 10 unchanged lines hidden (view full) ---

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.
26#
27# $FreeBSD: head/etc/rc.d/var 126744 2004-03-08 12:25:05Z pjd $
27# $FreeBSD: head/etc/rc.d/var 127345 2004-03-23 23:22:35Z brooks $
28#
29
28#
29
30# PROVIDE: diskless
31# REQUIRE: initdiskless rcconf mountcritlocal
32# BEFORE: addswap random
33# KEYWORD: FreeBSD nojail
30# PROVIDE: var
31# REQUIRE: mountcritlocal
32# KEYWORD: FreeBSD
34
33
35dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
36[ ${dlv:=0} -eq 0 ] && exit 0
34. /etc/rc.subr
37
35
38name="diskless2"
36name="var"
39
37
40# Provide a function for normalizing the mounting of memory
41# filesystems. This should allow the rest of the code here to remain
42# as close as possible between 5-current and 4-stable.
43# $1 = size
44# $2 = mount point
45# $3 = (optional) bytes-per-inode
46mount_md() {
47 if [ -n "$3" ]; then
48 bpi="-i $3"
49 fi
50 /sbin/mdmfs $bpi -s $1 -M md $2
51}
38load_rc_config $name
52
39
53# If there is a global system configuration file, suck it in.
54#
55if [ -r /etc/rc.subr ]; then
56 . /etc/rc.subr
57 load_rc_config $name
58elif [ -r /etc/defaults/rc.conf ]; then
59 . /etc/defaults/rc.conf
60 source_rc_confs
61elif [ -r /etc/rc.conf ]; then
62 . /etc/rc.conf
63fi
40_populate_var()
41{
42 /usr/sbin/mtree -deU -f /etc/mtree/BSD.var.dist -p /var > /dev/null
43 case ${sendmail_enable} in
44 [Nn][Oo][Nn][Ee])
45 ;;
46 *)
47 /usr/sbin/mtree -deU -f /etc/mtree/BSD.sendmail.dist -p / > /dev/null
48 ;;
49 esac
64
50
65# If we do not have a writable /var, create a memory
66# filesystem for /var. We don't have /usr yet so
67# use mkdir instead of touch to test. We want mount
68# to record its mounts so we have to make sure /var/db
69# exists before doing the mount -a.
70#
71if (/bin/mkdir /var/.diskless 2> /dev/null); then
72 rmdir /var/.diskless
73else
74 echo "+++ mount_md of /var"
75 mount_md ${varsize:=32m} /var
76fi
51 /usr/sbin/newsyslog -CC
77
52
78if [ ! -d /var/db ]; then
79 mkdir /var/db
80fi
53 /usr/bin/touch /var/log/lastlog
81
54
82# Now we need the rest of our mounts, particularly /usr
83#
84mount -a # chown and chgrp are in /usr
55 # XXX: should create spool dirs for lpd
56}
85
57
86# Populate /var
58# If we do not have a writable /var, create a memory filesystem for /var
59# unless told otherwise by rc.conf. We don't have /usr yet so use mkdir
60# instead of touch to test. We want mount to record its mounts so we
61# have to make sure /var/db exists before doing the mount -a.
87#
62#
88echo "+++ populate /var using /etc/mtree/BSD.var.dist"
89/usr/sbin/mtree -deU -f /etc/mtree/BSD.var.dist -p /var > /dev/null
90case ${sendmail_enable} in
91[Nn][Oo][Nn][Ee])
63case "${varmfs}" in
64[Yy][Ee][Ss])
65 mount_md ${varsize} /var
92 ;;
66 ;;
93*)
94 /usr/sbin/mtree -deU -f /etc/mtree/BSD.sendmail.dist -p / > /dev/null
67[Nn][Oo])
95 ;;
68 ;;
69*)
70 if (/bin/mkdir /var/.diskless 2> /dev/null); then
71 rmdir /var/.diskless
72 else
73 mount_md ${varsize} /var
74 fi
96esac
97
75esac
76
98echo "+++ create log files based on the contents of /etc/newsyslog.conf"
99LOGFILES=`/usr/bin/awk '$1 != "#" { printf "%s ", $1 } ' /etc/newsyslog.conf`
100if [ -n "$LOGFILES" ]; then
101 /usr/bin/touch $LOGFILES
102fi
103
77
104echo "+++ create lastlog"
105/usr/bin/touch /var/log/lastlog
106
107# Make sure our aliases database is uptodate, the aliases may have
108# been overriden in /conf.
109#
110case ${sendmail_enable} in
111[Nn][Oo][Nn][Ee])
78# If we have an empty looking /var, populate it, but only if we have
79# /usr available. Hopefully, we'll eventually find a workaround, but
80# in realistic diskless setups, we're probably ok.
81case "${populate_var}" in
82[Yy][Ee][Ss])
83 _populate_var
112 ;;
84 ;;
113*)
114 /usr/bin/newaliases
85[Nn][Oo])
115 ;;
86 ;;
116esac
117
118# XXX make sure to create one dir for each printer as requested by lpd
119#
120# If we do not have a writable /tmp, create a memory
121# filesystem for /tmp. If /tmp is a symlink (e.g. to /var/tmp,
122# then it should already be writable).
123#
124if (/bin/mkdir /tmp/.diskless 2> /dev/null); then
125 rmdir /tmp/.diskless
126else
127 if [ -h /tmp ]; then
128 echo "*** /tmp is a symlink to a non-writable area!"
129 echo "dropping into shell, ^D to continue anyway."
130 /bin/sh
87*)
88 if [ -d /var/run -a -d /var/db -a -d /var/empty ] ; then
89 true
90 elif [ ! -x /usr/sbin/mtree -o ! -x /usr/sbin/newsyslog -o \
91 ! -x /usr/bin/touch ] ; then
92 false
131 else
93 else
132 mount_md ${tmpsize:=20480} /tmp
133 chmod 01777 /tmp
94 _populate_var
134 fi
95 fi
135fi
136
137if sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
138 # we have DEVFS, no worries...
139 true
140elif (/bin/mkdir /dev/.diskless 2> /dev/null); then
141 # if /dev is writable assume it has already been populated
142 # via /etc/rc.d/initdiskless
143 #
144 rmdir /dev/.diskless
145else
146 (cd /; find -x dev | cpio -o -H newc) > /tmp/dev.tmp
147 mount_md 4096 /dev 512
148 (cd /; cpio -i -H newc -d < /tmp/dev.tmp)
149 rm -f /tmp/dev.tmp
150fi
151
152# generate our hostname
153#
154if [ -z "`hostname -s`" -a \
155 "x`/bin/kenv dhcp.host-name`" != "x" ]; then
156 hostname=`/bin/kenv dhcp.host-name`
157 hostname $hostname
158 echo "Hostname is $hostname"
159fi
160
161# if the info is available via dhcp/kenv
162# build the resolv.conf
163#
164if [ ! -e /etc/resolv.conf -a \
165 "x`/bin/kenv dhcp.domain-name-servers`" != "x" ]; then
166 echo domain `/bin/kenv dhcp.domain-name` > /etc/resolv.conf
167
168 set `/bin/kenv dhcp.domain-name-servers`
169 for ns in `IFS=','; echo $*`; do
170 echo nameserver $ns >> /etc/resolv.conf;
171 done
172fi
173
96 ;;
97esac