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