Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Jan 2004 21:49:19 +0100
From:      Poul-Henning Kamp <phk@phk.freebsd.dk>
To:        current@freebsd.org
Subject:   REVIEW: cleanvar.patch
Message-ID:  <98643.1074545359@critter.freebsd.dk>

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


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
@@ -7,6 +7,12 @@
 # REQUIRE: mountcritlocal
 # KEYWORD: FreeBSD
 
+. /etc/rc.subr
+
+name="cleanvar"
+
+load_rc_config $name
+
 purgedir()
 {
 	local dir file
@@ -31,6 +37,46 @@
 		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@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.



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