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