rc.d/diskless overhaul
Brooks Davis
brooks at one-eyed-alien.net
Fri Mar 5 17:12:34 PST 2004
Please find attached, a patch to overhaul rc.d/diskless (the script
formerly know as rc.diskless2.)
These changes break the functions of diskless up into three new scripts,
resolv, tmp, and var, plus a modification to hostname. To enable
scenerios other than NFS roots, these scripts no longer check that they
are operating in that mode and instead rely of an combination of rc.conf
variables and automated probes to determine what actions they will take.
I am running these changes on my test cluster with good results.
Comments on the operation of the scripts or on how they are written are
requested. Developers can find these changes in perforce under
//depot/user/brooks/cleanup/... Documenation will follow after
functionality is determined.
-- Brooks
Changed files:
etc/rc.subr
etc/defaults/rc.conf
etc/rc.d/Makefile
etc/rc.d/cleanvar
etc/rc.d/cleartmp
etc/rc.d/hostname
etc/rc.d/initdiskless
Added files:
etc/rc.d/resolv
etc/rc.d/tmp
etc/rc.d/var
Removed files (remove these by hand):
etc/rc.d/diskless
*** diffs for diskless changes ***
--- ../freebsd/etc/rc.subr Thu Mar 4 14:05:49 2004
+++ etc/rc.subr Fri Mar 5 16:06:12 2004
@@ -1273,3 +1273,16 @@
fi
return 0
}
+
+# Provide a function for normalizing the mounting of memory
+# filesystems. This should allow the rest of the code here to remain
+# as close as possible between 5-current and 4-stable.
+# $1 = size
+# $2 = mount point
+# $3 = (optional) bytes-per-inode
+mount_md() {
+ if [ -n "$3" ]; then
+ bpi="-i $3"
+ fi
+ /sbin/mdmfs $bpi -s $1 -M md $2
+}
--- ../freebsd/etc/defaults/rc.conf Thu Mar 4 14:05:49 2004
+++ etc/defaults/rc.conf Fri Mar 5 16:06:11 2004
@@ -38,6 +38,11 @@
pccard_conf="/etc/defaults/pccard.conf" # pccardd(8) config file
pccard_ether_delay="5" # Delay before trying to start dhclient in pccard_ether
removable_interfaces="" # Removable network interfaces for /etc/pccard_ether.
+tmpmfs="AUTO" # Set to YES to always create an mfs /tmp, NO to never
+tmpsize="20m" # Size of mfs /tmp if created
+varmfs="AUTO" # Set to YES to always create an mfs /var, NO to never
+varsize="32m" # Size of mfs /var if created
+populate_var="AUTO" # Set to YES to always (re)populate /var, NO to never
local_startup="/usr/local/etc/rc.d /usr/X11R6/etc/rc.d" # startup script dirs.
script_name_sep=" " # Change if your startup scripts' names contain spaces
rc_conf_files="/etc/rc.conf /etc/rc.conf.local"
--- ../freebsd/etc/rc.d/Makefile Fri Mar 5 10:59:01 2004
+++ etc/rc.d/Makefile Fri Mar 5 16:27:40 2004
@@ -6,7 +6,7 @@
apm apmd archdep atm1 atm2 atm3 \
bgfsck bootparams \
ccd cleanvar cleartmp cron \
- devd devfs dhclient diskless \
+ devd devfs dhclient \
dmesg dumpon \
early.sh \
fsck \
@@ -27,14 +27,14 @@
othermta \
pccard pcvt power_profile ppp-user pppoed pwcheck \
quota \
- random rarpd rcconf.sh root \
+ random rarpd rcconf.sh resolv root \
route6d routed routing rpcbind rtadvd rwho \
savecore securelevel sendmail \
serial sppp sshd swap1 \
syscons sysctl syslogd \
- timed \
+ timed tmp \
usbd \
- vinum virecover \
+ var vinum virecover \
watchdogd \
ypbind yppasswdd ypserv \
ypset ypupdated ypxfrd
--- ../freebsd/etc/rc.d/cleanvar Tue Sep 30 22:50:50 2003
+++ etc/rc.d/cleanvar Fri Mar 5 16:06:11 2004
@@ -4,7 +4,7 @@
#
# PROVIDE: cleanvar
-# REQUIRE: mountcritlocal
+# REQUIRE: mountcritlocal var
# KEYWORD: FreeBSD
purgedir()
--- ../freebsd/etc/rc.d/cleartmp Fri Mar 5 10:59:01 2004
+++ etc/rc.d/cleartmp Fri Mar 5 16:27:40 2004
@@ -5,7 +5,7 @@
#
# PROVIDE: cleartmp
-# REQUIRE: mountcritremote
+# REQUIRE: mountall tmp
# BEFORE: DAEMON
# KEYWORD: FreeBSD
--- ../freebsd/etc/rc.d/hostname Fri Mar 5 10:59:01 2004
+++ etc/rc.d/hostname Fri Mar 5 16:27:40 2004
@@ -49,6 +49,14 @@
fi
elif [ -n "`hostname -s`" ]; then
return
+ else
+ # If we're not in a jail and rc.conf doesn't specify a
+ # hostname, see if we can get one from kenv.
+ #
+ if [ -z "${hostname}" -a \
+ "x`/bin/kenv dhcp.host-name`" != "x" ]; then
+ hostname=`/bin/kenv dhcp.host-name`
+ fi
fi
hostname ${hostname}
--- ../freebsd/etc/rc.d/initdiskless Mon Oct 13 15:25:52 2003
+++ etc/rc.d/initdiskless Fri Mar 5 15:28:18 2004
@@ -75,8 +75,8 @@
# /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.
+# NOTE! /var, /tmp, and /dev will be created elsewhere.
+# Those filesystems should not be specified in /conf.
dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
[ ${dlv:=0} -eq 0 ] && exit 0
@@ -158,6 +158,17 @@
fi
shift
done
+
+# If /conf/diskless_remount exists, remount all of /conf. This allows
+# multiple roots to share the same conf files.
+if [ -d /conf -a -f /conf/diskless_remount ]; then
+ nfspt=`/bin/cat /conf/diskless_remount`
+ if [ `expr "$nfspt" : '\(.\)'` = "/" ]; then
+ nfspt="${nfsroot}${nfspt}"
+ fi
+ mount_nfs $nfspt /conf
+ chkerr $? "mount_nfs $nfspt /conf"
+fi
# Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca},
# and /conf/${bootp_ipa}. For each subdirectory found within these
--- /dev/null Fri Mar 5 16:33:00 2004
+++ etc/rc.d/resolv Fri Mar 5 16:06:11 2004
@@ -0,0 +1,56 @@
+#!/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: src/etc/rc.d/diskless,v 1.30 2004/01/05 19:14:47 brooks Exp $
+#
+
+# PROVIDE: resolv
+# REQUIRE: initdiskless rcconf
+# KEYWORD: FreeBSD
+
+. /etc/rc.subr
+
+name="resolv"
+
+load_rc_config $name
+
+# if the info is available via dhcp/kenv
+# build the resolv.conf
+#
+if [ ! -e /etc/resolv.conf -a \
+ "x`/bin/kenv dhcp.domain-name-servers 2> /dev/null`" != "x" ]; then
+ /bin/cat /dev/null > /etc/resolv.conf
+
+ if [ "x`/bin/kenv dhcp.domain-name 2> /dev/null`" != "x" ]; then
+ echo domain `/bin/kenv dhcp.domain-name` > /etc/resolv.conf
+ fi
+
+ set `/bin/kenv dhcp.domain-name-servers`
+ for ns in `IFS=','; echo $*`; do
+ echo nameserver $ns >> /etc/resolv.conf;
+ done
+fi
+
--- /dev/null Fri Mar 5 16:33:00 2004
+++ etc/rc.d/tmp Fri Mar 5 16:06:11 2004
@@ -0,0 +1,65 @@
+#!/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: src/etc/rc.d/diskless,v 1.30 2004/01/05 19:14:47 brooks Exp $
+#
+
+# PROVIDE: tmp
+# REQUIRE: mountcritlocal
+# KEYWORD: FreeBSD
+
+. /etc/rc.subr
+
+name="tmp"
+
+load_rc_config $name
+
+# 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).
+#
+case "${tmpmfs}" in
+[Yy][Ee][Ss])
+ mount_md ${tmpsize} /tmp
+ chmod 01777 /tmp
+ ;;
+[Nn][Oo])
+ ;;
+*)
+ 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} /tmp
+ chmod 01777 /tmp
+ fi
+ fi
+ ;;
+esac
--- /dev/null Fri Mar 5 16:33:00 2004
+++ etc/rc.d/var Fri Mar 5 16:06:12 2004
@@ -0,0 +1,97 @@
+#!/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: src/etc/rc.d/diskless,v 1.30 2004/01/05 19:14:47 brooks Exp $
+#
+
+# PROVIDE: var
+# REQUIRE: mountcritlocal
+# KEYWORD: FreeBSD
+
+. /etc/rc.subr
+
+name="var"
+
+load_rc_config $name
+
+_populate_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 / > /dev/null
+ ;;
+ esac
+
+ /usr/sbin/newsyslog -CC
+
+ /usr/bin/touch /var/log/lastlog
+
+ # XXX: should create spool dirs for lpd
+}
+
+# If we do not have a writable /var, create a memory filesystem for /var
+# unless told otherwise by rc.conf. 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.
+#
+case "${varmfs}" in
+[Yy][Ee][Ss])
+ mount_md ${varsize} /var
+ ;;
+[Nn][Oo])
+ ;;
+*)
+ if (/bin/mkdir /var/.diskless 2> /dev/null); then
+ rmdir /var/.diskless
+ else
+ mount_md ${varsize} /var
+ fi
+esac
+
+
+# If we have an empty looking /var, populate it, but only if we have
+# /usr available. Hopefully, we'll eventually find a workaround, but
+# in realistic diskless setups, we're probably ok.
+case "${populate_var}" in
+[Yy][Ee][Ss])
+ _populate_var
+ ;;
+[Nn][Oo])
+ ;;
+*)
+ if [ -d /var/run -a -d /var/db -a -d /var/empty ] ; then
+ true
+ elif [ ! -x /usr/sbin/mtree -o ! -x /usr/sbin/newsyslog -o \
+ ! -x /usr/bin/touch ] ; then
+ false
+ else
+ _populate_var
+ fi
+ ;;
+esac
--
Any statement of the form "X is the one, true Y" is FALSE.
PGP fingerprint 655D 519C 26A7 82E7 2529 9BF0 5D8E 8BE9 F238 1AD4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20040305/5ee6dae5/attachment.bin
More information about the freebsd-arch
mailing list