<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 &lt;<a href="mailto:matt.hoosier@gmail.com">matt.hoosier@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Matt Hoosier &lt;<a href="mailto:matt.hoosier@garmin.com" target="_blank">matt.hoosier@garmin.com</a>&gt;<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&#39;s<br>
read-only-rootfs-hook in 370fda1b2e8d5dc011522131bba4106de26bfb19.<br>
<br>
Signed-off-by: Matt Hoosier &lt;<a href="mailto:matt.hoosier@gmail.com" target="_blank">matt.hoosier@gmail.com</a>&gt;<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 &quot;$options&quot; ] &amp;&amp; options=&quot;,$options&quot;<br>
<br>
 mkdir -p &quot;${spec%/*}&quot;<br>
+<br>
 if [ -d &quot;$mountpoint&quot; ]; then<br>
-    if [ ! -d &quot;$spec&quot; ]; then<br>
+<br>
+    if [ -d &quot;$spec&quot; ]; then<br>
+        specdir_existed=yes<br>
+    else<br>
+        specdir_existed=no<br>
         mkdir &quot;$spec&quot;<br>
-        cp -pPR &quot;$mountpoint&quot;/. &quot;$spec/&quot;<br>
+    fi<br>
+<br>
+    # Fast version of calculating `dirname ${spec}`/.`basename ${spec}`-work<br>
+    overlay_workdir=&quot;${spec%/*}/.${spec##*/}-work&quot;<br>
+    mkdir &quot;${overlay_workdir}&quot;<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=&quot;$mountpoint&quot;,upperdir=&quot;$spec&quot;,workdir=&quot;$overlay_workdir&quot; &quot;$mountpoint&quot; &gt; /dev/null 2&gt;&amp;1; then<br>
+<br>
+        if [ &quot;$specdir_existed&quot; != &quot;yes&quot; ]; then<br>
+            cp -pPR &quot;$mountpoint&quot;/. &quot;$spec/&quot;<br>
+        fi<br>
+<br>
+        mount -o &quot;bind$options&quot; &quot;$spec&quot; &quot;$mountpoint&quot;<br>
     fi<br>
 elif [ -f &quot;$mountpoint&quot; ]; then<br>
     if [ ! -f &quot;$spec&quot; ]; then<br>
         cp -pP &quot;$mountpoint&quot; &quot;$spec&quot;<br>
     fi<br>
-fi<br>
<br>
-mount -o &quot;bind$options&quot; &quot;$spec&quot; &quot;$mountpoint&quot;<br>
+    mount -o &quot;bind$options&quot; &quot;$spec&quot; &quot;$mountpoint&quot;<br>
+fi<br>
-- <br>
2.17.2<br>
<br>
</blockquote></div></div>