diff options
author | Matt Hoosier <matt.hoosier@garmin.com> | 2018-10-19 11:04:55 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-10-20 22:40:16 +0100 |
commit | c4acf1b531843497297c492456daea1744400faa (patch) | |
tree | e2e48d69e36c74ff31c54d0efbecd92121e53f86 /meta/recipes-core | |
parent | ef2824e872ea2900e6a59f8035323e4e890650f3 (diff) | |
download | poky-c4acf1b531843497297c492456daea1744400faa.tar.gz |
volatile-binds: use overlayfs if available
Copying files from the read-only root filesystem to the tmpfs
providing the volatile directories can be slow and waste memory.
If the kernel supports the overlay filesystem, use it to mount
a writable tmpfs on top of the read-only directory from the
rootfs and avoid copies.
Analogous to the modification made to initscripts's
read-only-rootfs-hook in 370fda1b2e8d5dc011522131bba4106de26bfb19.
(From OE-Core rev: b4976f3cf8cd028f165100b67867adb862da4d7f)
Signed-off-by: Matt Hoosier <matt.hoosier@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-core')
-rwxr-xr-x | meta/recipes-core/volatile-binds/files/mount-copybind | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/meta/recipes-core/volatile-binds/files/mount-copybind b/meta/recipes-core/volatile-binds/files/mount-copybind index 2aeaf84ddb..fddf520053 100755 --- a/meta/recipes-core/volatile-binds/files/mount-copybind +++ b/meta/recipes-core/volatile-binds/files/mount-copybind | |||
@@ -8,7 +8,10 @@ if [ $# -lt 2 ]; then | |||
8 | exit 1 | 8 | exit 1 |
9 | fi | 9 | fi |
10 | 10 | ||
11 | # e.g. /var/volatile/lib | ||
11 | spec=$1 | 12 | spec=$1 |
13 | |||
14 | # e.g. /var/lib | ||
12 | mountpoint=$2 | 15 | mountpoint=$2 |
13 | 16 | ||
14 | if [ $# -gt 2 ]; then | 17 | if [ $# -gt 2 ]; then |
@@ -20,15 +23,34 @@ fi | |||
20 | [ -n "$options" ] && options=",$options" | 23 | [ -n "$options" ] && options=",$options" |
21 | 24 | ||
22 | mkdir -p "${spec%/*}" | 25 | mkdir -p "${spec%/*}" |
26 | |||
23 | if [ -d "$mountpoint" ]; then | 27 | if [ -d "$mountpoint" ]; then |
24 | if [ ! -d "$spec" ]; then | 28 | |
29 | if [ -d "$spec" ]; then | ||
30 | specdir_existed=yes | ||
31 | else | ||
32 | specdir_existed=no | ||
25 | mkdir "$spec" | 33 | mkdir "$spec" |
26 | cp -pPR "$mountpoint"/. "$spec/" | 34 | fi |
35 | |||
36 | # Fast version of calculating `dirname ${spec}`/.`basename ${spec}`-work | ||
37 | overlay_workdir="${spec%/*}/.${spec##*/}-work" | ||
38 | mkdir "${overlay_workdir}" | ||
39 | |||
40 | # Try to mount using overlay, which is must faster than copying files. | ||
41 | # If that fails, fall back to slower copy. | ||
42 | if ! mount -t overlay overlay -olowerdir="$mountpoint",upperdir="$spec",workdir="$overlay_workdir" "$mountpoint" > /dev/null 2>&1; then | ||
43 | |||
44 | if [ "$specdir_existed" != "yes" ]; then | ||
45 | cp -pPR "$mountpoint"/. "$spec/" | ||
46 | fi | ||
47 | |||
48 | mount -o "bind$options" "$spec" "$mountpoint" | ||
27 | fi | 49 | fi |
28 | elif [ -f "$mountpoint" ]; then | 50 | elif [ -f "$mountpoint" ]; then |
29 | if [ ! -f "$spec" ]; then | 51 | if [ ! -f "$spec" ]; then |
30 | cp -pP "$mountpoint" "$spec" | 52 | cp -pP "$mountpoint" "$spec" |
31 | fi | 53 | fi |
32 | fi | ||
33 | 54 | ||
34 | mount -o "bind$options" "$spec" "$mountpoint" | 55 | mount -o "bind$options" "$spec" "$mountpoint" |
56 | fi | ||