aboutsummaryrefslogtreecommitdiff
path: root/etc
diff options
context:
space:
mode:
Diffstat (limited to 'etc')
-rw-r--r--etc/rc.diskless1217
-rw-r--r--etc/rc.diskless280
2 files changed, 198 insertions, 99 deletions
diff --git a/etc/rc.diskless1 b/etc/rc.diskless1
index 3f0433569a4a..3fb22ad5cca1 100644
--- a/etc/rc.diskless1
+++ b/etc/rc.diskless1
@@ -1,57 +1,58 @@
-# 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.
+# Copyright (c) 1999-2002 Matt Dillion. Terms and conditions based on
+# the FreeBSD copyright as found at the base of the source distribution.
#
# $FreeBSD$
#
-
-#
# /etc/rc.diskless1 - general BOOTP startup
#
-# We assume that the shared readonly partition has been created with
-# the script /usr/share/examples/diskless/clone_root or similar
-# methods.
-#
-# BOOTP has mounted / for us. We assume a read-only mount, and that the
-# /conf subdirectory contains the following:
-# + /conf/base/etc
-# a copy of /etc, prepared by e.g. the clone_root script
-# + /conf/default
-# default files that override the ones in the readonly root
-# + /conf/${ipba} (${ipba} is the subnet broadcast address for the host)
-# subnet-specific files that override the ones in the readonly root
-# + /conf/${ip} (${ip} is the ip address for the host)
-# host-specific files that override the ones in the readonly root
-#
-# Now we need to do the following:
-# + figure out our IP by querying the interface
-# + mount /etc as an MFS
-# + populate /etc from /conf/base/etc
-# + override files in /etc with files from /conf/{default,${ipba},${ip}/etc
-#
-# 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.
+# 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
+# /<sub_directory_name>. 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 8192 (4MB). 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). Note that in -current the default is 4096 (2MB). For
+# example, /conf/base/etc/md_size might contain '16384'.
+#
+# If /conf/<special_dir>/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/<special_dir>/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! rc.diskless2 will create /var, /tmp, and /dev. Those filesystems
+# should not be specified in /conf. At least not yet.
# chkerr:
#
@@ -61,19 +62,36 @@
# 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
+ case $1 in
+ 0)
+ ;;
+ *)
+ echo "$2 failed: dropping into /bin/sh"
+ /bin/sh
+ # RESUME
+ ;;
+ esac
}
+# Create a generic memory disk
+#
mount_md() {
- /sbin/mount_mfs -s $1 -T qp120at -b 8192 -f 1024 dummy $2
+ /sbin/mount_mfs -s $1 -T qp120at -b 8192 -f 1024 dummy $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=8192
+ 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
@@ -103,34 +121,76 @@ for i in ${iflist} ; do
done
echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"
+# Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca},
+# 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.
+#
+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
-# Create an MFS /tmp to temporarily hold files from /etc until we
-# can bootstrap /etc as an MFS.
-
-mount_md 8192 /etc 0
-chkerr $? "MFS mount on /etc"
-/bin/chmod 755 /etc
+ # NFS remount
+ #
+ if [ -d $j -a -f $j/diskless_remount ]; then
+ nfspt=`/bin/cat $j/diskless_remount`
+ mount_nfs $nfspt $j
+ chkerr $? "mount_nfs $nfspt $j"
+ fi
+ done
+done
-# Populate /etc, and then override the base setup with increasingly
-# specific files.
-# The copy, especially the one with the initial content, touches
-# a large number of files, and can be very slow if the server is
-# far away. So, if there exists a cpio archive with the proper
-# content, use that one instead.
+# - 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;
-# + implement a way to _delete_ files when overriding configs.
for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
- if [ -f /conf/${i}/etc.cpio.gz ]; then
- echo "Loading ${i}/etc from cpio archive"
- (cd / ; /stand/gzip -d < /conf/${i}/etc.cpio.gz | \
- /stand/cpio --extract -d )
- elif [ -d /conf/${i}/etc ]; then
- cp -Rp /conf/${i}/etc/* /etc
+ 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
# Tell /etc/rc to run the specified script after
@@ -141,3 +201,4 @@ done
# diskless mount environment.
diskless_mount="/etc/rc.diskless2"
+
diff --git a/etc/rc.diskless2 b/etc/rc.diskless2
index e3abb5a91db6..b49773bb3161 100644
--- a/etc/rc.diskless2
+++ b/etc/rc.diskless2
@@ -34,11 +34,10 @@
# as close as possible between 5-current and 4-stable.
# $1 = size
# $2 = mount point
-# $3 = md unit number (ignored in pre 5.0 systems)
-# $4 = (optional) bytes-per-inode
+# $3 = (optional) bytes-per-inode
mount_md() {
- if [ -n "$4" ]; then
- bpi="-i $4"
+ if [ -n "$3" ]; then
+ bpi="-i $3"
fi
/sbin/mount_mfs -s $1 -T qp120at -b 8192 -f 1024 $bpi dummy $2
}
@@ -52,18 +51,37 @@ elif [ -r /etc/rc.conf ]; then
. /etc/rc.conf
fi
-echo "+++ mfs_mount of /var"
-mount_md ${varsize:=65536} /var 1
+# If we do not have a writable /var, create a memory
+# filesystem for /var. We don't have /usr yet so
+# use mkdir instead of touch to test. We want mount
+# to record its mounts so we have to make sure /var/db
+# exists before doing the mount -a.
+#
+if (/bin/mkdir /var/.diskless 2> /dev/null); then
+ rmdir /var/.diskless
+else
+ echo "+++ mfs_mount of /var"
+ mount_md ${varsize:=65536} /var
+fi
+
+if [ ! -d /var/db ]; then
+ mkdir /var/db
+fi
-mount -a # chown and chgrp are in /usr
+# Now we need the rest of our mounts, particularly /usr.
+#
+mount -a
+# Populate /var
+#
echo "+++ populate /var using /etc/mtree/BSD.var.dist"
-/usr/sbin/mtree -deU -f /etc/mtree/BSD.var.dist -p /var
+/usr/sbin/mtree -deU -f /etc/mtree/BSD.var.dist -p /var > /dev/null
+
case ${sendmail_enable} in
[Nn][Oo][Nn][Ee])
;;
*)
- /usr/sbin/mtree -deU -f /etc/mtree/BSD.sendmail.dist -p /
+ /usr/sbin/mtree -deU -f /etc/mtree/BSD.sendmail.dist -p / > /dev/null
;;
esac
@@ -76,24 +94,44 @@ fi
echo "+++ create lastlog"
/usr/bin/touch /var/log/lastlog
+# Make sure our aliases database is uptodate, the aliases may have
+# been overriden in /conf.
+#
+/usr/bin/newaliases
+
#
# XXX make sure to create one dir for each printer as requested by lpd
#
-
-# If /tmp is a symlink, assume it points to somewhere writable, like
-# /var/tmp, otherwise, use a small memory filesystem for /tmp.
-if [ ! -h /tmp ]; then
- mount_md ${tmpsize:=20480} /tmp 2
+# If we do not have a writable /tmp, create a memory
+# filesystem for /tmp. If /tmp is a symlink (e.g. to /var/tmp,
+# then it should already be writable).
+#
+if (/bin/mkdir /tmp/.diskless 2> /dev/null); then
+ rmdir /tmp/.diskless
+else
+ if [ -h /tmp ]; then
+ echo "*** /tmp is a symlink to a non-writable area!"
+ echo "dropping into shell, ^D to continue anyway."
+ /bin/sh
+ else
+ mount_md ${tmpsize:=20480} /tmp
+ chmod 01777 /tmp
+ fi
fi
-# Extract a list of device entries, then copy them to a writable fs.
-# The list can be long, so if there is already a cpio archive prepared
-# for us, use that one instead.
+# If /dev has already been created in rc.diskless1 it will be writable
+# and we do nothing. If /dev is not writable then we have to dup it as
+# a memory filesystem.
+#
+# note: /conf/dev.cpio.gz is no longer valid. Use /conf/base/dev.cpio.gz
+# instead and it will be handled in rc.diskless1
-if [ -f /conf/dev.cpio.gz ] ; then
- ln -s /conf/dev.cpio.gz /tmp/dev.cpio.gz
+if (/bin/mkdir /dev/.diskless 2> /dev/null); then
+ rmdir /dev/.diskless
else
(cd /; find -x dev | cpio --create -H newc | gzip) > /tmp/dev.cpio.gz
+ mount_md 4096 /dev 512
+ (cd /; gzip -dc /tmp/dev.cpio.gz | cpio --extract -H newc -d )
+ rm -f /tmp/dev.cpio.gz
fi
-mount_md 4096 /dev 3 512
-(cd /; gzip -dc /tmp/dev.cpio.gz | cpio --extract -H newc -d )
+