<div dir="ltr"><div class="gmail_quote"><div>Hi; any interest in this one?</div><div dir="ltr"><br></div><div dir="ltr">On Fri, Oct 19, 2018 at 11:04 AM Matt Hoosier <<a href="mailto:matt.hoosier@gmail.com">matt.hoosier@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Matt Hoosier <<a href="mailto:matt.hoosier@garmin.com" target="_blank">matt.hoosier@garmin.com</a>><br>
<br>
Copying files from the read-only root filesystem to the tmpfs<br>
providing the volatile directories can be slow and waste memory.<br>
If the kernel supports the overlay filesystem, use it to mount<br>
a writable tmpfs on top of the read-only directory from the<br>
rootfs and avoid copies.<br>
<br>
Analogous to the modification made to initscripts's<br>
read-only-rootfs-hook in 370fda1b2e8d5dc011522131bba4106de26bfb19.<br>
<br>
Signed-off-by: Matt Hoosier <<a href="mailto:matt.hoosier@gmail.com" target="_blank">matt.hoosier@gmail.com</a>><br>
---<br>
.../volatile-binds/files/mount-copybind | 30 ++++++++++++++++---<br>
1 file changed, 26 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/meta/recipes-core/volatile-binds/files/mount-copybind b/meta/recipes-core/volatile-binds/files/mount-copybind<br>
index 2aeaf84ddb..fddf520053 100755<br>
--- a/meta/recipes-core/volatile-binds/files/mount-copybind<br>
+++ b/meta/recipes-core/volatile-binds/files/mount-copybind<br>
@@ -8,7 +8,10 @@ if [ $# -lt 2 ]; then<br>
exit 1<br>
fi<br>
<br>
+# e.g. /var/volatile/lib<br>
spec=$1<br>
+<br>
+# e.g. /var/lib<br>
mountpoint=$2<br>
<br>
if [ $# -gt 2 ]; then<br>
@@ -20,15 +23,34 @@ fi<br>
[ -n "$options" ] && options=",$options"<br>
<br>
mkdir -p "${spec%/*}"<br>
+<br>
if [ -d "$mountpoint" ]; then<br>
- if [ ! -d "$spec" ]; then<br>
+<br>
+ if [ -d "$spec" ]; then<br>
+ specdir_existed=yes<br>
+ else<br>
+ specdir_existed=no<br>
mkdir "$spec"<br>
- cp -pPR "$mountpoint"/. "$spec/"<br>
+ fi<br>
+<br>
+ # Fast version of calculating `dirname ${spec}`/.`basename ${spec}`-work<br>
+ overlay_workdir="${spec%/*}/.${spec##*/}-work"<br>
+ mkdir "${overlay_workdir}"<br>
+<br>
+ # Try to mount using overlay, which is must faster than copying files.<br>
+ # If that fails, fall back to slower copy.<br>
+ if ! mount -t overlay overlay -olowerdir="$mountpoint",upperdir="$spec",workdir="$overlay_workdir" "$mountpoint" > /dev/null 2>&1; then<br>
+<br>
+ if [ "$specdir_existed" != "yes" ]; then<br>
+ cp -pPR "$mountpoint"/. "$spec/"<br>
+ fi<br>
+<br>
+ mount -o "bind$options" "$spec" "$mountpoint"<br>
fi<br>
elif [ -f "$mountpoint" ]; then<br>
if [ ! -f "$spec" ]; then<br>
cp -pP "$mountpoint" "$spec"<br>
fi<br>
-fi<br>
<br>
-mount -o "bind$options" "$spec" "$mountpoint"<br>
+ mount -o "bind$options" "$spec" "$mountpoint"<br>
+fi<br>
-- <br>
2.17.2<br>
<br>
</blockquote></div></div>