tmp revision 76409
1238438Sdteske#!/bin/sh
2238438Sdteske#
3238438Sdteske# Copyright (c) 1999  Matt Dillon
4238438Sdteske# All rights reserved.
5238438Sdteske#
6238438Sdteske# Redistribution and use in source and binary forms, with or without
7238438Sdteske# modification, are permitted provided that the following conditions
8238438Sdteske# are met:
9238438Sdteske# 1. Redistributions of source code must retain the above copyright
10238438Sdteske#    notice, this list of conditions and the following disclaimer.
11238438Sdteske# 2. Redistributions in binary form must reproduce the above copyright
12238438Sdteske#    notice, this list of conditions and the following disclaimer in the
13238438Sdteske#    documentation and/or other materials provided with the distribution.
14238438Sdteske#
15238438Sdteske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16238438Sdteske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17238438Sdteske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18238438Sdteske# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19238438Sdteske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20238438Sdteske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21238438Sdteske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22238438Sdteske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23238438Sdteske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24238438Sdteske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25238438Sdteske# $FreeBSD: head/etc/rc.d/tmp 76409 2001-05-09 15:13:51Z bsd $
26238438Sdteske#
27238438Sdteske# $FreeBSD: head/etc/rc.d/tmp 76409 2001-05-09 15:13:51Z bsd $
28238438Sdteske#
29238438Sdteske
30238438Sdteske# PROVIDE: diskless
31269027Sdteske# 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/mdconfig -a -t malloc -s $1 -u $3
53	/sbin/disklabel -r -w md$3 auto
54	/sbin/newfs $bpi /dev/md$3c
55	/sbin/mount /dev/md$3c $2
56}
57
58echo "+++ mfs_mount of /var"
59mount_md ${varsize:=65536} /var 1
60if [ -r /etc/rc.subr ]; then
61        . /etc/rc.subr
62        load_rc_config $name
63echo "+++ mount_md of /var"
64mount_md ${varsize:=32m} /var 1
65
66echo "+++ populate /var using /etc/mtree/BSD.var.dist"
67/usr/sbin/mtree -deU -f /etc/mtree/BSD.var.dist -p /var
68case ${sendmail_enable} in
69	/usr/bin/touch $LOGFILES
70fi
71
72# Since we are starting with a very fresh /etc on an MFS:
73if [ -d /conf/default/etc ]; then
74	newaliases
75fi
76
77#
78# /var/tmp, otherwise, use a small memory filesystem for /tmp.
79	mount_md ${tmpsize:=20480} /tmp 2
80# so if /var/tmp == /tmp, then you don't get a vi.recover.
81#
82if [ ! -h /tmp ]; then
83	mount_md ${tmpsize:=64m} /tmp 2
84	chmod 01777 /tmp
85fi
86
87if sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
88	# we have DEVFS, no worries...
89	true
90else
91	# extract a list of device entries, then copy them to a writable fs
92	(cd /; find -x dev | cpio -o -H newc) > /tmp/dev.tmp
93	mount_md 4096 /dev 3 512
94	(cd /; cpio -i -H newc -d < /tmp/dev.tmp)
95fi
96