tmp revision 103799
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:
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.
14#
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.
26#
27# $FreeBSD: head/etc/rc.d/tmp 103799 2002-09-22 09:48:02Z phk $
28#
29
30# PROVIDE: diskless
31# REQUIRE: initdiskless mountcritlocal
32# BEFORE: addswap random
33# KEYWORD: FreeBSD
34
35dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
36[ ${dlv:=0} -eq 0 ] && exit 0
37
38name="diskless2"
39
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 = md unit number (ignored in pre 5.0 systems)
46#   $4 = (optional) bytes-per-inode
47mount_md()
48{
49	if [ -n "$4" ]; then
50		bpi="-i $4"
51	fi
52	/sbin/mdmfs $bpi -s $1 -M md$3 $2
53}
54
55# If there is a global system configuration file, suck it in.
56#
57if [ -r /etc/rc.subr ]; then
58        . /etc/rc.subr
59        load_rc_config $name
60elif [ -r /etc/defaults/rc.conf ]; then
61	. /etc/defaults/rc.conf
62	source_rc_confs
63elif [ -r /etc/rc.conf ]; then
64	. /etc/rc.conf
65fi
66
67echo "+++ mount_md of /var"
68mount_md ${varsize:=32m} /var 1
69
70echo "+++ populate /var using /etc/mtree/BSD.var.dist"
71/usr/sbin/mtree -deU -f /etc/mtree/BSD.var.dist -p /var
72case ${sendmail_enable} in
73[Nn][Oo][Nn][Ee])
74	;;
75*)
76	/usr/sbin/mtree -deU -f /etc/mtree/BSD.sendmail.dist -p /
77	;;
78esac
79
80echo "+++ create log files based on the contents of /etc/newsyslog.conf"
81LOGFILES=`/usr/bin/awk '$1 != "#" { printf "%s ", $1 } ' /etc/newsyslog.conf`
82if [ -n "$LOGFILES" ]; then
83	/usr/bin/touch $LOGFILES
84fi
85
86echo "+++ create lastlog"
87/usr/bin/touch /var/log/lastlog
88
89mount -a       # chown and chgrp are in /usr
90
91# Since we are starting with a very fresh /etc on an MFS:
92if [ -d /conf/default/etc ]; then
93	newaliases
94fi
95
96#
97# XXX make sure to create one dir for each printer as requested by lpd
98#
99
100# If /tmp is a symlink, assume it points to somewhere writable, like
101# /var/tmp, otherwise, use a small memory filesystem for /tmp.
102#
103# XXX: mtree runs too early to create any directories needed in /tmp,
104# so if /var/tmp == /tmp, then you don't get a vi.recover.
105#
106if [ ! -h /tmp ]; then
107	mount_md ${tmpsize:=64m} /tmp 2
108	chmod 01777 /tmp
109fi
110
111if sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
112	# we have DEVFS, no worries...
113	true
114else
115	# extract a list of device entries, then copy them to a writable fs
116	(cd /; find -x dev | cpio -o -H newc) > /tmp/dev.tmp
117	mount_md 4096 /dev 3 512
118	(cd /; cpio -i -H newc -d < /tmp/dev.tmp)
119fi
120