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