User Tools

Site Tools


acdsn:tmpfs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
acdsn:tmpfs [2012/08/21 19:37] – created sbolayacdsn:tmpfs [2013/07/24 12:51] (current) – [/etc/init.d/tmpfs] jzaehrin
Line 3: Line 3:
 inspired from http://forums.debian.net/viewtopic.php?t=16450 inspired from http://forums.debian.net/viewtopic.php?t=16450
  
-/etc/default/tmpfs+===== /etc/default/tmpfs =====
 <code bash> <code bash>
 # Where to mount the DIRS # Where to mount the DIRS
Line 31: Line 31:
 # Leave empty to unset # Leave empty to unset
 #QUIET="" #QUIET=""
 +</code>
 +
 +===== /etc/init.d/tmpfs =====
 +<code bash>
 +#! /bin/sh
 +### BEGIN INIT INFO
 +# Provides:          tmpfs       
 +# Required-Start:    mountall
 +# Required-Stop:    
 +# Default-Start:     
 +# Default-Stop:      
 +# Short-Description: Mount directories in tmpfs
 +# Description: This initscript can bind directories in a tmpfs ramdisk, the
 +#              primary goal is to allow laptop users to let the hard-disk
 +#              drive spin up most of the time, it can also be used by people
 +#              having their system on a USB disk or a CF card.
 +# Author: Mathias Laurin
 +# License: GNU General Public License version 2 or higher
 +# Version: 1.0.4
 +# update-rc.d tmpfs defaults 10 
 +# update-rc.d tmpfs enable 2
 +### END INIT INFO
 +
 +PATH=/sbin:/bin
 +NAME="tmpfs"
 +
 +. /lib/init/vars.sh
 +. /lib/lsb/init-functions
 +
 +# Source tmpfs before $NAME so that SHM_SIZE gets overwritten
 +[ -e /etc/default/tmpfs ] && . /etc/default/tmpfs
 +[ -e /etc/default/$NAME ] && . /etc/default/$NAME
 +
 +# no directory to mount, exit graciously
 +[ -z "$DIRS" ] && exit 0
 +[ -n "$QUIET" ] && OPTS_TMPFS_QUIET="-n"
 +[ -z "MNT_TMPFS" ] && MNT_TMPFS="/dev/shm"
 +
 +# no /dev/shm, error and exit
 +[ ! -d "/dev/shm" ] && echo "Enable tmpfs in the kernel" >&2 && exit 1
 +
 +do_start() {
 +   # Prepare mount point
 +   [ ! -d "$MNT_TMPFS" ] && mkdir "$MNT_TMPFS"
 +   
 +   # Mount options
 +   MNT_OPTS=${MNT_OPTS:-"rw,nodev,nosuid"}
 +   [ -n "$SHM_SIZE" ] && MNT_OPTS="$MNT_OPTS",size=$SHM_SIZE
 +
 +   [ -n "$(grep $MNT_TMPFS /proc/mounts)" ] && umount "$MNT_TMPFS"
 +   
 +   mount -t tmpfs -o "$MNT_OPTS" tmpfs "$MNT_TMPFS"
 +   
 +   for MY_DIR in $DIRS; do
 +      MY_TMPFS="$MNT_TMPFS/$MY_DIR"
 +      [ ! -d "$MY_TMPFS" ] && mkdir -p "$MY_TMPFS"
 +
 +      mount --bind $OPTS_TMPFS_QUIET "$MY_TMPFS" "$MY_DIR" -o "$OPTS_TMPFS"
 +
 +      # special cases handled here, using "case" allows more flexibility
 +      case $MY_DIR in
 +         /tmp|/var/tmp)
 +         mount -o,remount,nodev,nosuid $MY_DIR
 +         chmod 1777 $MY_DIR
 +         ;;
 +         /var/log)
 +         touch /var/log/lastlog
 +         touch /var/log/wtmp
 +         chgrp utmp /var/log/lastlog
 +         chmod 0644 /var/log/lastlog
 +         chmod 0644 /var/log/wtmp
 +         chmod 0600 /var/log/btmp
 +         mkdir /var/log/news
 +         chown news:news /var/log/news
 +         chmod g+s /var/log/news
 +         [ -f /etc/init.d/mpd ] &&
 +         mkdir /var/log/mpd &&
 +         chown mpd:audio /var/log/mpd
 +         [-f /etc/init.d/ipw3945d ] &&
 +         mkdir /var/log/ipw3945d &&
 +         chown Debian-ipw3945d:Debian-ipw3945d /var/log/ipw3945d
 +         ;;
 +         /var/run)
 +         mount -o,remount,nodev,nosuid,noexec /var/run
 +         chmod 1777 /var/run
 +         [ ! -d /var/run/screen ] && mkdir -m 0777 /var/run/screen
 +         touch /var/run/utmp
 +         chgrp utmp /var/run/utmp
 +         chmod 0644 /var/run/utmp
 +         ;;
 +      esac
 +   done
 +}
 +
 +case "$1" in
 +  start|"")
 +   do_start
 +   ;;
 +  restart|reload|force-reload)
 +   echo "Error: argument '$1' not supported" >&2
 +   exit 3
 +   ;;
 +  stop)
 +   # No-op
 +   ;;
 +  *)
 +   echo "Usage: my-tmpfs.sh [start|stop]" >&2
 +   exit 3
 +   ;;
 +esac
 +
 +:
 +</code>
 +
 +and update all with:
 +
 +    # chmod a+x /etc/init.d/tmpfs
 +    # update-rc.d tmpfs defaults
 +
 +
 +
 +===== mount =====
 +The original fs is like:
 +<code bash>
 +/dev/mmcblk0p2 on / type ext4 (rw,noatime)
 +tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
 +proc on /proc type proc (rw,noexec,nosuid,nodev)
 +sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
 +udev on /dev type tmpfs (rw,mode=0755)
 +tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
 +devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
 +/dev/mmcblk0p1 on /media/mmc_p1 type vfat (rw,noatime)
 +/dev/mmcblk0p3 on /media/data type ext4 (rw,noatime)
 +</code>
 +
 +and finally you obtain
 +
 +<code bash>
 +/dev/mmcblk0p2 on / type ext4 (rw,noatime)
 +tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
 +proc on /proc type proc (rw,noexec,nosuid,nodev)
 +sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
 +udev on /dev type tmpfs (rw,mode=0755)
 +devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
 +/dev/mmcblk0p1 on /media/mmc_p1 type vfat (rw,noatime)
 +/dev/mmcblk0p3 on /media/data type ext4 (rw,noatime)
 +tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
 +/dev/shm/tmp on /tmp type none (rw,noexec,nosuid,nodev,bind)
 +/dev/shm/var/log on /var/log type none (rw,noexec,nodev,bind)
 +/dev/shm/var/run on /var/run type none (rw,noexec,nosuid,nodev,bind)
 +/dev/shm/var/lock on /var/lock type none (rw,noexec,nodev,bind)
 </code> </code>
acdsn/tmpfs.1345577829.txt.gz · Last modified: 2012/08/21 19:37 by sbolay