From owner-freebsd-current Fri Mar 30 9:38:42 2001 Delivered-To: freebsd-current@freebsd.org Received: from mailhub.fokus.gmd.de (mailhub.fokus.gmd.de [193.174.154.14]) by hub.freebsd.org (Postfix) with ESMTP id 6E4F937B718 for ; Fri, 30 Mar 2001 09:38:31 -0800 (PST) (envelope-from krepel@fokus.gmd.de) Received: from fokus.gmd.de (quant [193.175.133.183]) by mailhub.fokus.gmd.de (8.8.8/8.8.8) with ESMTP id TAA12839 for ; Fri, 30 Mar 2001 19:38:30 +0200 (MET DST) Message-ID: <3AC4C496.60861EB6@fokus.gmd.de> Date: Fri, 30 Mar 2001 19:38:30 +0200 From: Falco Krepel Organization: GMD FOKUS - CATS Group X-Mailer: Mozilla 4.76 [en] (X11; U; SunOS 5.6 sun4u) X-Accept-Language: en, de-DE MIME-Version: 1.0 To: freebsd-current@FreeBSD.org Subject: new rc.diskless{1,2} files Content-Type: multipart/mixed; boundary="------------9C3EE933AA7CBB7E614C0D38" Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG This is a multi-part message in MIME format. --------------9C3EE933AA7CBB7E614C0D38 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I have implemented good ideas from Mike Smith in my rc.diskless{1,2} files and make some other changes: 1. Now I use the kernel flag "vm.nswapdev" to determine if swap is available. 2. To determine if DEVFS are used I check the kernel flag "vfs.devfs.generation" as it done within the /etc/rc file. 3. I write "chk_err" and "mkmd" functions also in rc.diskless2 because the rc.diskless2 file is executed in the rc file: "sh rc.diskless2" When you change this call to ". rc.diskless2" than the mkmd function from rc.diskless2 could replace the mkmd function in rc.diskless1. The chk_err function in rc.diskless2 could be deleted. The following knobs must be added in the rc.conf: diskless_var_size="32m" diskless_tmp_enable="NO" diskless_tmp_size="32m" diskless_dev_size="2m" I am attaching the files here for those interested. Any comments are welcome. -- Falco Krepel Phone: +49-(0)30 - 34 63 - 7 276 GMD-FOKUS Fax: +49-(0)30 - 34 63 - 8 276 Kaiserin-Augusta-Allee 31 e-mail: krepel@fokus.gmd.de 10589 Berlin WWW: http://www.fokus.gmd.de/usr/krepel --------------9C3EE933AA7CBB7E614C0D38 Content-Type: text/plain; charset=us-ascii; name="rc.diskless1" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="rc.diskless1" # Copyright (c) 1999 Matt Dillion # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: src/etc/rc.diskless1,v 1.6 2000/10/08 19:18:24 obrien Exp $ # # # /etc/rc.diskless1 - general BOOTP startup # # BOOTP has mounted / for us. Assume a read-only mount. We must then # - figure out our IP by querying the interface # - fill /conf/etc (writable) with files from /etc, and then update # per-machine files from /conf/*/ where * is the IP of the host, # the IP of the subnet, "default", or nothing. # - mount /conf/etc over /etc so we can see the new files. # # WARNING: i thing you should not change /etc/rc or strange things could # happen. # # The operator is in charge of setting /conf/*/etc/* things as appropriate. # Typically rc.conf and fstab need to be changed, but possibly # also other files such as inetd.conf etc. # 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 } # mkmd: # # Builds an md(4) disk of the size in $1 # Labels and newfs' it. # Mounts it on the destination in $2 # Returns the name of the created md device in md_device # Returns the name of the device containing the filesystem in md_filesystem mkmd() { md_device=`mdconfig -a -t malloc -s $1` chkerr $? "configuring md device" disklabel -rw $md_device auto chkerr $? "labelling md device" md_filesystem=/dev/$md_device"c" newfs $md_filesystem 2>&1 >/dev/null chkerr $? "making md device filesystem" mount $md_filesystem $2 chkerr $? "mounting md filesystem on $2" } # DEBUGGING # # set -v # Figure out our interface and IP. # bootp_ifc="" bootp_ipa="" bootp_ipbca="" iflist=`ifconfig -l` for i in ${iflist} ; do set `ifconfig ${i}` while [ $# -ge 1 ] ; do if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then bootp_ifc=${i} ; bootp_ipa=${2} ; shift fi if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then bootp_ipbca=$2; shift fi shift done if [ "${bootp_ifc}" != "" ] ; then break fi done echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}" # 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. # # up to now we don't have make swapon and so we must use malloc # mkmd 2m /mnt cp -Rp /etc/* /mnt chkerr $? "copy /etc template" if [ -d /conf/${bootp_ipa} ] ; then cp -Rp /conf/${bootp_ipa}/etc/* /mnt elif [ -d /conf/${bootp_ipbca} ] ; then cp -Rp /conf/${bootp_ipbca}/etc/* /mnt else cp -Rp /conf/default/etc/* /mnt fi # Make the new directory available as /etc # umount /mnt mount $md_filesystem /etc # 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" --------------9C3EE933AA7CBB7E614C0D38 Content-Type: text/plain; charset=us-ascii; name="rc.diskless2" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="rc.diskless2" # Copyright (c) 1999 Matt Dillon # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: src/etc/rc.diskless2,v 1.7 2000/10/08 19:18:24 obrien 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 source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi # 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 } # mkmd: # # Builds an md(4) disk with malloc or swap depending on # the diskless client use swap with the size in $1 # Labels and newfs' it. # Mounts it on the destination in $2 # Returns the name of the created md device in md_device # Returns the name of the device containing the filesystem in md_filesystem # mkmd() { dlv=`/sbin/sysctl -n vm.nswapdev 2> /dev/null` if [ ${dlv:=0} != 0 ]; then md_device=`mdconfig -a -t swap -s $1` else md_device=`mdconfig -a -t malloc -s $1` fi chkerr $? "configuring md device" disklabel -rw $md_device auto chkerr $? "labelling md device" md_filesystem=/dev/$md_device"c" newfs $md_filesystem 2>&1 >/dev/null chkerr $? "making md device filesystem" mount $md_filesystem $2 chkerr $? "mounting md filesystem on $2" } # reconstruct /var # mkmd ${diskless_var_size} /var mtree -p /var -eU -f /etc/mtree/BSD.var.dist 2>&1 >/dev/null touch /var/log/cron touch /var/log/lpd-errs touch /var/log/maillog touch /var/log/messages touch /var/log/ppp.log touch /var/log/security touch /var/log/slip.log # Copy the templated /dev into a locally-writable version # if wo are not using DEVFS # if [ ! sysctl vfs.devfs.generation > /dev/null 2>&1 ]; then mkmd ${diskless_dev_size} /mnt cp -Rp /dev/* /mnt umount /mnt mount $md_filesystem /dev fi # Build a small /tmp # case ${diskless_tmp_enable} in [Yy][Ee][Ss]) mkmd ${diskless_tmp_size} /tmp ;; *) if [ ! -h /tmp -a ! -h /var/tmp ]; then mount_null /var/tmp /tmp fi ;; esac --------------9C3EE933AA7CBB7E614C0D38-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message