2 # /etc/rc.diskless - general BOOTP startup
4 # BOOTP has mounted / for us. Assume a read-only mount. We must then
5 # - figure out where the NFS mount is coming from
7 # - figure out our IP by querying the interface
8 # - setup the configuration script directory
9 # - setup the configuration function
11 # SEE SAMPLE FILES IN /usr/share/examples/diskless. If you have nothing
14 # ln -s /usr/share/examples/diskless /conf
16 # but at least read the README.
20 # Routine to check for error
22 # checks error code and drops into shell on failure.
23 # if shell exits, terminates script as well as /etc/rc.
27 echo "$2 failed: dropping into /bin/sh"
37 # Figure out where the root mount is coming from, synthesize a mount
38 # for /usr and mount it. Also mount /var
40 # e.g. nfs_root might wind up as "A.B.C.D:/"
44 mount_nfs -o ro ${nfs_root}/usr /usr
46 chkerr $? "mount of /usr"
48 # Figure out our interface and IP.
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; }'`
54 echo "Interface $bootp_ifc IP-Address $bootp_ipa"
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.
60 # retarget the kernel ( put a softlink in your conf directory to point to
61 # the correct kernel ).
63 conf_dir=/conf/$bootp_ipa
64 sysctl -w kern.bootfile=$conf_dir/kernel
66 if [ ! -f $conf_dir/rc.conf.local ]; then
67 chkerr 1 "access to $conf_dir"
70 # Tell /etc/rc to skip normal disk configuration and replace
74 diskless_mount_func=diskless_mount_system
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.
84 var_spool_sectors=65536
86 # Default mounting pass procedure
88 # We have to create the filesystems that are expected
91 diskless_mount_system() {
92 sysctl -w net.inet.ip.portrange.first=4000
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.
100 if [ "X$nfs_var_mount" != "XNO" ]; then
101 mount_nfs -o ro ${nfs_root}/var /var
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
112 # /tmp should be a softlink to /var/tmp on most systems. If it isn't,
115 if [ ! -h /tmp -a ! -h /var/tmp ]; then
116 mount_null /var/tmp /tmp
119 # Create a skeleton spool
121 mkdir /var/spool/mqueue
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
128 # /proc may be necessary
130 mount_procfs proc /proc
132 # We need a R+W /dev ! Use cpio to copy /dev from the
133 # server to an MFS mount.
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 )