Subject: Re: towards a NetBSD LiveCD: /etc/rc.d/mountcritmem
To: None <tech-install@netbsd.org>
From: David Young <dyoung@pobox.com>
List: tech-install
Date: 12/02/2005 20:00:10
--TB36FDmn/VVEgNH/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Oops, here is the attachment.

Dave

-- 
David Young             OJC Technologies
dyoung@ojctech.com      Urbana, IL * (217) 278-3933

--TB36FDmn/VVEgNH/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=mountcritmem

#!/bin/sh
#
# $NetBSD$
# $Id: mountcritmem 3314 2005-06-26 05:01:59Z dyoung $
#

# PROVIDE: mountcritmem
# REQUIRE: root
# BEFORE: mountcritlocal

$_rc_subr_loaded . /etc/rc.subr

name="mountcritmem"
required_dirs="/mfs /permanent $critical_filesystems_memory"

for _d in $critical_filesystems_memory; do
	d=${_d#/}
	required_dirs="$required_dirs /permanent/$d"
done

start_cmd="mountcritmem_start"
stop_cmd="mountcritmem_stop"

#
# Example /etc/fstab
#
# /dev/wd0a / ffs ro 0 0
# swap /mfs mfs rw,-s=10880k,-i=256 0 0

abort_mountcritmem()
{
	if [ "$autoboot" = yes ]; then
		echo "ERROR: ABORTING BOOT (sending SIGTERM to parent)!"
		kill -TERM $$
		exit 1
	fi
}

mountcritmem_start()
{
	echo "Mounting critical memory filesystems"
	_fs_list=
	for _d in $critical_filesystems_memory; do
		d=${_d#/}
		_fs_list="$_fs_list $d"
	done
	for d in $_fs_list; do
		if [ ! -d /permanent/$d ]; then
			echo "ERROR: missing /permanent/$d"
			abort_mountcritmem
			return 1
		fi
	done

	for d in $_fs_list; do
		if ! mount /mfs; then
			echo "ERROR: cannot mount /mfs"
			abort_mountcritmem
			return 1
		fi
		break
	done

	for d in $_fs_list; do
		if ! mkdir /mfs/$d; then
			echo "ERROR: cannot mkdir /mfs/$d"
			abort_mountcritmem
			return 1
		fi
	done

	for d in $_fs_list; do
		if ! mount -t null /$d /permanent/$d; then
			echo "ERROR: cannot mount /permanent/$d"
			abort_mountcritmem
			return 1
		fi
	done

	for d in $_fs_list; do
		cd /permanent/$d
		if ! mount -t null /mfs/$d /$d; then
			echo "ERROR: cannot mount /mfs/$d"
			abort_mountcritmem
			return 1
		fi
		if ! pax -pe -rw . /$d ; then
			echo "ERROR: cannot populate /mfs/$d"
			abort_mountcritmem
			return 1
		fi
		cd -
	done
}

mountcritmem_stop()
{
	_rev_fs_list=
	for _d in $critical_filesystems_memory; do
		d=${_d#/}
		_rev_fs_list="$d $_rev_fs_list"
	done
	for d in $_rev_fs_list; do
		umount /mfs/$d
		umount /permanent/$d
	done
	for d in $_rev_fs_list; do
		umount /mfs
		break
	done
}

load_rc_config $name
run_rc_command "$1"

--TB36FDmn/VVEgNH/--