[Pkg-sysvinit-devel] Bug#430814: Mount a tmpfs on /tmp if /tmp is too small

Ian Jackson iwj at ubuntu.com
Wed Jun 27 12:59:17 UTC 2007


Package: sysvinit
Version: 2.86.ds1-14.1
Severity: wishlist
Tags: patch

The attached patch arranges that at boot time, if /tmp (or whatever is
mounted there) has less than a certain amount of free space, a tmpfs
will be mounted over the top.  This makes some parts of the system
more robust in the face of disk full situations; in Ubuntu we are
deploying this pursuant to our plan
https://wiki.ubuntu.com/BootLoginWithFullFilesystem).

In the patch below:
 * The trigger size is 1Mby by default but configurable in
   /etc/default/mountoverflowtmp by setting MINTMPKB.  Setting
   this value to 0 disables the setup.
 * The tmpfs is always 1Mby.  Alternatively one might take the
   view that this size should be configurable or perhaps it should be
   the same as the minimum space.

Note that you might want to consider different defaults for Debian
than for Ubuntu.

Ian.

#! /bin/sh /usr/share/dpatch/dpatch-run
## 92_mountoverflowtmp.dpatch by Ian Jackson
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Mount a 1Mby tmpfs on /tmp if /tmp is otherwise less than 1Mby

@DPATCH@
--- ./debian/initscripts/postinst	2007-06-27 11:26:19.000000000 +0100
+++ edit/sysvinit-2.86.ds1/debian/initscripts/postinst	2007-06-27 11:38:05.000000000 +0100
@@ -102,6 +102,7 @@
 updatercd checkfs.sh             start 30 S .
 updatercd mountall.sh            start 35 S .
 updatercd mountall-bootclean.sh  start 36 S .
+updatercd mountoverflowtmp       start 37 S . stop 59 0 6 .
 updatercd waitnfs.sh             start 45 S .
 updatercd mountnfs-bootclean.sh  start 46 S .
 updatercd bootmisc.sh            start 80 S .
--- ./debian/initscripts/conffiles	2007-06-27 11:26:19.000000000 +0100
+++ edit/sysvinit-2.86.ds1/debian/initscripts/conffiles	2007-06-27 11:31:27.000000000 +0100
@@ -11,6 +11,7 @@
 /etc/init.d/mountall.sh
 /etc/init.d/mountall-bootclean.sh
 /etc/init.d/mountnfs-bootclean.sh
+/etc/init.d/mountoverflowtmp
 /etc/init.d/mountdevsubfs.sh
 /etc/init.d/mountkernfs.sh
 /etc/init.d/mtab.sh
--- ./debian/initscripts/etc/init.d/mountoverflowtmp	1970-01-01 01:00:00.000000000 +0100
+++ edit/sysvinit-2.86.ds1/debian/initscripts/etc/init.d/mountoverflowtmp	2007-06-27 11:29:46.000000000 +0100
@@ -0,0 +1,53 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides:          mountoverflowtmp
+# Required-Start:    mountall-bootclean
+# Required-Stop:
+# Default-Start:     S
+# Default-Stop:
+# Short-Description: mount emergency /tmp.
+# Description:       Mount a tmpfs on /tmp if there would
+#                    otherwise be too little space to log in.
+### END INIT INFO
+
+. /lib/lsb/init-functions
+
+set -e
+
+defs=/etc/default/mountoverflowtmp
+test ! -f "$defs" || . "$defs"
+
+: ${MINTMPKB:=1024}
+if test "$MINTMPKB" = "0"; then exit 0; fi
+
+case "$1" in
+  start|"")
+	log_action_begin_msg "Checking minimum space in /tmp"
+	df="`df -kP /tmp`"
+	avail="`printf "%s" "$df" | awk 'NR==2 { print $4 }'`"
+	log_action_end_msg 0
+	if test $avail -lt "$MINTMPKB"; then
+		log_action_begin_msg "Mounting emergency tmpfs on /tmp"
+		mount -t tmpfs -o size=1048576,mode=1777 overflow /tmp
+		log_action_end_msg 0
+	fi
+	;;
+  restart|reload|force-reload)
+	echo "Error: argument '$1' not supported" >&2
+	exit 3
+	;;
+  stop)
+	log_action_begin_msg "Unmounting any overflow tmpfs from /tmp"
+	if LANG=C LC_ALL=C mount | \
+		grep '^overflow on /tmp type tmpfs' >/dev/null; then
+		umount overflow
+	fi
+	log_action_end_msg 0
+	;;
+  *)
+	echo "Usage: mountoverflowtmp [start|stop]" >&2
+	exit 3
+	;;
+esac
+
+:




More information about the Pkg-sysvinit-devel mailing list