How does overlayfs determine what folders to merge and what folders to replace
<p>How does <code>overlayfs</code> determine what folders to merge and what folders to replace?</p>

<pre class="lang-none prettyprint-override"><code>Tree:
  -lower
    -dir1
      -file1
  -upper
  -work
  -ready
</code></pre>

<p>Mount command:</p>



<pre class="lang-sh prettyprint-override"><code>mount -t overlay -o lowerdir=lower,upperdir=upper,workdir=work overlayfs ready
</code></pre>

<p>Case 1(merge):</p>

<pre class="lang-sh prettyprint-override"><code>cd ready/dir1
echo "newFile"&gt;newFile
#New file placed at upper/dir1/newFile.
#Then remount overlayfs, and we see both files in ready dir
</code></pre>

<p>Case 2(replace):</p>

<pre class="lang-sh prettyprint-override"><code>cd ready
rm dir1 -Rf
mkdir dir1
cd dir1
echo "newFile"&gt;newFile
# newFile placed at upper dir also
# Unmount/Remount overlayfs and we see only newFile
</code></pre>