Implemented a persistence exclude list.
authorMarco Amadori <marco.amadori@gmail.com>
Sat, 27 Sep 2008 22:51:04 +0000 (00:51 +0200)
committerDaniel Baumann <daniel@debian.org>
Wed, 9 Mar 2011 16:48:02 +0000 (17:48 +0100)
* This finally enables one of the most requested feature to exclude
  things like disk caches and temporary files from the persistence
  images in order to speed things up and saves precious writes of flash
  based storages.
  This works at boot by bind mounting tmpfs clones of paths listed on
  "/etc/live-persistence.binds".

conf/live-persistence.binds [new file with mode: 0644]
debian/changelog
manpages/live-initramfs.en.7.txt
scripts/live
scripts/live-bottom/08persistence_excludes [new file with mode: 0755]

diff --git a/conf/live-persistence.binds b/conf/live-persistence.binds
new file mode 100644 (file)
index 0000000..b2c3833
--- /dev/null
@@ -0,0 +1,15 @@
+# /etc/live-persistence.binds example
+#
+# If this file is present in the proper path, each uncommented not empty line
+# will be treated as a directory which should not be made persistent and
+# which it's content should be volatile.
+#
+# This is achieved by bind mounting on it a tmpfs clone of the directory specified
+
+# Exclude some standard temporary paths
+/tmp
+/var/log
+/var/cache
+
+# Firefox profiles are not always useful to remember
+/root/.mozilla
index 4c59e5f..005786b 100644 (file)
@@ -1,3 +1,9 @@
+live-initramfs (1.139.1-3.1) unstable; urgency=low
+
+  * Non-maintainer upload.
+
+ -- Marco Amadori <marco.amadori@vdavda.com>  Mon, 29 Sep 2008 11:53:00 +0200
+
 live-initramfs (1.139.1-3) unstable; urgency=medium
 
   [ Chris Lamb ]
index f42a9ce..9766e21 100644 (file)
@@ -290,6 +290,11 @@ in this file will be the "lowest" point in the aufs, and the last file in
 this list will be on the "top" of the aufs, directly below /cow.  Without
 this file, any images in the "/live" directory are loaded in alphanumeric order.
 
+ /etc/live-persistence.binds
+
+This optional file, which resides in the rootfs system, not in the live media as above mentioned files, if exists will be used as a list of directories which not need to be persistent and which their content does not need to survive reboots. This is achieved by bind mounting for each directory listed there a tmpfs on the original path. This will permits to save precious writes and speed up operations for content like web caches and temporary files (like e.g.  /tmp and .mozilla) which are regenerated each time.
+
+
 See also
 --------
 
index 5be6fe2..0f4ef0d 100755 (executable)
@@ -1151,9 +1151,16 @@ setup_unionfs ()
                        # snapshots to be sure to really store some e.g key config files,
                        # but not on the same media
                        blacklistdev="${cowprobe}"
+                       PERSISTENCE_IS_ON="Yes"
+                       export PERSISTENCE_IS_ON
                fi
                # homecow just mount something on /home, this should be generalized some way
                homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
+               if [ -b "${homecow}" ]
+               then
+                       PERSISTENCE_IS_ON="Yes"
+                       export PERSISTENCE_IS_ON
+               fi
                root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
                # This second type should be removed when snapshot will get smarter,
                # hence when "/etc/live-snapshot*list" will be supported also by
diff --git a/scripts/live-bottom/08persistence_excludes b/scripts/live-bottom/08persistence_excludes
new file mode 100755 (executable)
index 0000000..bc5c4d8
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+# Persistence enhancer script
+# This script saves precious time on slow persistence devices/image files
+# and writes on flash based device.
+# a tmpfs on $PERSTMP is mounted and directories listed in
+# /etc/live-persistence.binds will be copied there and then bind mounted back.
+
+#set -e
+
+# initramfs-tools header
+
+PREREQ=""
+
+prereqs()
+{
+       echo "${PREREQ}"
+}
+
+case "${1}" in
+       prereqs)
+               prereqs
+               exit 0
+               ;;
+esac
+
+# live-initramfs header
+
+if [ -z "${PERSISTENT}" ] || [ -n "${NOPERSISTENT}" ] || [ -z "${PERSISTENCE_IS_ON}" ] || [ ! -f /root/etc/live-persistence.binds ]
+then
+       exit 0
+fi
+
+. /scripts/live-functions
+
+# live-initramfs script
+
+dirs="$(cat /root/etc/live-persistence.binds | grep -v '^#.*$' | grep -v '^ *$' | tr '\n' '\0')"
+if [ -z "${dirs}" ]
+then
+       exit 0
+fi
+
+log_begin_msg "Moving persistence bind mounts"
+
+PERSTMP="/root/live/persistence-binds"
+CPIO="/bin/cpio"
+
+if [ ! -d "${PERSTMP}" ]
+then
+       mkdir -p "${PERSTMP}"
+fi
+
+mount -t tmpfs tmpfs "${PERSTMP}"
+
+for dir in $(echo "${dirs}" | tr '\0' '\n')
+do
+       if [ ! -e "/root/${dir}" ] && [ ! -L "/root/${dir}" ]
+       then
+               # directory do not exists, create it
+               mkdir -p "/root/${dir}"
+       elif [ ! -d "/root/${dir}" ]
+       then
+               # it is not a directory, skip it
+               break
+       fi
+
+       # Copy previous content if any
+       cd "/root/${dir}"
+       find . -print0 | ${CPIO} -pumd0 "${PERSTMP}/${dir}"
+       cd "${OLDPWD}"
+
+       # Bind mount it to origin
+       mount -o bind "${PERSTMP}/${dir}" "/root/${dir}"
+done
+
+log_end_msg