REVIEW: cleanvar.patch

From: Poul-Henning Kamp <phk_at_phk.freebsd.dk>
Date: Mon, 19 Jan 2004 21:49:19 +0100
This patch adds code which detects an read-only /var and puts
a MD(4) disk on it in that case.

This is really a move of some diskless specific code to the
more general use of read-only rootfs systems.

Poul-Henning

Index: etc/rc.d/cleanvar
===================================================================
RCS file: /home/ncvs/src/etc/rc.d/cleanvar,v
retrieving revision 1.5
diff -u -r1.5 cleanvar
--- etc/rc.d/cleanvar	14 Jul 2003 13:02:36 -0000	1.5
+++ etc/rc.d/cleanvar	9 Oct 2003 13:21:56 -0000
_at__at_ -7,6 +7,12 _at__at_
 # REQUIRE: mountcritlocal
 # KEYWORD: FreeBSD
 
+. /etc/rc.subr
+
+name="cleanvar"
+
+load_rc_config $name
+
 purgedir()
 {
 	local dir file
_at__at_ -31,6 +37,46 _at__at_
 		done
 	fi
 }
+
+# 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
+}
+
+# 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
+	mkdir -p /var
+	mount_md ${varsize:=32m} /var
+fi
+
+# Populate /var if it looks empty
+if [ -d /var/run -a -d /var/db -a -d /var/empty ] ; then
+	true
+else
+	/usr/sbin/mtree -deU -f /etc/mtree/BSD.var.dist -p /var > /dev/null 2>&1
+	LOGFILES=`/usr/bin/awk '$1 != "#" { printf "%s ", $1 } ' /etc/newsyslog.conf`
+	if [ -n "$LOGFILES" ]; then
+		/usr/bin/touch $LOGFILES
+	fi
+	/usr/bin/touch /var/log/lastlog
+
+fi
 
 # These files must be removed only the first time this script is run
 # on boot.
-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk_at_FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
Received on Mon Jan 19 2004 - 11:49:25 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:39 UTC