Index: head/etc/rc.d/atm3 =================================================================== --- head/etc/rc.d/atm3 (revision 121066) +++ head/etc/rc.d/atm3 (revision 121067) @@ -1,93 +1,93 @@ #!/bin/sh # # Copyright (c) 2000 The FreeBSD Project # 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$ # # Start ATM daemons # PROVIDE: atm3 # REQUIRE: atm2 # BEFORE: DAEMON # KEYWORD: FreeBSD . /etc/rc.subr name="atm3" rcvar="atm_enable" start_cmd="atm3_start" stop_cmd=":" atm3_start() { echo -n 'Starting ATM daemons:' # Get a list of network interfaces atm_nif=`atm sh netif | { read junk ; \ while read dev junk ; do echo "${dev} " - done + done }` for net in ${atm_nif} ; do eval atmarp_args=\$atm_arpserver_${net} eval scsparp_args=\$atm_scsparp_${net} case ${scsparp_args} in [Yy][Ee][Ss]) case ${atmarp_args} in local) ;; *) warn "${net}: local arpserver required for SCSP" continue ;; esac atm_atmarpd="${atm_atmarpd} ${net}" atm_scspd=1 ;; esac done # Start SCSP daemon (if needed) case ${atm_scspd} in 1) echo -n ' scspd' scspd ;; esac # Start ATMARP daemon (if needed) if [ -n "${atm_atmarpd}" ]; then echo -n ' atmarpd' atmarpd ${atm_atmarpd} fi echo '.' } load_rc_config $name run_rc_command "$1" Index: head/etc/rc.d/initdiskless =================================================================== --- head/etc/rc.d/initdiskless (revision 121066) +++ head/etc/rc.d/initdiskless (revision 121067) @@ -1,240 +1,240 @@ #!/bin/sh # # 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$ # # PROVIDE: initdiskless # KEYWORD: FreeBSD - + # On entry to this script the entire system consists of a read-only root # mounted via NFS. We use the contents of /conf to create and populate # memory filesystems. The kernel has run BOOTP and configured an interface # (otherwise it would not have been able to mount the NFS root!) # # The following directories are scanned. Each sucessive directory overrides # (is merged into) the previous one. # # /conf/base universal base # /conf/default modified by a secondary universal base # /conf/${ipba} modified based on the assigned broadcast IP # /conf/${ip} modified based on the machine's assigned IP # # Each of these directories may contain any number of subdirectories which # represent directories in / on the diskless machine. The existance of # these subdirectories causes this script to create a MEMORY FILESYSTEM for # /. For example, if /conf/base/etc exists then a # memory filesystem will be created for /etc. # # If a subdirectory contains the file 'diskless_remount' the contents of # the file is used to remount the subdirectory prior to it being copied to # the memory filesystem. For example, if /conf/base/etc/diskless_remount # contains the string 'my.server.com:/etc' then my.server.com:/etc will be # mounted in place of the subdirectory. This allows you to avoid making # duplicates of system directories in /conf. # # If a subdirectory contains the file 'md_size', the contents of the # file is used to determine the size of the memory filesystem, in 512 # byte sectors. The default is 10240 (5MB). You only have to specify an # md_size if the default doesn't work for you (i.e. if it is too big or # too small). For example, /conf/base/etc/md_size might contain '16384'. # # If /conf//SUBDIR.cpio.gz exists, the file is cpio'd into # the specified /SUBDIR (and a memory filesystem is created for /SUBDIR # if necessary). # # If /conf//SUBDIR.remove exists, the file contains a list # of paths which are rm -rf'd relative to /SUBDIR. # # You will almost universally want to create a /conf/base/etc containing # a diskless_remount and possibly an md_size file. You will then almost # universally want to override rc.conf, rc.local, and fstab by creating # /conf/default/etc/{rc.conf,rc.local,fstab}. Your fstab should be sure # to mount a /usr... typically an NFS readonly /usr. # # NOTE! /etc/rc.d/diskless will create /var, /tmp, and /dev. # Those filesystems should not be specified in /conf. At least not yet. dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` [ ${dlv:=0} -eq 0 ] && exit 0 # 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 } # Create a generic memory disk # mount_md() { /sbin/mdmfs -i 4096 -s $1 -M md $2 } # Create the memory filesystem if it has not already been created # create_md() { if [ "x`eval echo \\$md_created_$1`" = "x" ]; then if [ "x`eval echo \\$md_size_$1`" = "x" ]; then md_size=10240 else md_size=`eval echo \\$md_size_$1` fi mount_md $md_size /$1 /bin/chmod 755 /$1 eval md_created_$1=created fi } # 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}" # Figure out our NFS root path -# +# set `mount -t nfs` while [ $# -ge 1 ] ; do if [ "$2" = "on" -a "$3" = "/" ]; then nfsroot="$1" break fi shift done # Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca}, -# and /conf/${bootp_ipa}. For each subdirectory found within these +# and /conf/${bootp_ipa}. For each subdirectory found within these # directories: # # - calculate memory filesystem sizes. If the subdirectory (prior to # NFS remounting) contains the file 'md_size', the contents specified # in 512 byte sectors will be used to size the memory filesystem. Otherwise # 8192 sectors (4MB) is used. # # - handle NFS remounts. If the subdirectory contains the file # diskless_remount, the contents of the file is NFS mounted over # the directory. For example /conf/base/etc/diskless_remount # might contain 'myserver:/etc'. NFS remounts allow you to avoid # having to dup your system directories in /conf. Your server must # be sure to export those filesystems -alldirs, however. # If the diskless_remount file contains a string beginning with a # '/' it is assumed that the local nfsroot should be prepended to # it before attemping to the remount. This allows the root to be # relocated without needing to change the remount files. # for i in base default ${bootp_ipbca} ${bootp_ipa} ; do for j in /conf/$i/* ; do # memory filesystem size specification # subdir=${j##*/} if [ -d $j -a -f $j/md_size ]; then eval md_size_$subdir=`cat $j/md_size` fi # NFS remount # if [ -d $j -a -f $j/diskless_remount ]; then nfspt=`/bin/cat $j/diskless_remount` if [ `expr "$nfspt" : '\(.\)'` = "/" ]; then nfspt="${nfsroot}${nfspt}" fi mount_nfs $nfspt $j chkerr $? "mount_nfs $nfspt $j" fi done done # - Create all required MFS filesystems and populate them from # our templates. Support both a direct template and a dir.cpio.gz # archive. Support dir.remove files containing a list of relative # paths to remove. # # TODO: # + find a way to assign a 'group' identifier to a machine # so we can use group-specific configurations; for i in base default ${bootp_ipbca} ${bootp_ipa} ; do for j in /conf/$i/* ; do subdir=${j##*/} if [ -d $j ]; then create_md $subdir cp -Rp $j/* /$subdir fi done for j in /conf/$i/*.cpio.gz ; do subdir=${j%*.cpio.gz} subdir=${subdir##*/} if [ -f $j ]; then create_md $subdir echo "Loading /$subdir from cpio archive $j" (cd / ; /stand/gzip -d < $j | /stand/cpio --extract -d ) fi done for j in /conf/$i/*.remove ; do subdir=${j%*.remove} subdir=${subdir##*/} if [ -f $j ]; then # doubly sure it is a memory disk before rm -rf'ing create_md $subdir (cd /$subdir; rm -rf `/bin/cat $j`) fi done done Index: head/etc/rc.d/ipfilter =================================================================== --- head/etc/rc.d/ipfilter (revision 121066) +++ head/etc/rc.d/ipfilter (revision 121067) @@ -1,180 +1,180 @@ #!/bin/sh # # $NetBSD: ipfilter,v 1.10 2001/02/28 17:03:50 lukem Exp $ # $FreeBSD$ # # PROVIDE: ipfilter # REQUIRE: root beforenetlkm mountcritlocal ipmon # BEFORE: netif # KEYWORD: FreeBSD NetBSD . /etc/rc.subr name="ipfilter" rcvar=`set_rcvar` load_rc_config $name case ${OSTYPE} in FreeBSD) stop_precmd="test -f ${ipfilter_rules} -o -f ${ipv6_ipfilter_rules}" ;; NetBSD) stop_precmd="test -f /etc/ipf.conf -o -f /etc/ipf6.conf" ;; esac start_precmd="ipfilter_prestart" start_cmd="ipfilter_start" stop_cmd="ipfilter_stop" reload_precmd="$stop_precmd" reload_cmd="ipfilter_reload" resync_precmd="$stop_precmd" resync_cmd="ipfilter_resync" status_precmd="$stop_precmd" status_cmd="ipfilter_status" extra_commands="reload resync status" ipfilter_prestart() { case ${OSTYPE} in FreeBSD) # load ipfilter kernel module if needed if ! kldstat -v | grep "IP Filter" > /dev/null 2>&1; then if kldload ipl; then info 'IP-filter module loaded.' else err 1 'IP-filter module failed to load.' fi fi # check for ipfilter rules if [ ! -r "${ipfilter_rules}" ] && [ ! -r "${ipv6_ipfilter_rules}" ] then warn 'IP-filter: NO IPF RULES' return 1 fi ;; NetBSD) if [ ! -f /etc/ipf.conf ] && [ ! -f /etc/ipf6.conf ]; then warn "/etc/ipf*.conf not readable; ipfilter start aborted." # # If booting directly to multiuser, send SIGTERM to # the parent (/etc/rc) to abort the boot # if [ "$autoboot" = yes ]; then echo "ERROR: ABORTING BOOT (sending SIGTERM to parent)!" kill -TERM $$ exit 1 fi return 1 fi ;; esac return 0 } ipfilter_start() { echo "Enabling ipfilter." case ${OSTYPE} in FreeBSD) if [ `sysctl -n net.inet.ipf.fr_running` -eq 0 ]; then ${ipfilter_program:-/sbin/ipf} -E - fi + fi ${ipfilter_program:-/sbin/ipf} -Fa if [ -r "${ipfilter_rules}" ]; then ${ipfilter_program:-/sbin/ipf} \ -f "${ipfilter_rules}" ${ipfilter_flags} fi ${ipfilter_program:-/sbin/ipf} -6 -Fa if [ -r "${ipv6_ipfilter_rules}" ]; then ${ipfilter_program:-/sbin/ipf} -6 \ -f "${ipv6_ipfilter_rules}" ${ipfilter_flags} fi ;; NetBSD) /sbin/ipf -E -Fa if [ -f /etc/ipf.conf ]; then /sbin/ipf -f /etc/ipf.conf fi if [ -f /etc/ipf6.conf ]; then /sbin/ipf -6 -f /etc/ipf6.conf fi ;; esac } ipfilter_stop() { # XXX - The ipf -D command is not effective for 'lkm's if [ `sysctl -n net.inet.ipf.fr_running` -eq 1 ]; then case ${OSTYPE} in FreeBSD) echo "Saving firewall state tables" ${ipfs_program:-/sbin/ipfs} -W ${ipfs_flags} echo "Disabling ipfilter." ${ipfilter_program:-/sbin/ipf} -D ;; NetBSD) echo "Disabling ipfilter." /sbin/ipf -D ;; esac fi } ipfilter_reload() { echo "Reloading ipfilter rules." case ${OSTYPE} in FreeBSD) ${ipfilter_program:-/sbin/ipf} -I -Fa if [ -r "${ipfilter_rules}" ]; then ${ipfilter_program:-/sbin/ipf} -I \ -f "${ipfilter_rules}" ${ipfilter_flags} fi ${ipfilter_program:-/sbin/ipf} -I -6 -Fa if [ -r "${ipv6_ipfilter_rules}" ]; then ${ipfilter_program:-/sbin/ipf} -I -6 \ -f "${ipv6_ipfilter_rules}" ${ipfilter_flags} fi ${ipfilter_program:-/sbin/ipf} -s ;; NetBSD) /sbin/ipf -I -Fa if [ -f /etc/ipf.conf ] && ! /sbin/ipf -I -f /etc/ipf.conf; then err 1 "reload of ipf.conf failed; not swapping to" \ " new ruleset." fi if [ -f /etc/ipf6.conf ] && \ ! /sbin/ipf -I -6 -f /etc/ipf6.conf; then err 1 "reload of ipf6.conf failed; not swapping to" \ " new ruleset." fi /sbin/ipf -s ;; esac } ipfilter_resync() { case ${OSTYPE} in FreeBSD) # Don't resync if ipfilter is not loaded if ! kldstat -v | grep "IP Filter" > /dev/null 2>&1; then return fi ;; esac ${ipfilter_program:-/sbin/ipf} -y ${ipfilter_flags} } ipfilter_status() { ${ipfilter_program:-/sbin/ipf} -V } run_rc_command "$1" Index: head/etc/rc.d/ipnat =================================================================== --- head/etc/rc.d/ipnat (revision 121066) +++ head/etc/rc.d/ipnat (revision 121067) @@ -1,65 +1,65 @@ #!/bin/sh # # $NetBSD: ipnat,v 1.6 2000/09/19 13:04:38 lukem Exp $ # $FreeBSD$ # # PROVIDE: ipnat # REQUIRE: ipfilter # BEFORE: DAEMON netif # KEYWORD: FreeBSD NetBSD . /etc/rc.subr name="ipnat" rcvar=`set_rcvar` load_rc_config $name case ${OSTYPE} in NetBSD) ipnat_flags= ipnat_rules="/etc/ipnat.conf" ipnat_program="/usr/sbin/ipnat" ;; esac start_precmd="ipnat_precmd" start_cmd="ipnat_start" stop_cmd="${ipnat_program} -F -C" reload_cmd="${ipnat_program} -F -C -f ${ipnat_rules}" extra_commands="reload" ipnat_precmd() { case ${OSTYPE} in NetBSD) - if ! checkyesno ipfilter || [ ! -f /etc/ipf.conf ]; then + if ! checkyesno ipfilter || [ ! -f /etc/ipf.conf ]; then echo "Enabling ipfilter for NAT." /sbin/ipf -E -Fa fi return 0 ;; esac # Make sure ipfilter is loaded before continuing if ! ${SYSCTL} net.inet.ipf.fr_pass >/dev/null 2>&1; then if kldload ipl; then info 'IP-filter module loaded.' else err 1 'IP-filter module failed to load.' fi fi return 0 } ipnat_start() { if [ ! -f ${ipnat_rules} ]; then warn 'NO IPNAT RULES' return 0 fi echo -n "Installing NAT rules." ${ipnat_program} -CF -f ${ipnat_rules} ${ipnat_flags} } run_rc_command "$1" Index: head/etc/rc.d/jail =================================================================== --- head/etc/rc.d/jail (revision 121066) +++ head/etc/rc.d/jail (revision 121067) @@ -1,159 +1,159 @@ #!/bin/sh # # $FreeBSD$ # # PROVIDE: jail # REQUIRE: LOGIN # BEFORE: securelevel # KEYWORD: FreeBSD shutdown . /etc/rc.subr name="jail" rcvar=`set_rcvar` start_cmd="jail_start" stop_cmd="jail_stop" # init_variables _j # Initialize the various jail variables for jail _j. # init_variables() { _j="$1" if [ -z "$_j" ]; then warn "init_variables: you must specify a jail" return fi eval jail_rootdir=\"\$jail_${_j}_rootdir\" jail_devdir="${jail_rootdir}/dev" jail_fdescdir="${jail_devdir}/fd" jail_procdir="${jail_rootdir}/proc" eval jail_hostname=\"\$jail_${_j}_hostname\" eval jail_ip=\"\$jail_${_j}_ip\" eval jail_exec=\"\$jail_${_j}_exec\" [ -z "${jail_exec}" ] && jail_exec="/bin/sh /etc/rc" # The default jail ruleset will be used by rc.subr if none is specified. eval jail_ruleset=\"\$jail_${_j}_devfs_ruleset\" eval jail_devfs=\"\$jail_${_j}_devfs_enable\" [ -z "${jail_devfs}" ] && jail_devfs="NO" eval jail_fdescfs=\"\$jail_${_j}_fdescfs_enable\" [ -z "${jail_fdescfs}" ] && jail_fdescfs="NO" eval jail_procfs=\"\$jail_${_j}_procfs_enable\" [ -z "${jail_procfs}" ] && jail_procfs="NO" # Debuggin aid # debug "$_j devfs enable: $jail_devfs" debug "$_j fdescfs enable: $jail_fdescfs" debug "$_j procfs enable: $jail_procfs" debug "$_j hostname: $jail_hostname" debug "$_j ip: $jail_ip" debug "$_j root: $jail_rootdir" debug "$_j devdir: $jail_devdir" debug "$_j fdescdir: $jail_fdescdir" debug "$_j procdir: $jail_procdir" debug "$_j ruleset: $jail_ruleset" } jail_start() { echo -n 'Configuring jails:' echo -n ' set_hostname_allowed=' - if checkyesno jail_set_hostname_allow ; then + if checkyesno jail_set_hostname_allow ; then echo -n 'YES' ${SYSCTL_W} 1>/dev/null security.jail.set_hostname_allowed=1 else echo -n 'NO' ${SYSCTL_W} 1>/dev/null security.jail.set_hostname_allowed=0 fi echo -n ' unixiproute_only=' - if checkyesno jail_socket_unixiproute_only ; then + if checkyesno jail_socket_unixiproute_only ; then echo -n 'YES' ${SYSCTL_W} 1>/dev/null security.jail.socket_unixiproute_only=1 else echo -n 'NO' ${SYSCTL_W} 1>/dev/null security.jail.socket_unixiproute_only=0 fi echo -n ' sysvipc_allow=' if checkyesno jail_sysvipc_allow ; then echo -n 'YES' ${SYSCTL_W} 1>/dev/null security.jail.sysvipc_allowed=1 else echo -n 'NO' ${SYSCTL_W} 1>/dev/null security.jail.sysvipc_allowed=0 fi echo '.' echo -n 'Starting Jails:' - for _jail in ${jail_list} + for _jail in ${jail_list} do init_variables $_jail if checkyesno jail_devfs; then info "Mounting devfs on ${jail_devdir}" devfs_mount_jail "${jail_devdir}" ${jail_ruleset} # Transitional symlink for old binaries if [ ! -L ${jail_devdir}/log ]; then devfs_link ${jail_devdir} ../var/run/log log fi # Jail console output devfs_link ${jail_devdir} ../var/log/console console fi if checkyesno jail_fdescfs; then info "Mounting fdescfs on ${jail_fdescdir}" mount -t fdescfs fdesc "${jail_fdescdir}" fi if checkyesno jail_procfs; then info "Mounting procfs onto ${jail_procdir}" if [ -d ${jail_procdir} ] ; then mount -t procfs proc "${jail_procdir}" fi fi jail 1>/dev/null 2>&1 \ ${jail_rootdir} ${jail_hostname} ${jail_ip} ${jail_exec} [ "$?" -eq 0 ] && echo -n " $jail_hostname" done echo '.' } jail_stop() { echo 'Stopping all jails.' if checkyesno jail_stop_jailer; then rc_pid=$(ps aux | grep "jailer" | awk '$8 ~ /.*J/ {print $2};') else rc_pid=$(ps aux | awk '$8 ~ /.*J/ {print $2};') fi if [ -n "${rc_pid}" ]; then kill -TERM $rc_pid wait_for_pids $rc_pid fi for _jail in ${jail_list} do init_variables $_jail if checkyesno jail_devfs; then if [ -d ${jail_devdir} ] ; then umount -f ${jail_devdir} >/dev/null 2>&1 fi fi if checkyesno jail_fdescfs; then umount -f ${jail_fdescdir} >/dev/null 2>&1 fi if checkyesno jail_procfs; then if [ -d ${jail_procdir} ] ; then umount -f ${jail_procdir} >/dev/null 2>&1 fi fi done } load_rc_config $name run_rc_command "$1" Index: head/etc/rc.initdiskless =================================================================== --- head/etc/rc.initdiskless (revision 121066) +++ head/etc/rc.initdiskless (revision 121067) @@ -1,240 +1,240 @@ #!/bin/sh # # 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$ # # PROVIDE: initdiskless # KEYWORD: FreeBSD - + # On entry to this script the entire system consists of a read-only root # mounted via NFS. We use the contents of /conf to create and populate # memory filesystems. The kernel has run BOOTP and configured an interface # (otherwise it would not have been able to mount the NFS root!) # # The following directories are scanned. Each sucessive directory overrides # (is merged into) the previous one. # # /conf/base universal base # /conf/default modified by a secondary universal base # /conf/${ipba} modified based on the assigned broadcast IP # /conf/${ip} modified based on the machine's assigned IP # # Each of these directories may contain any number of subdirectories which # represent directories in / on the diskless machine. The existance of # these subdirectories causes this script to create a MEMORY FILESYSTEM for # /. For example, if /conf/base/etc exists then a # memory filesystem will be created for /etc. # # If a subdirectory contains the file 'diskless_remount' the contents of # the file is used to remount the subdirectory prior to it being copied to # the memory filesystem. For example, if /conf/base/etc/diskless_remount # contains the string 'my.server.com:/etc' then my.server.com:/etc will be # mounted in place of the subdirectory. This allows you to avoid making # duplicates of system directories in /conf. # # If a subdirectory contains the file 'md_size', the contents of the # file is used to determine the size of the memory filesystem, in 512 # byte sectors. The default is 10240 (5MB). You only have to specify an # md_size if the default doesn't work for you (i.e. if it is too big or # too small). For example, /conf/base/etc/md_size might contain '16384'. # # If /conf//SUBDIR.cpio.gz exists, the file is cpio'd into # the specified /SUBDIR (and a memory filesystem is created for /SUBDIR # if necessary). # # If /conf//SUBDIR.remove exists, the file contains a list # of paths which are rm -rf'd relative to /SUBDIR. # # You will almost universally want to create a /conf/base/etc containing # a diskless_remount and possibly an md_size file. You will then almost # universally want to override rc.conf, rc.local, and fstab by creating # /conf/default/etc/{rc.conf,rc.local,fstab}. Your fstab should be sure # to mount a /usr... typically an NFS readonly /usr. # # NOTE! /etc/rc.d/diskless will create /var, /tmp, and /dev. # Those filesystems should not be specified in /conf. At least not yet. dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` [ ${dlv:=0} -eq 0 ] && exit 0 # 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 } # Create a generic memory disk # mount_md() { /sbin/mdmfs -i 4096 -s $1 -M md $2 } # Create the memory filesystem if it has not already been created # create_md() { if [ "x`eval echo \\$md_created_$1`" = "x" ]; then if [ "x`eval echo \\$md_size_$1`" = "x" ]; then md_size=10240 else md_size=`eval echo \\$md_size_$1` fi mount_md $md_size /$1 /bin/chmod 755 /$1 eval md_created_$1=created fi } # 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}" # Figure out our NFS root path -# +# set `mount -t nfs` while [ $# -ge 1 ] ; do if [ "$2" = "on" -a "$3" = "/" ]; then nfsroot="$1" break fi shift done # Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca}, -# and /conf/${bootp_ipa}. For each subdirectory found within these +# and /conf/${bootp_ipa}. For each subdirectory found within these # directories: # # - calculate memory filesystem sizes. If the subdirectory (prior to # NFS remounting) contains the file 'md_size', the contents specified # in 512 byte sectors will be used to size the memory filesystem. Otherwise # 8192 sectors (4MB) is used. # # - handle NFS remounts. If the subdirectory contains the file # diskless_remount, the contents of the file is NFS mounted over # the directory. For example /conf/base/etc/diskless_remount # might contain 'myserver:/etc'. NFS remounts allow you to avoid # having to dup your system directories in /conf. Your server must # be sure to export those filesystems -alldirs, however. # If the diskless_remount file contains a string beginning with a # '/' it is assumed that the local nfsroot should be prepended to # it before attemping to the remount. This allows the root to be # relocated without needing to change the remount files. # for i in base default ${bootp_ipbca} ${bootp_ipa} ; do for j in /conf/$i/* ; do # memory filesystem size specification # subdir=${j##*/} if [ -d $j -a -f $j/md_size ]; then eval md_size_$subdir=`cat $j/md_size` fi # NFS remount # if [ -d $j -a -f $j/diskless_remount ]; then nfspt=`/bin/cat $j/diskless_remount` if [ `expr "$nfspt" : '\(.\)'` = "/" ]; then nfspt="${nfsroot}${nfspt}" fi mount_nfs $nfspt $j chkerr $? "mount_nfs $nfspt $j" fi done done # - Create all required MFS filesystems and populate them from # our templates. Support both a direct template and a dir.cpio.gz # archive. Support dir.remove files containing a list of relative # paths to remove. # # TODO: # + find a way to assign a 'group' identifier to a machine # so we can use group-specific configurations; for i in base default ${bootp_ipbca} ${bootp_ipa} ; do for j in /conf/$i/* ; do subdir=${j##*/} if [ -d $j ]; then create_md $subdir cp -Rp $j/* /$subdir fi done for j in /conf/$i/*.cpio.gz ; do subdir=${j%*.cpio.gz} subdir=${subdir##*/} if [ -f $j ]; then create_md $subdir echo "Loading /$subdir from cpio archive $j" (cd / ; /stand/gzip -d < $j | /stand/cpio --extract -d ) fi done for j in /conf/$i/*.remove ; do subdir=${j%*.remove} subdir=${subdir##*/} if [ -f $j ]; then # doubly sure it is a memory disk before rm -rf'ing create_md $subdir (cd /$subdir; rm -rf `/bin/cat $j`) fi done done