Install live-bottom/08persistence_excludes
authorMichael Prokop <mika@grml.org>
Mon, 24 Nov 2008 09:21:57 +0000 (10:21 +0100)
committerMichael Prokop <mika@grml.org>
Mon, 24 Nov 2008 09:21:57 +0000 (10:21 +0100)
debian/changelog
debian/rules
grml/08persistence_excludes [new file with mode: 0755]

index de54535..c4bd134 100644 (file)
@@ -10,8 +10,11 @@ live-initramfs (1.139.1-4grml.03) unstable; urgency=low
     - Adding a panic message when we netboot and have no supported
       network device (Closes: #496684).
     - Add a warning message when no image can be found.
+  * Install script
+    /usr/share/initramfs-tools/scripts/live-bottom/08persistence_excludes
+    we now start using persitency features.
 
- -- Michael Prokop <mika@grml.org>  Mon, 24 Nov 2008 10:17:30 +0100
+ -- Michael Prokop <mika@grml.org>  Mon, 24 Nov 2008 10:21:07 +0100
 
 live-initramfs (1.139.1-4grml.02) unstable; urgency=low
 
index 55b12ba..82e9fbf 100755 (executable)
@@ -54,6 +54,8 @@ install: build
        mkdir ./debian/live-initramfs/usr/share/initramfs-tools/scripts/live-bottom/
        install -m 755 grml/05mountpoints \
          ./debian/live-initramfs/usr/share/initramfs-tools/scripts/live-bottom/05mountpoints
+       install -m 755 grml/08persistence_excludes \
+         ./debian/live-initramfs/usr/share/initramfs-tools/scripts/live-bottom/08persistence_excludes
 
        # Removing double files
        rm -f debian/live-initramfs/usr/share/doc/live-initramfs/COPYING
diff --git a/grml/08persistence_excludes b/grml/08persistence_excludes
new file mode 100755 (executable)
index 0000000..b7aac92
--- /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="$(sed -e '/^ *$/d' -e '/^#.*$/d' /root/etc/live-persistence.binds | 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