]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.diskless
This commit was generated by cvs2svn to compensate for changes in r43550,
[FreeBSD/FreeBSD.git] / etc / rc.diskless
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 #       - mount /usr via nfs
7 #       - figure out our IP by querying the interface
8 #       - setup the configuration script directory
9 #       - setup the configuration function
10 #
11 # SEE SAMPLE FILES IN /usr/share/examples/diskless.  If you have nothing 
12 # better to do, try:
13 #
14 #       ln -s /usr/share/examples/diskless /conf
15 #
16 # but at least read the README.
17
18 # chkerr:
19 #
20 # Routine to check for error
21 #
22 #       checks error code and drops into shell on failure.
23 #       if shell exits, terminates script as well as /etc/rc.
24
25 chkerr() {
26         if [ $1 != 0 ]; then
27                 echo "$2 failed: dropping into /bin/sh"
28                 /bin/sh
29                 # RESUME
30         fi
31 }
32
33 # DEBUGGING
34 #
35 set -v
36
37 #  Figure out where the root mount is coming from, synthesize a mount
38 #  for /usr and mount it.  Also mount /var
39 #
40 #  e.g. nfs_root might wind up as "A.B.C.D:/"
41 #
42 set `/bin/df /`
43 nfs_root=$8
44 mount_nfs -o ro ${nfs_root}/usr /usr
45
46 chkerr $? "mount of /usr"
47
48 #  Figure out our interface and IP.
49 #
50
51 bootp_ifc=`route -n get default | fgrep interface | awk '{ print $2; }'`
52 bootp_ipa=`ifconfig $bootp_ifc | fgrep inet | head -1 | awk '{ print $2; }'`
53
54 echo "Interface $bootp_ifc IP-Address $bootp_ipa"
55
56 # retarget the configuration directory, where rc.conf.local and rc.local
57 # are found.  We set the directory to /conf/$bootp_ipa.  'conf_dir' will
58 # be used by rc.conf and later in /etc/rc.
59 #
60 # retarget the kernel ( put a softlink in your conf directory to point to
61 # the correct kernel ).
62
63 conf_dir=/conf/$bootp_ipa
64 sysctl -w kern.bootfile=$conf_dir/kernel
65
66 if [ ! -f $conf_dir/rc.conf.local ]; then
67         chkerr 1 "access to $conf_dir"
68 fi
69
70 #  Tell /etc/rc to skip normal disk configuration and replace
71 #  it with our own.
72 #
73 skip_diskconf=YES
74 diskless_mount_func=diskless_mount_system
75
76 #  Set defaults for MFS filesystem sizes.  These can get overriden by
77 #  rc.conf when diskless_mount_system is called back.  NOTE!  These
78 #  defaults are generous, but may be too large for your memory/swap
79 #  configuration.  Large is ok as long as you have sufficient NFS swap.
80 #
81 var_run_sectors=2048
82 var_db_sectors=16384
83 var_tmp_sectors=65536
84 var_spool_sectors=65536
85
86 #  Default mounting pass procedure
87 #
88 #       We have to create the filesystems that are expected
89 #       to be writeable.
90
91 diskless_mount_system() {
92         sysctl -w net.inet.ip.portrange.first=4000
93
94         # This is kinda a hack at the moment.  Typically, we do not want to
95         # export /var from the server root due to security considerations,
96         # even read-only.  XXX fixme.  See the tail end of the
97         # /usr/share/examples/diskless/README.TEMPLATING file for the
98         # reasoning and other security considerations.
99         #
100         if [ "X$nfs_var_mount" != "XNO" ]; then
101                 mount_nfs -o ro ${nfs_root}/var /var
102         fi
103         mount_mfs -s $var_run_sectors -T qp120at dummy /var/run
104         mount_mfs -s $var_db_sectors -T qp120at dummy /var/db
105         mount_mfs -s $var_tmp_sectors -T qp120at dummy /var/tmp
106         mount_mfs -s $var_spool_sectors -T qp120at dummy /var/spool
107         chmod 755 /var/run
108         chmod 755 /var/db
109         chmod 755 /var/spool
110         chmod 1777 /var/tmp
111
112         # /tmp should be a softlink to /var/tmp on most systems.  If it isn't, 
113         # use nullfs
114         #
115         if [ ! -h /tmp -a ! -h /var/tmp ]; then
116                 mount_null /var/tmp /tmp
117         fi
118
119         # Create a skeleton spool
120         #
121         mkdir /var/spool/mqueue
122         mkdir /var/spool/lpd
123         mkdir /var/spool/output
124         mkdir /var/spool/output/lpd
125         chown -R root.daemon /var/spool/output
126         chgrp daemon /var/spool/lpd
127
128         # /proc may be necessary
129         #
130         mount_procfs proc /proc
131
132         # We need a R+W /dev !  Use cpio to copy /dev from the 
133         # server to an MFS mount.
134
135         mkdir /tmp/root
136         mount ${nfs_root} /tmp/root
137         mount_mfs -s 4096 -i 512 -T qp120at dummy /dev
138         ( cd /tmp/root ; find -x dev | cpio -o -H newc ) | \
139                 ( cd / ; cpio -i -H newc -d )
140         umount /tmp/root
141 }
142