tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Creating /var/shm as a symlink during startup



I would like to commit the patch below.

It is usefull for memory restricted systems where you only want one tmpfs
(with a single, reasonable small limit) and want to share that tmpfs
for both /tmp and /var/shm.

With the patch, it is as easy as setting

	var_shm_symlink="/tmp/.shm"

in /etc/rc.conf and making /tmp a tmpfs in /etc/fstab.

Any objections? Better ideas?

Martin
Index: share/man/man5/rc.conf.5
===================================================================
RCS file: /cvsroot/src/share/man/man5/rc.conf.5,v
retrieving revision 1.163
diff -u -r1.163 rc.conf.5
--- share/man/man5/rc.conf.5	12 Oct 2015 12:07:24 -0000	1.163
+++ share/man/man5/rc.conf.5	6 Nov 2015 19:26:40 -0000
@@ -55,7 +55,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd October 9, 2015
+.Dd November 6, 2015
 .Dt RC.CONF 5
 .Os
 .Sh NAME
@@ -331,6 +331,13 @@
 Boolean value.
 Remove block-type swap devices at shutdown time.
 Useful if swapping onto RAIDframe devices.
+.It Sy var_shm_symlink
+A path.
+If set, names a path that /var/shm will be symlinked to.
+.Pp
+The path needs to live on a tmpfs file system.
+A typical value (assuming /tmp is mounted on tmpfs) would be
+.Pa /tmp/.shm .
 .El
 .Ss Block device subsystems
 .Bl -tag -width net_interfaces
Index: etc/rc.d/cleartmp
===================================================================
RCS file: /cvsroot/src/etc/rc.d/cleartmp,v
retrieving revision 1.12
diff -u -r1.12 cleartmp
--- etc/rc.d/cleartmp	3 Jul 2015 18:36:54 -0000	1.12
+++ etc/rc.d/cleartmp	6 Nov 2015 19:26:40 -0000
@@ -45,6 +45,14 @@
 	(cd ${tmp_dir} &&
 	    find -x . ! -name . ! -name lost+found ! -name quota.user \
 		! -name quota.group -exec rm -rf -- {} \+ -type d -prune)
+
+	# if requested, create symlink for /var/shm
+	if [ -n "${var_shm_symlink}" ]; then
+		rm -rf /var/shm
+		mkdir -p "${var_shm_symlink}"
+		chmod 1777 "${var_shm_symlink}"
+		ln -s "${var_shm_symlink}" /var/shm
+	fi
 }
 
 load_rc_config $name


Home | Main Index | Thread Index | Old Index