rc.initdiskless revision 51231
1# 2# $FreeBSD: head/etc/rc.initdiskless 51231 1999-09-13 15:44:20Z sheldonh $ 3# 4# /etc/rc.diskless - general BOOTP startup 5# 6# BOOTP has mounted / for us. Assume a read-only mount. We must then 7# - figure out where the NFS mount is coming from 8# - figure out our IP by querying the interface 9# - retarget /conf/ME softlink to proper configuration script directory 10# 11# It is expected that /etc/fstab and /etc/rc.conf.local will be 12# set by the system operator on the server to be softlinks to 13# /conf/ME/fstab and /conf/ME/rc.conf.local. The system operator may 14# choose to retarget other files as well. The server itself boots 15# properly with its default /conf/ME softlink pointing to 16# /conf/server.host.name. 17# 18# During a diskless boot, we retarget the /conf/ME softlink to point 19# to /conf/DISKLESS.CLIENT.IP.ADDRESS. Thus, various system config 20# files that are softlinks through /conf/ME also get retargeted. 21# 22# SEE SAMPLE FILES IN /usr/share/examples/diskless. 23 24# chkerr: 25# 26# Routine to check for error 27# 28# checks error code and drops into shell on failure. 29# if shell exits, terminates script as well as /etc/rc. 30# 31chkerr() { 32 case $1 in 33 0) 34 ;; 35 *) 36 echo "$2 failed: dropping into /bin/sh" 37 /bin/sh 38 # RESUME 39 ;; 40 esac 41} 42 43# DEBUGGING 44# 45set -v 46 47# Figure out where the root mount is coming from, synthesize a mount 48# for /usr and mount it. 49# 50# e.g. nfs_root might wind up as "A.B.C.D:/" 51# 52# NOTE! the /usr mount is only temporary so we can access commands necessary 53# to retarget /conf/ME. The actual /usr mount should be part of the 54# retargeted /etc/fstab. See instructions in /usr/share/examples/diskless. 55# 56set `/bin/df /` 57nfs_root=$8 58mount_nfs -o ro ${nfs_root}/usr /usr 59 60chkerr $? "mount of /usr" 61 62# Figure out our interface and IP. 63# 64 65bootp_ifc=`route -n get default | fgrep interface | awk '{ print $2; }'` 66bootp_ipa=`ifconfig ${bootp_ifc} | fgrep inet | head -1 | awk '{ print $2; }'` 67 68echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa}" 69 70umount /usr 71 72# retarget /conf/ME 73# 74# MFS's background process takes a bit to startup. Various config files 75# on server should be softlinks through /conf/ME. The server's own /conf/ME 76# points to the server's version of the files. 77# 78# We retarget /conf/ME using a -o union mount. This allows 79# us to 'mkdir' over whatever was there previously. 80# 81# WARNING! null mounts cannot handle mmap, and since many programs 82# use mmap (such as 'cp'), we have to copy. 83# 84mount_mfs -s 256 -T qp120at -o union dummy /conf 85chkerr $? "MFS mount on /conf" 86 87mkdir /conf/ME 88cp -Rp /conf/$bootp_ipa/* /conf/ME 89 90# retarget the kernel 91# 92 93sysctl -w kern.bootfile=/conf/ME/kernel 94 95# Tell /etc/rc to run the specified script after 96# it does its mounts but before it does anything 97# else. 98# 99# This script is responsible for setting up the 100# diskless mount environment. This can be 101# overriden by /conf/ME/rc.conf.local if, for 102# example, you do not want to run the standard 103# system /etc/rc.diskless2 104 105diskless_mount="/etc/rc.diskless2" 106