Hi,
i just gave a shot at diskless support in RELENG_4, and I am
attaching some code to help setting things.

The first one (a shell script called clone_root) helps you
create a shared readonly root partition for the diskless clients.

The second piece of code is a set of patches for /etc/rc and
/etc/rc.diskless2, which do the following:

    /etc/rc
        Diskless needs a slightly different sequence of
        mounts. There used to be a variable, early_nfs_mounts,
        which controlled this, but it got nuked in 1.209
        with no corresponding reinsertion in /etc/rc.diskless2.
        This patch fixes this.

    /etc/diskless2
        Mount filesystems in the order needed to make things
        work.
        Also comment out the mount_null of /var/tmp on /tmp,
        and assume that /tmp is symlinked to /var/tmp on the
        root partition. For some reason the mount_null
        causes a panic here and this workaround seems to work
        anyways.

Any takers to test&commit this to -current ? The clone_root
script could go into /usr/share/examples/diskless

        cheers
        luigi

------------- cut here ---- file: clone_root -----------------
#!/bin/sh
#
# (C) 2001 Luigi Rizzo, Gabriele Cecchetti
#       <Standard BSD copyright>
# Revised 2001.04.16
# clone root filesystem for diskless root stuff
#
# usage
#       clone_root all          to do a full copy (e.g. bin, sbin...)
#       clone_root update       to recreate /var (including devices)
#       clone_root              to copy /conf and password-related files
#
# This script assumes that you use a shared readonly root and /usr
# partition. The script creates a partial clone of the root partition,
# and puts it into ${DEST} (defaults to /diskless_root ) on the server,
# where it is read.
#
# To run a diskless install you need to do the following:
#
# create /conf/default/etc/fstab
#    this will replace the standard /etc/fstab and should contain
#    as a minimum the following lines
#    ${SERVER}:${DEST} /     nfs    ro 0 0
#    ${SERVER}:/usr    /usr  nfs    ro 0 0
#    proc              /proc procfs rw 0 0
#
# create /conf/default/etc/rc.conf
#    this will replace the standard rc.conf and should contain
#    the startup options for the diskless client. Most likely
#    you will not need to set hostname and ifconfig_* because these
#    will be already set by the startup code. You will also
#    probably need to set local_startup="" so that the server's
#    local startup files will not be used.
#
# create a kernel config file in /sys/i386/conf/DISKLESS with
#       options MFS
#       options BOOTP
#       options BOOTP_NFSROOT
#       options BOOTP_COMPAT
# and do a full build of the kernel.
# If you use the firewall, remember to default to open or your kernel
# will not be able to send/receive the bootp packets.
#
# On the server:
# enable NFS server and set /etc/exports as
#       ${DEST} -maproot=0 -alldirs <list of diskless clients>
#       /usr -alldirs
#
# enable bootpd by uncommenting the bootps line in /etc/inetd.conf
# and putting at least the following entries in /etc/bootptab:
#  .default:\
#       hn:ht=1:vm=rfc1048:\
#       :sm=255.255.255.0:\
#       :sa=${SERVER}:\
#       :gw=${GATEWAY}:\
#       :rp="${SERVER}:${DEST}":
#
#  client1:ha=0123456789ab:tc=.default
#
# and make sure that client1 is listed in /etc/hosts

# VARIABLES:
#       some manual init is needed here.
# DEST  the diskless_root dir (goes into /etc/bootptab and /etc/exports
#       on the server)
# DEVICES       device entries to create in /dev
DEST=/diskless_root
DEVICES="all snd1 bktr0"

# you should not touch these vars:
# SYSDIRS       system directories and mountpoints
# DIRS          mountpoints (empty dirs)
# PWFILES       files related to passwords
# TOCOPY        files and dirs to copy from root partition

SYSDIRS="dev proc root usr var var/db"
DIRS="c cdrom home home2 mnt mnt1 sd1 sd1/usr wd0e wd2 wd2/usr"
PWFILES="master.passwd passwd spwd.db pwd.db"
TOCOPY="bin boot compat etc modules sbin stand sys"

