blob: b7aac9226e309ba75ed23bfba1ffbd8d1994ecba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
|