Hi.

  First of all, I tried to take in modification of 3-stable into
4-current. And I tested with 4-current NFS server and diskless
client.

  merge from latest 3-stable rc.diskless shell scripts:
        etc/rc.diskless1 1.1.2.1(for 3-stable)
        etc/rc.diskless2 1.2.2.1(for 3-stable)

  Some differences between 3-stable and below rc.diskless{1,2} files
        - add $FreeBSD$ tag
        - apply a consistent style to most of the etc scripts
        - don't extract inet6 address for bootp_ipa and bootp_bca.
  
  TODO list:
        - If files in ``/etc'' directory are symbolic linked,
          cp -Rp are failed.  I will check it and fix.
        - I want to free rc.diskless1 from /usr partition.
          (We don't have any hint about path name of /usr directory
          with bootp.
          But we need to use ``/usr/bin/awk and /usr/bin/fgrep,
          /usr/bin/head'' commands to obtain IP address.
          So currently rc.diskless1 has hard-coded with ${nfs_root}/usr).
        - create or copy below files and directories
          (I want to compile ports collection in diskless machine)
                /var/db/port.mkversion
                /var/db/pkg

---
MIHIRA Sanpei Yoshiro
Yokohama, Japan.
# $FreeBSD: src/etc/rc.diskless1,v 1.4 1999/09/13 17:09:07 peter Exp $
#
# /etc/rc.diskless - general BOOTP startup
#
#       BOOTP has mounted / for us.  Assume a read-only mount.  We must then
#       - figure out where the NFS mount is coming from
#       - figure out our IP by querying the interface
#       - retarget /conf/ME softlink to proper configuration script directory
#
#       It is expected that /etc/fstab and /etc/rc.conf.local will be
#       set by the system operator on the server to be softlinks to
#       /conf/ME/fstab and /conf/ME/rc.conf.local.  The system operator may
#       choose to retarget other files as well.  The server itself boots
#       properly with its default /conf/ME softlink pointing to
#       /conf/server.host.name.
#
#       During a diskless boot, we retarget the /conf/ME softlink to point
#       to /conf/DISKLESS.CLIENT.IP.ADDRESS.  Thus, various system config
#       files that are softlinks through /conf/ME also get retargeted.
#
# SEE SAMPLE FILES IN /usr/share/examples/diskless.

# chkerr:
#
# Routine to check for error
#
#       checks error code and drops into shell on failure.
#       if shell exits, terminates script as well as /etc/rc.
#
chkerr() {
        case $1 in
        0)
                ;;
        *)
                echo "$2 failed: dropping into /bin/sh"
                /bin/sh
                # RESUME
                ;;
        esac
}

# DEBUGGING
#
# set -v

# Figure out where the root mount is coming from, synthesize a mount
# for /usr and mount it.
#
# e.g. nfs_root might wind up as "A.B.C.D:/"
#
# NOTE! the /usr mount is only temporary so we can access commands necessary
# to retarget /conf/ME.  The actual /usr mount should be part of the
# retargeted /etc/fstab.  See instructions in /usr/share/examples/diskless.
#
set `/bin/df /`
nfs_root=$8

# XXX we should extract the host part from nfs_root, but we don't have
# any good tool for string parsing yet. The ../ is a dirty hack. We
# can add more than one. But this whole section to determine the boot
# ifc etc. needs some cleanup
mount_nfs -o ro ${nfs_root}/../usr /usr

chkerr $? "mount of /usr"

# Figure out our interface and IP.
#

bootp_ifc=`route -n get default | fgrep interface | awk '{ print $2; }'`
bootp_ipbca=`ifconfig ${bootp_ifc} | fgrep 'inet ' | head -1 | awk '{ print $6; }'`
bootp_ipa=`ifconfig ${bootp_ifc} | fgrep 'inet ' | head -1 | awk '{ print $2; }'`

echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"

umount /usr
 
# Files in /etc are copied to /conf/etc which is writable. Then
# per-machine configs from /conf/ip.address/etc are copied onto this
# directory. First choice is using the client's IP, then the client's
# broadcast address, then a default configuration.
# This way we have some flexibility to handle clusters of machines
# on separate subnets.
#
# WARNING! null mounts cannot handle mmap, and since many programs
# use mmap (such as 'cp'), we have to copy.
#
mount_mfs -s 2048 -T qp120at dummy /conf/etc
cp -Rp /etc/* /conf/etc
chkerr $? "MFS mount on /conf/etc"

if [ -d /conf/${bootp_ipa} ]
then
        cp -Rp /conf/${bootp_ipa}/etc/* /conf/etc
elif [ -d /conf/${bootp_ipbca} ]
then
        cp -Rp /conf/${bootp_ipbca}/etc/* /conf/etc
else
        cp -Rp /conf/default/etc/* /conf/etc
fi


#mkdir /conf/ME
#cp -Rp /conf/${bootp_ipa}/* /conf/ME
#
# Make the new directory available as /etc
#
mount_null /conf/etc /etc

# retarget the kernel
#

#sysctl -w kern.bootfile=/conf/ME/kernel

# Tell /etc/rc to run the specified script after
# it does its mounts but before it does anything
# else.
#
# This script is responsible for setting up the
# diskless mount environment.  This can be
# overriden by /conf/ME/rc.conf.local if, for
# example, you do not want to run the standard
# system /etc/rc.diskless2

diskless_mount="/etc/rc.diskless2"
# $FreeBSD: src/etc/rc.diskless2,v 1.4 1999/09/13 17:09:07 peter Exp $
#
# rc.diskless2
#

# If there is a global system configuration file, suck it in.
#
if [ -r /etc/defaults/rc.conf ]; then
        . /etc/defaults/rc.conf
elif [ -r /etc/rc.conf ]; then
        . /etc/rc.conf
fi

mount_mfs -s ${varsize:=65536} -T qp120at dummy /var
var_dirs="run dev db msgs tmp spool spool/mqueue spool/lpd spool/output \
        spool/output/lpd"
for i in ${var_dirs}
do
    mkdir /var/${i}
done
chmod 755 /var/run
chmod 755 /var/db
chmod 755 /var/spool
chmod 1777 /var/tmp
chown -R root.daemon /var/spool/output
chgrp daemon /var/spool/lpd
#
# XXX make sure to create one dir for each printer as requested by lpd
#

if [ ! -h /tmp -a ! -h /var/tmp ]; then
        mount_null /var/tmp /tmp
fi

# extract a list of device entries, then copy them to a writable partition
(cd /; find -x dev | cpio -o -H newc) > /tmp/dev.tmp
mount_mfs -s 4096 -i 512 -T qp120at dummy /dev
(cd /; cpio -i -H newc -d < /tmp/dev.tmp)

Reply via email to