Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Mar 2001 16:51:18 +0900
From:      Makoto MATSUSHITA <matusita@jp.FreeBSD.org>
To:        current@FreeBSD.ORG
Subject:   Re: swap-backed md-based /tmp to replace mfs-based one
Message-ID:  <20010313165118S.matusita@jp.FreeBSD.org>
In-Reply-To: <20010311151109.A69412@mollari.cthul.hu>
References:  <20010312.062914.92581299.ume@mahoroba.org> <20010312.062914.92581299.ume@mahoroba.org> <20010311151109.A69412@mollari.cthul.hu>

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

kris> We really need to provide a better rc.conf hook for doing this --
kris> expecting people to write their own script just to create a /tmp
kris> is lame.

Here is just an example script (CAUTION: not well-tested) to create a
filesystem/swap with mdconfig(8). This script support not only '/tmp
by mdconfig(8)', but also replaces 'swapfile' variable of rc.conf with
more generic way.

Sorry no diffs for rc.conf(5) nor any comments of this script, but
seeing is believing:)

-- -
Makoto `MAR' MATSUSHITA

#!/bin/sh
#
# mdconfig(8) knob for /etc/rc
#
# Example:
#	mdconfig_filesystems='tmp swap'
#
#	mdconfig_tmp_type='swap'
#	mdconfig_tmp_size='32M'
#	mdconfig_tmp_newfs_enable='YES'
#	mdconfig_tmp_newfs_flags=''
#	mdconfig_tmp_tunefs_enable='YES'
#	mdconfig_tmp_tunefs_flags='-n enable'
#	mdconfig_tmp_dir='/tmp'
#	mdconfig_tmp_mode='1777'
#	mdconfig_tmp_owner='root:wheel'
#
#	mdconfig_swap_type="vnode"
#	mdconfig_swap_file="/swapfile"
#	mdconfig_swap_dir="swap"
#
# Note:
#	- No support of 'mdconfig -u unit'.
#	- No error checking of mdconfig(8).
#

for mdfs in ${mdconfig_filesystems}; do
	eval _type=\$mdconfig_${mdfs}_type
	eval _size=\$mdconfig_${mdfs}_size
	eval _file=\$mdconfig_${mdfs}_file
	eval _flags=\$mdconfig_${mdfs}_flags
	eval _newfs_enable=\$mdconfig_${mdfs}_newfs_enable
	eval _newfs_flags=\$mdconfig_${mdfs}_newfs_flags
	eval _tunefs_enable=\$mdconfig_${mdfs}_tunefs_enable
	eval _tunefs_flags=\$mdconfig_${mdfs}_tunefs_flags
	eval _dir=\$mdconfig_${mdfs}_dir
	eval _mode=\$mdconfig_${mdfs}_mode
	eval _owner=\$mdconfig_${mdfs}_owner

	case ${_type} in
	[Ss][Ww][Aa][Pp])
		_args="-t swap -s ${_size}"
		;;
	[Vv][Nn][Oo][Dd][Ee])
		_args="-t vnode -f ${_file}"
		;;
	[Mm][Aa][Ll][Ll][Oo][Cc])
		_args="-t malloc -s ${size}"
		;;
	esac

	_mddev=`mdconfig -a ${_args} ${_flags}`

	case ${_newfs_enable} in
	[Yy][Ee][Ss])
		disklabel -r -w ${_mddev} auto
		newfs ${_newfs_flags} /dev/${_mddev}c >/dev/null 2>&1
		;;
	*)
		;;
	esac

	case ${_tunefs_enable} in
	[Yy][Ee][Ss])
		tunefs ${_tunefs_flags} /dev/${_mddev}c >/dev/null 2>&1
		;;
	*)
		;;
	esac
	
	case ${_dir} in
	[Ss][Ww][Aa][Pp])
		swapon /dev/${_mddev}
		;;
	*)
		if [ ! -d ${_dir} ]; then
			mkdir -p ${_dir}
		fi

		mount /dev/${_mddev}c ${_dir}

		if [ -n "${_mode}" ]; then
			chmod ${_mode} ${_dir}
		fi
		if [ -n "${_owner}" ]; then
			chown ${_owner} ${_dir}
		fi
		;;
	esac
done

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




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