]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.diskless1
This commit was generated by cvs2svn to compensate for changes in r76238,
[FreeBSD/FreeBSD.git] / etc / rc.diskless1
1 # Copyright (c) 1999  Matt Dillion
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7 # 1. Redistributions of source code must retain the above copyright
8 #    notice, this list of conditions and the following disclaimer.
9 # 2. Redistributions in binary form must reproduce the above copyright
10 #    notice, this list of conditions and the following disclaimer in the
11 #    documentation and/or other materials provided with the distribution.
12 #
13 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 # SUCH DAMAGE.
24 #
25 # $FreeBSD$
26 #
27
28 #
29 # /etc/rc.diskless1 - general BOOTP startup
30 #
31 # BOOTP has mounted / for us.  Assume a read-only mount.  We must then
32 # - figure out our IP by querying the interface
33 # - copy /etc temporarily out of the way to /tmp/etc
34 # - mount /etc as an MFS
35 # - repopulate /etc with the saved off copy
36 # - override files in /etc with files from /conf/*/etc where
37 #   '*' is default, netmask of client, ip-address of client
38 #
39 # WARNING: i thing you should not change /etc/rc or strange things could
40 # happen.
41 #
42 # The operator is in charge of setting /conf/*/etc/* things as appropriate.
43 # Typically rc.conf and fstab need to be changed, but possibly
44 # also other files such as inetd.conf etc.
45
46 # chkerr:
47 #
48 # Routine to check for error
49 #
50 #       checks error code and drops into shell on failure.
51 #       if shell exits, terminates script as well as /etc/rc.
52 #
53 chkerr() {
54         case $1 in
55         0)
56                 ;;
57         *)
58                 echo "$2 failed: dropping into /bin/sh"
59                 /bin/sh
60                 # RESUME
61                 ;;
62         esac
63 }
64
65 mount_md() {
66         /sbin/mdconfig -a -t malloc -s $1 -u $3
67         /sbin/disklabel -r -w md$3 auto
68         /sbin/newfs /dev/md$3c
69         /sbin/mount /dev/md$3c $2
70 }
71
72 # DEBUGGING
73 #
74 # set -v
75
76 # Figure out our interface and IP.
77 #
78 bootp_ifc=""
79 bootp_ipa=""
80 bootp_ipbca=""
81 iflist=`ifconfig -l`
82 for i in ${iflist} ; do
83     set `ifconfig ${i}`
84     while [ $# -ge 1 ] ; do
85         if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then
86             bootp_ifc=${i} ; bootp_ipa=${2} ; shift
87         fi
88         if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then
89             bootp_ipbca=$2; shift
90         fi
91         shift
92     done
93     if [ "${bootp_ifc}" != "" ] ; then
94         break
95     fi
96 done
97 echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"
98
99
100 # Create an MFS /tmp to temporarily hold files from /etc until we
101 # can bootstrap /etc as an MFS.
102
103 mount_md 4096 /tmp 0
104 chmod 1777 /tmp
105 chkerr $? "MFS mount on /tmp"
106 /bin/cp -Rp /etc /tmp
107 chkerr $? "cp /etc to /tmp/etc MFS"
108
109 mount_md 4096 /etc 1
110 chkerr $? "MFS mount on /etc"
111 /bin/chmod 755 /etc
112
113 /bin/cp -Rp /tmp/etc/* /etc
114 chkerr $? "cp /tmp/etc to /etc MFS"
115
116 rm -rf /tmp/etc
117 /sbin/umount /tmp
118 /sbin/mdconfig -d -u 0
119
120 # Allow for override files to replace files in /etc.  Use /conf/*/etc
121 # to find the override files.  First choice is default files that
122 # always override, then files that from the directory that matches the
123 # client's broadcast address, finally followed by overrides that match
124 # the client's IP address.
125 #
126 # This way we have some flexibility to handle clusters of machines
127 # on separate subnets.
128 #
129
130 for i in default ${bootp_ipbca} ${bootp_ipa} ; do
131         if [ -d /conf/${i}/etc ]; then
132                 cp -Rp /conf/${i}/etc/* /etc
133         fi
134 done
135
136 # Tell /etc/rc to run the specified script after
137 # it does its mounts but before it does anything
138 # else.
139 #
140 # This script is responsible for setting up the
141 # diskless mount environment.  This can be
142 # overriden by /conf/ME/rc.conf.local if, for
143 # example, you do not want to run the standard
144 # system /etc/rc.diskless2
145
146 diskless_mount="/etc/rc.diskless2"