bin/51451: RC_NG Script for creating Memory Disks

Scot W. Hetzel hetzels at westbend.net
Sat Apr 26 17:20:14 PDT 2003


>Number:         51451
>Category:       bin
>Synopsis:       RC_NG Script for creating Memory Disks
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 26 17:20:12 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Scot W. Hetzel
>Release:        FreeBSD 5.0-CURRENT
>Organization:
West Bend Internet
>Environment:
System: FreeBSD WBIw009.westbend.net 4.8-STABLE FreeBSD 4.8-STABLE #2: Tue Apr 22 02:28:52 CDT 2003 root at WBIw009.westbend.net:/usr/obj/usr/src/4x/sys/GENERIC-SMP i386

>Description:
	I didn't find a RC_NG script on current that would create and
	mount the Memory Disks (/dev/md?).

>How-To-Repeat:
	Try to have the system create/mount a Memory Disk as it is booting.

>Fix:
	The attached patch allows you to create them.  For example by placing
	the following into rc.conf, You can creat the vnode, swap, or malloc
	Memory Disks.

	    memorydisk_enable="YES"
	    memorydisk_list="test0 test1 test2"

	    memorydisk_test0_type="vnode"
	    memorydisk_test0_file="/usr/test/file"
	    memorydisk_test0_mount="/usr/test0"

	    memorydisk_test1_type="swap"
	    memorydisk_test1_size="4m"
	    memorydisk_test1_mount="/usr/test1"

	    memorydisk_test2_type="malloc"
	    memorydisk_test2_size="5m"
	    memorydisk_test2_mount="/usr/test2"

	Depending on the setting of memorydisk_<name>_type will determine
	which additional variables will need to be set (*_file, or *_size).

Index: etc/defaults/rc.conf
===================================================================
RCS file: /home/ncvs/src/etc/defaults/rc.conf,v
retrieving revision 1.172
diff -u -r1.172 rc.conf
--- etc/defaults/rc.conf	16 Apr 2003 16:29:51 -0000	1.172
+++ etc/defaults/rc.conf	26 Apr 2003 23:41:46 -0000
@@ -48,6 +48,16 @@
 extra_netfs_types="NO"	# List of network extra filesystem types for delayed
 			# mount at startup (or NO).
 
+memorydisk_enable="NO"	# Enable Memory Disks
+memorydisk_list=""	# List of Memory Disks to create
+
+# for each named Memory Disk in mdfile_list, create an entry with these variables:
+#
+# memorydisk_<name>_type    - swap, malloc, vnode
+# memorydisk_<name>_file    - required by vnode only
+# memorydisk_<name>_size    - required by swap/malloc only
+# memorydisk_<name>_mount   - mount point for mdfile (optional?)
+
 ##############################################################
 ###  Network configuration sub-section  ######################
 ##############################################################
Index: etc/rc.d/Makefile
===================================================================
RCS file: /home/ncvs/src/etc/rc.d/Makefile,v
retrieving revision 1.15
diff -u -r1.15 Makefile
--- etc/rc.d/Makefile	24 Apr 2003 08:20:47 -0000	1.15
+++ etc/rc.d/Makefile	26 Apr 2003 23:16:55 -0000
@@ -8,7 +8,7 @@
 	cleartmp cron devd devdb devfs dhclient diskless dmesg dumpon fsck \
 	hostname inetd initdiskless initrandom ip6fw ipfilter ipfs ipfw ipmon \
 	ipnat ipsec ipxrouted isdnd jail kadmind kerberos keyserv kldxref \
-	ldconfig local localdaemons lomac lpd motd mountcritlocal mountcritremote \
+	ldconfig local localdaemons lomac lpd memorydisk motd mountcritlocal mountcritremote \
 	mountd moused mroute6d mrouted msgs named netif network1 network2 network3 \
 	network_ipv6 nfsclient nfsd nfslocking nfsserver nisdomain ntpd \
 	ntpdate othermta pccard pcvt ppp-user pppoed pwcheck quota random \
Index: etc/rc.d/memorydisk
===================================================================
RCS file: etc/rc.d/memorydisk
diff -N etc/rc.d/memorydisk
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ etc/rc.d/memorydisk	26 Apr 2003 23:45:15 -0000
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+
+# PROVIDE: memorydisk
+# REQUIRE: NETWORKING root mountcritlocal
+# KEYWORD: FreeBSD
+
+. /etc/rc.subr
+
+name="memorydisk"
+rcvar=`set_rcvar`
+start_cmd="memorydisk_start"
+stop_cmd=":"
+
+memorydisk_start()
+{
+	for _md_name in ${memorydisk_list}
+	do
+		eval md_type=\"\$memorydisk_${_md_name}_type\"
+		eval md_file=\"\$memorydisk_${_md_name}_file\"
+		eval md_size=\"\$memorydisk_${_md_name}_size\"
+		eval md_mount=\"\$memorydisk_${_md_name}_mount\"
+
+		case "${md_type}" in
+			swap|malloc)
+				if [ -n "${md_size}" -a -c /dev/mdctl ]; then
+					mdev=`mdconfig -a -t ${md_type} -s ${md_size}`
+					[ -n "${md_mount}" ] && newfs -U /dev/${mdev}
+				fi
+				;;
+
+			vnode)
+				if [ -w "${md_file}" -a -c /dev/mdctl ]; then
+					mdev=`mdconfig -a -t vnode -f ${md_file}`
+				fi
+				;;
+			*)
+				;;
+		esac
+
+		[ -n "${md_mount}" -a -d ${md_mount} ] && mount /dev/${mdev} ${md_mount}
+	done
+}
+
+load_rc_config $name
+run_rc_command "$1"
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list