From owner-freebsd-current@FreeBSD.ORG Mon Jan 19 12:49:25 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AE1AB16A4CE for ; Mon, 19 Jan 2004 12:49:25 -0800 (PST) Received: from critter.freebsd.dk (critter.freebsd.dk [212.242.86.163]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0D4BB43D4C for ; Mon, 19 Jan 2004 12:49:20 -0800 (PST) (envelope-from phk@phk.freebsd.dk) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.12.10/8.12.10) with ESMTP id i0JKnJCf098644 for ; Mon, 19 Jan 2004 21:49:19 +0100 (CET) (envelope-from phk@phk.freebsd.dk) To: current@freebsd.org From: Poul-Henning Kamp Date: Mon, 19 Jan 2004 21:49:19 +0100 Message-ID: <98643.1074545359@critter.freebsd.dk> Subject: REVIEW: cleanvar.patch X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Jan 2004 20:49:25 -0000 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.