Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Mar 2004 17:12:28 -0800
From:      Brooks Davis <brooks@one-eyed-alien.net>
To:        arch@freebsd.org
Subject:   rc.d/diskless overhaul
Message-ID:  <20040306011228.GC24617@Odin.AC.HMC.Edu>

next in thread | raw e-mail | index | archive | help

--Izn7cH1Com+I3R9J
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Please find attached, a patch to overhaul rc.d/diskless (the script
formerly know as rc.diskless2.) =20

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 =3D size
+#   $2 =3D mount point
+#   $3 =3D (optional) bytes-per-inode
+mount_md() {
+	if [ -n "$3" ]; then
+		bpi=3D"-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=3D"/etc/defaults/pccard.conf"	# pccardd(8) config file
 pccard_ether_delay=3D"5"	# Delay before trying to start dhclient in pccard=
_ether
 removable_interfaces=3D""	# Removable network interfaces for /etc/pccard_e=
ther.
+tmpmfs=3D"AUTO"		# Set to YES to always create an mfs /tmp, NO to never
+tmpsize=3D"20m"		# Size of mfs /tmp if created
+varmfs=3D"AUTO"		# Set to YES to always create an mfs /var, NO to never
+varsize=3D"32m"		# Size of mfs /var if created
+populate_var=3D"AUTO"	# Set to YES to always (re)populate /var, NO to never
 local_startup=3D"/usr/local/etc/rc.d /usr/X11R6/etc/rc.d" # startup script=
 dirs.
 script_name_sep=3D" "	# Change if your startup scripts' names contain spac=
es
 rc_conf_files=3D"/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 @@
 #
=20
 # PROVIDE: cleanvar
-# REQUIRE: mountcritlocal
+# REQUIRE: mountcritlocal var
 # KEYWORD: FreeBSD
=20
 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 @@
 #
=20
 # PROVIDE: cleartmp
-# REQUIRE: mountcritremote
+# REQUIRE: mountall tmp
 # BEFORE: DAEMON
 # KEYWORD: FreeBSD
=20
--- ../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`" !=3D "x" ]; then
+			hostname=3D`/bin/kenv dhcp.host-name`
+		fi
 	fi
=20
 	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.
=20
 dlv=3D`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
 [ ${dlv:=3D0} -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=3D`/bin/cat /conf/diskless_remount`
+    if [ `expr "$nfspt" : '\(.\)'` =3D "/" ]; then
+	nfspt=3D"${nfsroot}${nfspt}"
+    fi
+    mount_nfs $nfspt /conf
+    chkerr $? "mount_nfs $nfspt /conf"
+fi
=20
 # 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 PURPO=
SE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTI=
AL
+# 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, STRI=
CT
+# 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=3D"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`" !=3D "x" ]; then
+	/bin/cat /dev/null > /etc/resolv.conf
+
+	if [ "x`/bin/kenv dhcp.domain-name 2> /dev/null`" !=3D "x" ]; then
+		echo domain `/bin/kenv dhcp.domain-name` > /etc/resolv.conf
+	fi
+
+        set `/bin/kenv dhcp.domain-name-servers`
+        for ns in `IFS=3D','; 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 PURPO=
SE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTI=
AL
+# 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, STRI=
CT
+# 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=3D"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 PURPO=
SE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTI=
AL
+# 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, STRI=
CT
+# 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=3D"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



--=20
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

--Izn7cH1Com+I3R9J
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFASSV6XY6L6fI4GtQRAqTvAKCH2qpweaP+REr4HXgMDUs0Q9SVKwCg40o/
a7jUrsLwyoFur6ROchi6GV8=
=BYET
-----END PGP SIGNATURE-----

--Izn7cH1Com+I3R9J--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040306011228.GC24617>