3 # Persistence enhancer script
4 # This script saves precious time on slow persistence devices/image files
5 # and writes on flash based device.
6 # a tmpfs on $PERSTMP is mounted and directories listed in
7 # /etc/live-persistence.binds will be copied there and then bind mounted back.
11 # initramfs-tools header
27 # live-initramfs header
29 if [ -z "${PERSISTENT}" ] || [ -n "${NOPERSISTENT}" ] || [ -z "${PERSISTENCE_IS_ON}" ] || [ ! -f /root/etc/live-persistence.binds ]
34 . /scripts/live-functions
36 # live-initramfs script
38 dirs="$(sed -e '/^ *$/d' -e '/^#.*$/d' /root/etc/live-persistence.binds | tr '\n' '\0')"
44 log_begin_msg "Moving persistence bind mounts"
46 PERSTMP="/root/live/persistence-binds"
49 if [ ! -d "${PERSTMP}" ]
54 mount -t tmpfs tmpfs "${PERSTMP}"
56 for dir in $(echo "${dirs}" | tr '\0' '\n')
58 if [ ! -e "/root/${dir}" ] && [ ! -L "/root/${dir}" ]
60 # directory do not exists, create it
61 mkdir -p "/root/${dir}"
62 elif [ ! -d "/root/${dir}" ]
64 # it is not a directory, skip it
68 # Copy previous content if any
70 find . -print0 | ${CPIO} -pumd0 "${PERSTMP}/${dir}"
73 # Bind mount it to origin
74 mount -o bind "${PERSTMP}/${dir}" "/root/${dir}"