init_diskless_root() {
        echo "Cleaning old diskless root ($DEST)"
        cd /
        rm -rf ${DEST} && echo "Old diskless root removed."
        echo "Creating $DEST..."
        mkdir -p $DEST && echo "New diskless root created."
        echo "+++ Now copy original tree from / ..."
        ex=""
        (cd / ; tar -clf - ${TOCOPY} ) | (cd $DEST; tar xvf - )
        #(cd / ; find -x dev | cpio -o -H newc ) | \
        #       (cd $DEST; cpio -i -H newc -d )
        echo "+++ Fixing permissions on some objects"
        chmod 555 $DEST/sbin/init
}

update_conf_and_pw() {
        echo "+++ Copying files in /conf and password files"
        (cd ${DEST} ; rm -rf conf )
        (cd / ; tar clf - conf ) | (cd ${DEST}; tar xvf - )
        mkdir -p ${DEST}/conf/etc       # used to mount things
        (cd /etc ; tar cvf - ${PWFILES} ) | (cd ${DEST}/etc ; tar xf - )
}

update() {
        echo "+++ update: create mountpoints and device entries, kernel"
        for i in ${SYSDIRS} ${DIRS}
        do
            rm -r -f ${DEST}/$i
            mkdir -p ${DEST}/$i && chown root:wheel ${DEST}/$i && echo -n "$i "
        done
        echo "."
        ln -s /var/tmp ${DEST}/tmp
        echo "+++ Now use MAKEDEV to create devices ${DEVICES}"
        (cd $DEST/dev ; cp /dev/MAKEDEV . )
        (cd $DEST/dev ; /dev/MAKEDEV ${DEVICES} )
        (cd $DEST/dev ; ln -s /dev/sysmouse mouse )
        echo "+++ Copying kernel from /sys/compile/DISKLESS"
        cp /sys/compile/DISKLESS/kernel $DEST/kernel
        echo "."
}


# Main entry point
case $1 in
        all)    # clean and reinstall the whole diskless_root
                init_diskless_root
                update
                update_conf_and_pw
                ;;

        update) # clean and rebuild mountpoints and device entries
                update
                update_conf_and_pw
                ;;

        *)      # copy /conf and password files
                update_conf_and_pw
                ;;
esac
exit 0
### end of file ###
------------- cut here --- end of clone_root ---------------

------------- cut here --- patches for /etc/rc and /etc/rc.diskless2 ----
--- src/etc/rc  Sat Apr 14 04:32:22 2001
+++ /etc/rc     Mon Apr 16 06:48:27 2001
@@ -187,24 +140,24 @@
 
 umount -a >/dev/null 2>&1
 
+# Run custom disk mounting function here
+#
+if [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
+               sh ${diskless_mount}
+else
 # Mount everything except nfs filesystems.
 mount -a -t nonfs
+fi
 
 case $? in
 0)
        ;;
 *)
        echo 'Mounting /etc/fstab filesystems failed, startup aborted'
        exit 1
        ;;
 esac
 
-# Run custom disk mounting function here
-#
-if [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
-               sh ${diskless_mount}
-fi
-
 adjkerntz -i
 
 purgedir() {
--- src/etc/rc.diskless2        Tue Mar  6 03:15:04 2001
+++ /etc/rc.diskless2   Mon Apr 16 07:12:25 2001
@@ -38,28 +38,34 @@
        . /etc/rc.conf
 fi
 
+echo "+++ mfs_mount of /var"
 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"
+echo "+++ create dirs in /var"
 for i in ${var_dirs}
 do
     mkdir /var/${i}
 done
-chmod 755 /var/run
-chmod 755 /var/db
-chmod 755 /var/spool
+chmod 755 /var/run /var/db /var/spool
 chmod 1777 /var/tmp
+
+mount -a       # chown and chgrp are in /usr
+
 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
+# We assume that /tmp is symlinked to /var/tmp on the shared root
+# echo "+++ mount_null of /var/tmp"
+# 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
+echo "+++ mount_mfs of /dev"
 mount_mfs -s 4096 -i 512 -T qp120at dummy /dev
 (cd /; cpio -i -H newc -d < /tmp/dev.tmp)

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-net" in the body of the message

Reply via email to