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: 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 $ 29# 30 31# PROVIDE: diskless 32# REQUIRE: initdiskless rcconf mountcritlocal 33# BEFORE: addswap random 34 35if [ -r /etc/rc.subr ]; then 36 . /etc/rc.subr 37 dummy_rc_command "$1" 38fi 39 40dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` 41[ ${dlv:=0} -eq 0 ] && exit 0 42 43name="diskless" 44 45# Provide a function for normalizing the mounting of memory filesystems. 46# $1 = size 47# $2 = mount point 48mount_md() { 49 /sbin/mount_tmpfs -s $1 tmpfs $2 50} 51 52# If there is a global system configuration file, suck it in. 53# 54if [ -r /etc/rc.subr ]; then 55 . /etc/rc.subr 56 load_rc_config $name 57elif [ -r /etc/defaults/rc.conf ]; then 58 . /etc/defaults/rc.conf 59 source_rc_confs 60elif [ -r /etc/rc.conf ]; then 61 . /etc/rc.conf 62fi 63 64# If we do not have a writable /var, create a memory 65# filesystem for /var. We don't have /usr yet so 66# use mkdir instead of touch to test. We want mount 67# to record its mounts so we have to make sure /var/db 68# exists before doing the mount -a. 69# 70if (/bin/mkdir /var/.diskless 2> /dev/null); then 71 rmdir /var/.diskless 72else 73 echo "+++ mount_md of /var" 74 mount_md ${varsize:=16M} /var 75fi 76 77if [ ! -d /var/db ]; then 78 mkdir /var/db 79fi 80 81# Now we need the rest of our mounts, particularly /usr 82# 83mount -a # chown and chgrp are in /usr 84 85# Populate /var 86# 87echo "+++ populate /var using /etc/mtree/BSD.var.dist" 88/usr/sbin/mtree -deU -f /etc/mtree/BSD.var.dist -p /var > /dev/null 89case ${sendmail_enable} in 90[Nn][Oo][Nn][Ee]) 91 ;; 92*) 93 /usr/sbin/mtree -deU -f /etc/mtree/BSD.sendmail.dist -p / > /dev/null 94 ;; 95esac 96 97echo "+++ create log files based on the contents of /etc/newsyslog.conf" 98LOGFILES=`/usr/bin/awk '$1 != "#" { printf "%s ", $1 } ' /etc/newsyslog.conf` 99if [ -n "$LOGFILES" ]; then 100 /usr/bin/touch $LOGFILES 101fi 102 103echo "+++ create lastlog" 104/usr/bin/touch /var/log/lastlog 105 106# XXX make sure to create one dir for each printer as requested by lpd 107# 108# If we do not have a writable /tmp, create a memory 109# filesystem for /tmp. If /tmp is a symlink (e.g. to /var/tmp, 110# then it should already be writable). 111# 112if (/bin/mkdir /tmp/.diskless 2> /dev/null); then 113 rmdir /tmp/.diskless 114else 115 if [ -h /tmp ]; then 116 echo "*** /tmp is a symlink to a non-writable area!" 117 echo "dropping into shell, ^D to continue anyway." 118 /bin/sh 119 else 120 mount_md ${tmpsize:=10M} /tmp 121 chmod 01777 /tmp 122 fi 123fi 124 125# generate our hostname 126# 127if [ -z "`hostname -s`" ]; then 128 hostname=`/usr/bin/kenv dhcp.host-name` 129 hostname $hostname 130 echo "Hostname is $hostname" 131fi 132 133# if the info is available via dhcp/kenv 134# build the resolv.conf 135# 136if [ ! -e /etc/resolv.conf ]; then 137 echo domain `/usr/bin/kenv dhcp.domain-name` > /etc/resolv.conf 138 139 set `/usr/bin/kenv dhcp.domain-name-servers` 140 for ns in `IFS=','; echo $*`; do 141 echo nameserver $ns >> /etc/resolv.conf; 142 done 143fi 144