conf/98603: [PATCH] /etc/rc.d/ramdisk + ramdisk-own replacement

Olli Hauer ohauer at gmx.de
Tue Jun 6 15:16:34 PDT 2006


>Number:         98603
>Category:       conf
>Synopsis:       [PATCH] /etc/rc.d/ramdisk + ramdisk-own replacement
>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:   Tue Jun 06 22:00:34 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Olli Hauer
>Release:        FreeBSD 6.1-RELEASE i386
>Organization:
>Environment:
>Description:
Replacement for the following scripts:
- /etc/rc.d/ramdisk
- /etc/rc.d/ramdisk-own


I see the old scripts as workaround for md's in fstab, but there is no
dockumentation inside (I think only a handful people use them as they are).

The replacement covers both scripts in one with fault tolerance and give
example how to use it (extra paramter help). 
It also has the feature to create directorys before the owner or permissions 
are set, this is handy for example cvs-lock directoy or other things.


>How-To-Repeat:

>Fix:
--- ramdisk.orig	Mon Jun  5 20:05:09 2006
+++ ramdisk.sh	Tue Jun  6 23:09:40 2006
@@ -36,31 +36,110 @@
 name="ramdisk"
 stop_cmd="ramdisk_stop"
 start_cmd="ramdisk_start"
+help_cmd=ramdisk_help
+extra_commands="help"
 
 ramdisk_start()
 {
-	for unit in $ramdisk_units; do
+	for unit in ${ramdisk_units}; do
+		if [ -c /dev/md${unit} ]; then
+			echo "${0}: md${unit} exists, skipping"
+			continue
+		fi
+
 		eval mdoptions=\$ramdisk_${unit}_config
-		if [ "$mdoptions" = "${mdoptions##-t}" ]; then
-			echo "Type not specified for md$unit"
+
+		if [ "${mdoptions}" = "${mdoptions##-t}" ]; then
+			echo "Type not specified for md${unit}"
 			continue
 		fi
+
 		eval fsoptions=\$ramdisk_${unit}_newfs
+		eval owner=\$ramdisk_${unit}_owner
+		eval perms=\$ramdisk_${unit}_perms
+		eval mount=\$ramdisk_${unit}_mount
+		eval mdirs=\$ramdisk_${unit}_mkdir
+
+		echo "Configuring ramdisk /dev/md${unit}"
+
+		[ "X${mount}" != "X" ] && mkdir -p ${mount} > /dev/null 2>&1
+
+		mdconfig -a ${mdoptions} -u ${unit}
+		newfs ${fsoptions} /dev/md${unit}
+
+
+		[ "X${mount}" != "X" ] && mount /dev/md${unit} ${mount} 
+		[ "X${mdirs}" != "X" ] && for DIR in ${mdirs}; do mkdir -p ${mount}/${DIR}; done 
+		[ "X${owner}" != "X" ] && chown -R ${owner} ${mount}
+		[ "X${perms}" != "X" ] && chmod -R ${perms} ${mount} 
+
+		echo "---------------------------------------"
+		echo "unit     : ${unit}"
+		echo "mdoptions: ${mdoptions}"
+		echo "fsoptions: ${fsoptions}"
+		echo "owner    : ${owner}"
+		echo "perms    : ${perms}"
+		echo "mount    : ${mount}"
+		[ "X${mdirs}" != "X" ] && for DIR in ${mdirs}; do echo "mkdir    : ${mount}/${DIR}" ; done 
+		echo "---------------------------------------"
+		/bin/df -hi ${mount}
+		echo "---------------------------------------"
 
-		mdconfig -a $mdoptions -u $unit
-		newfs $fsoptions /dev/md$unit
 	done
 }
 
 ramdisk_stop()
 {
-	for unit in $ramdisk_units
-	do
-		if [ -c /dev/md$unit ]; then
-			umount -f /dev/md$unit > /dev/null 2>&1
-			mdconfig -d -u $unit
+	for unit in ${ramdisk_units}; do
+		if [ -c /dev/md${unit} ]; then
+			eval mount=\$ramdisk_${unit}_mount
+			[ "X${mount}" != "X" ]   && umount -f ${mount} > /dev/null 2>&1
+
+			umount -f /dev/md${unit} 	> /dev/null 2>&1
+			mdconfig -d -u ${unit}
+			echo Recovered ramdisk /dev/md${unit}
 		fi
 	done
+}
+
+
+ramdisk_help()
+{
+cat << _EOF
+
+#=======================================
+#  config sample in rc.conf
+#   see man mdconfig(8)
+#=======================================
+
+	ramdisk_enable="YES"'
+	ramdisk_units="10 11"
+
+	# -- ramdisk unit 10 configuration --
+
+	# 1: allocate from RAM (malloc)
+	ramdisk_10_config="-t malloc -s 128m"
+	
+	# 2: mountpoint
+	ramdisk_10_mount="/data/ncvs/CVSTMP"
+	
+	# 3: crate this folders inside the ramdisk
+	ramdisk_10_mkdir="tmp lock/Prj1 lock/Prj2"
+	
+	# 4: owner:group
+	ramdisk_10_owner="ncvs:ncvs"
+	
+	# 5: permissions
+	ramdisk_10_perms="1755"
+
+
+	# -- ramdisk unit 11 configuration --
+
+	# 1: allocate from swap 
+	ramdisk_11_config="-t swap -s 128m"
+	...
+
+_EOF
 }
 
 load_rc_config $name
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list