rc.initdiskless revision 51231
143803Sdillon# 251231Ssheldonh# $FreeBSD: head/etc/rc.initdiskless 51231 1999-09-13 15:44:20Z sheldonh $ 351231Ssheldonh# 443803Sdillon# /etc/rc.diskless - general BOOTP startup 543803Sdillon# 643803Sdillon# BOOTP has mounted / for us. Assume a read-only mount. We must then 743803Sdillon# - figure out where the NFS mount is coming from 843803Sdillon# - figure out our IP by querying the interface 943803Sdillon# - retarget /conf/ME softlink to proper configuration script directory 1043803Sdillon# 1143803Sdillon# It is expected that /etc/fstab and /etc/rc.conf.local will be 1243803Sdillon# set by the system operator on the server to be softlinks to 1343803Sdillon# /conf/ME/fstab and /conf/ME/rc.conf.local. The system operator may 1443803Sdillon# choose to retarget other files as well. The server itself boots 1551231Ssheldonh# properly with its default /conf/ME softlink pointing to 1651231Ssheldonh# /conf/server.host.name. 1743803Sdillon# 1843803Sdillon# During a diskless boot, we retarget the /conf/ME softlink to point 1943803Sdillon# to /conf/DISKLESS.CLIENT.IP.ADDRESS. Thus, various system config 2043803Sdillon# files that are softlinks through /conf/ME also get retargeted. 2143803Sdillon# 2251231Ssheldonh# SEE SAMPLE FILES IN /usr/share/examples/diskless. 2343803Sdillon 2443803Sdillon# chkerr: 2543803Sdillon# 2643803Sdillon# Routine to check for error 2743803Sdillon# 2843803Sdillon# checks error code and drops into shell on failure. 2943803Sdillon# if shell exits, terminates script as well as /etc/rc. 3051231Ssheldonh# 3143803Sdillonchkerr() { 3251231Ssheldonh case $1 in 3351231Ssheldonh 0) 3451231Ssheldonh ;; 3551231Ssheldonh *) 3643803Sdillon echo "$2 failed: dropping into /bin/sh" 3743803Sdillon /bin/sh 3843803Sdillon # RESUME 3951231Ssheldonh ;; 4051231Ssheldonh esac 4143803Sdillon} 4243803Sdillon 4343803Sdillon# DEBUGGING 4443803Sdillon# 4543803Sdillonset -v 4643803Sdillon 4751231Ssheldonh# Figure out where the root mount is coming from, synthesize a mount 4851231Ssheldonh# for /usr and mount it. 4943803Sdillon# 5051231Ssheldonh# e.g. nfs_root might wind up as "A.B.C.D:/" 5143803Sdillon# 5251231Ssheldonh# NOTE! the /usr mount is only temporary so we can access commands necessary 5351231Ssheldonh# to retarget /conf/ME. The actual /usr mount should be part of the 5451231Ssheldonh# retargeted /etc/fstab. See instructions in /usr/share/examples/diskless. 5543803Sdillon# 5643803Sdillonset `/bin/df /` 5743803Sdillonnfs_root=$8 5843803Sdillonmount_nfs -o ro ${nfs_root}/usr /usr 5943803Sdillon 6043803Sdillonchkerr $? "mount of /usr" 6143803Sdillon 6251231Ssheldonh# Figure out our interface and IP. 6343803Sdillon# 6443803Sdillon 6543803Sdillonbootp_ifc=`route -n get default | fgrep interface | awk '{ print $2; }'` 6650357Ssheldonhbootp_ipa=`ifconfig ${bootp_ifc} | fgrep inet | head -1 | awk '{ print $2; }'` 6743803Sdillon 6850357Ssheldonhecho "Interface ${bootp_ifc} IP-Address ${bootp_ipa}" 6943803Sdillon 7043803Sdillonumount /usr 7143803Sdillon 7243803Sdillon# retarget /conf/ME 7343803Sdillon# 7443803Sdillon# MFS's background process takes a bit to startup. Various config files 7543803Sdillon# on server should be softlinks through /conf/ME. The server's own /conf/ME 7643803Sdillon# points to the server's version of the files. 7743803Sdillon# 7843803Sdillon# We retarget /conf/ME using a -o union mount. This allows 7943803Sdillon# us to 'mkdir' over whatever was there previously. 8043803Sdillon# 8143803Sdillon# WARNING! null mounts cannot handle mmap, and since many programs 8243803Sdillon# use mmap (such as 'cp'), we have to copy. 8351231Ssheldonh# 8443803Sdillonmount_mfs -s 256 -T qp120at -o union dummy /conf 8543803Sdillonchkerr $? "MFS mount on /conf" 8643803Sdillon 8743803Sdillonmkdir /conf/ME 8843803Sdilloncp -Rp /conf/$bootp_ipa/* /conf/ME 8943803Sdillon 9043803Sdillon# retarget the kernel 9143803Sdillon# 9243803Sdillon 9343803Sdillonsysctl -w kern.bootfile=/conf/ME/kernel 9443803Sdillon 9543803Sdillon# Tell /etc/rc to run the specified script after 9643803Sdillon# it does its mounts but before it does anything 9743803Sdillon# else. 9843803Sdillon# 9943803Sdillon# This script is responsible for setting up the 10051231Ssheldonh# diskless mount environment. This can be 10143803Sdillon# overriden by /conf/ME/rc.conf.local if, for 10243803Sdillon# example, you do not want to run the standard 10343803Sdillon# system /etc/rc.diskless2 10443803Sdillon 10543803Sdillondiskless_mount="/etc/rc.diskless2" 106