<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>overlayfs &amp;mdash; Little Step</title>
    <link>https://rex.writeas.com/tag:overlayfs</link>
    <description></description>
    <pubDate>Sat, 09 May 2026 22:24:51 +0000</pubDate>
    <item>
      <title>Use Overlay Filesystem on Ubuntu</title>
      <link>https://rex.writeas.com/use-overlay-filesystem-on-ubuntu?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[How to use&#xA;How to disable&#xA;  Remount&#xA;  Use overlayroot-chroot&#xA;  Disable OverlayFS when booting&#xA;  Disable by overlayroot.conf&#xA;&#xA;a id=&#34;org08f1a6b&#34;/a&#xA;&#xA;How to use&#xA;&#xA;We have a device running Ubuntu and will be powered off directly without shutdown gracefully.&#xA;&#xA;In order to keep the file system from damage, we use the OverlayFS provided in Linux kernel since 3.18.&#xA;&#xA;The usage of OverlayFS is very simple, as following:&#xA;&#xA;first install overlayroot package&#xA;$ sudo apt-get install overlayroot&#xA;&#xA;second, change the config file /etc/overlayroot.conf&#xA;the simple config is as following&#xA;we enable swap, and disable recurse overlay&#xA;$ cat /etc/overlayroot.conf&#xA;overlayroot=&#34;tmpfs:swap=1,recurse=0&#34;&#xA;&#xA;After rebooting, we should see something like this:&#xA;&#xA;$ df -h&#xA;Filesystem              Size  Used Avail Use% Mounted on&#xA;udev                     16G  8.0K   16G   1% /dev&#xA;tmpfs                   3.1G   74M  3.1G   3% /run&#xA;/dev/sda3                96G   16G   76G  17% /media/root-ro&#xA;tmpfs-root               16G   60M   16G   1% /media/root-rw&#xA;overlayroot              16G   60M   16G   1% /&#xA;tmpfs                    16G   24K   16G   1% /dev/shm&#xA;tmpfs                   5.0M  4.0K  5.0M   1% /run/lock&#xA;tmpfs                    16G     0   16G   0% /sys/fs/cgroup&#xA;&#xA;$ mount&#xA;[...]&#xA;configfs on /sys/kernel/config type configfs (rw,relatime)&#xA;overlayroot on /var/cache/apt/archives type overlay (rw,relatime,lowerdir=/media/root-ro,upperdir=/media/root-rw/overlay,workdir=/media/root-rw/overlay-workdir/)&#xA;overlayroot on /opt/var/cache/apt/archives type overlay (rw,relatime,lowerdir=/media/root-ro,upperdir=/media/root-rw/overlay,workdir=/media/root-rw/overlay-workdir/)&#xA;overlayroot on /var/lib/apt/lists type overlay (rw,relatime,lowerdir=/media/root-ro,upperdir=/media/root-rw/overlay,workdir=/media/root-rw/overlay-workdir/)&#xA;overlayroot on /opt/var/lib/apt/lists type overlay (rw,relatime,lowerdir=/media/root-ro,upperdir=/media/root-rw/overlay,workdir=/media/root-rw/overlay-workdir/)&#xA;&#xA;a id=&#34;orgf9f1ab8&#34;/a&#xA;&#xA;How to disable&#xA;&#xA;When you change some file under OverlayFS, and after the reboot, the file will keep the same.&#xA;&#xA;But sometimes you do want to change the original file, how to disable this feature?&#xA;&#xA;We have these methods:&#xA;&#xA;Remount the disk with rw, and change the file under lowerdir&#xA;Use overlayroot-chroot tool provided by the package&#xA;Disable OverlayFS when booting&#xA;Disable by overlayroot.conf&#xA;&#xA;a id=&#34;orgdd61966&#34;/a&#xA;&#xA;Remount&#xA;&#xA;If you just want to change some files, this is very direct, remount the block device and change the file under lowerdir.&#xA;&#xA;remount with read-write&#xA;$ sudo mount -o remount,rw /dev/sda3&#xA;&#xA;say we want to change overlayroot.conf&#xA;note: we must change under the file under the lowerdir: /media/root-ro&#xA;$ sudo vim /media/root-ro/etc/overlayroot.conf&#xA;&#xA;remount with read-only&#xA;$ sudo mount -o remount,ro /dev/sda3&#xA;&#xA;a id=&#34;orgd65b959&#34;/a&#xA;&#xA;Use overlayroot-chroot&#xA;&#xA;If we want to install some package and keep the package after reboot, we can&#39;t use the first method, since the package may change many files under different directories.&#xA;&#xA;We still have a simple way, you run overlayroot-chroot with root, make changes, and the changes will be saved after reboot.&#xA;&#xA;$ sudo overlayroot-chroot&#xA;&#xA;The change may not take effect immediately after exit the command, you can mount again like this:&#xA;&#xA;$ sudo mount -o remount /&#xA;&#xA;a id=&#34;org5f572fb&#34;/a&#xA;&#xA;Disable OverlayFS when booting&#xA;&#xA;The overlayroot-chroot method may solve 90% of the problem, but it do has some limitation.&#xA;&#xA;The overlayroot-chroot just like chroot into the lower filesystem, and remount with writable.&#xA;&#xA;If you have some scripts-say postinstall in some package, checks the chroot mode, it may refuse to execute under this case.&#xA;&#xA;To fix this problem, we can disable OverlayFS during the booting phase.&#xA;&#xA;We can edit the boot command line, append overlayroot=disabled and boot again.&#xA;&#xA;  linux /vmlinuz-4.15.0-123-lowlatency root=UUID=bfb40993-3xxxx ro systemd.unit=multi-user.target overlayroot=disabled&#xA;&#xA;Under this case, the OverlayFS will be disabled completely.&#xA;&#xA;a id=&#34;orga277402&#34;/a&#xA;&#xA;Disable by overlayroot.conf&#xA;&#xA;We can disable OverlayFS during the boot time, but if we want to keep it disabled after several reboots, we have a simple way.&#xA;&#xA;You can change the overlayroot.conf config file using the remount method, and comment all the lines, and then reboot again.&#xA;&#xA;If we want to enable, we can remount and un-comment the config lines, and after reboot, the OverlayFS will be enabled agian.&#xA;&#xA;$ cat /media/root-ro/etc/overlayroot.conf&#xA;overlayroot=&#34;tmpfs:swap=1,recurse=0&#34;&#xA;&#xA;#overlayfs #linux]]&gt;</description>
      <content:encoded><![CDATA[<ul><li><a href="#org08f1a6b" rel="nofollow">How to use</a></li>
<li><a href="#orgf9f1ab8" rel="nofollow">How to disable</a>
<ul><li><a href="#orgdd61966" rel="nofollow">Remount</a></li>
<li><a href="#orgd65b959" rel="nofollow">Use overlayroot-chroot</a></li>
<li><a href="#org5f572fb" rel="nofollow">Disable OverlayFS when booting</a></li>
<li><a href="#orga277402" rel="nofollow">Disable by overlayroot.conf</a></li></ul></li></ul>

<p><a id="org08f1a6b" id="org08f1a6b"></a></p>

<h1 id="how-to-use" id="how-to-use">How to use</h1>

<p>We have a device running Ubuntu and will be powered off directly without shutdown gracefully.</p>

<p>In order to keep the file system from damage, we use the <a href="https://en.wikipedia.org/wiki/OverlayFS" rel="nofollow">OverlayFS</a> provided in Linux kernel since 3.18.</p>

<p>The usage of <strong>OverlayFS</strong> is very simple, as following:</p>

<pre><code class="language-shell"># first install overlayroot package
$ sudo apt-get install overlayroot

# second, change the config file /etc/overlayroot.conf
# the simple config is as following
# we enable swap, and disable recurse overlay
$ cat /etc/overlayroot.conf
overlayroot=&#34;tmpfs:swap=1,recurse=0&#34;
</code></pre>

<p>After rebooting, we should see something like this:</p>

<pre><code class="language-shell">$ df -h
Filesystem              Size  Used Avail Use% Mounted on
udev                     16G  8.0K   16G   1% /dev
tmpfs                   3.1G   74M  3.1G   3% /run
/dev/sda3                96G   16G   76G  17% /media/root-ro
tmpfs-root               16G   60M   16G   1% /media/root-rw
overlayroot              16G   60M   16G   1% /
tmpfs                    16G   24K   16G   1% /dev/shm
tmpfs                   5.0M  4.0K  5.0M   1% /run/lock
tmpfs                    16G     0   16G   0% /sys/fs/cgroup

$ mount
[...]
configfs on /sys/kernel/config type configfs (rw,relatime)
overlayroot on /var/cache/apt/archives type overlay (rw,relatime,lowerdir=/media/root-ro,upperdir=/media/root-rw/overlay,workdir=/media/root-rw/overlay-workdir/_)
overlayroot on /opt/var/cache/apt/archives type overlay (rw,relatime,lowerdir=/media/root-ro,upperdir=/media/root-rw/overlay,workdir=/media/root-rw/overlay-workdir/_)
overlayroot on /var/lib/apt/lists type overlay (rw,relatime,lowerdir=/media/root-ro,upperdir=/media/root-rw/overlay,workdir=/media/root-rw/overlay-workdir/_)
overlayroot on /opt/var/lib/apt/lists type overlay (rw,relatime,lowerdir=/media/root-ro,upperdir=/media/root-rw/overlay,workdir=/media/root-rw/overlay-workdir/_)
</code></pre>

<p><a id="orgf9f1ab8" id="orgf9f1ab8"></a></p>

<h1 id="how-to-disable" id="how-to-disable">How to disable</h1>

<p>When you change some file under <strong>OverlayFS</strong>, and after the reboot, the file will keep the same.</p>

<p>But sometimes you do want to change the original file, how to disable this feature?</p>

<p>We have these methods:</p>
<ul><li>Remount the disk with rw, and change the file under lowerdir</li>
<li>Use <a href="http://manpages.ubuntu.com/manpages/impish/man8/overlayroot-chroot.8.html" rel="nofollow">overlayroot-chroot</a> tool provided by the package</li>
<li>Disable OverlayFS when booting</li>
<li>Disable by overlayroot.conf</li></ul>

<p><a id="orgdd61966" id="orgdd61966"></a></p>

<h2 id="remount" id="remount">Remount</h2>

<p>If you just want to change some files, this is very direct, remount the block device and change the file under lowerdir.</p>

<pre><code class="language-shell"># remount with read-write
$ sudo mount -o remount,rw /dev/sda3

# say we want to change overlayroot.conf
# note: we must change under the file under the lowerdir: /media/root-ro
$ sudo vim /media/root-ro/etc/overlayroot.conf

# remount with read-only
$ sudo mount -o remount,ro /dev/sda3
</code></pre>

<p><a id="orgd65b959" id="orgd65b959"></a></p>

<h2 id="use-overlayroot-chroot" id="use-overlayroot-chroot">Use overlayroot-chroot</h2>

<p>If we want to install some package and keep the package after reboot, we can&#39;t use the first method, since the package may change many files under different directories.</p>

<p>We still have a simple way, you run <strong>overlayroot-chroot</strong> with root, make changes, and the changes will be saved after reboot.</p>

<pre><code class="language-shell">$ sudo overlayroot-chroot
</code></pre>

<p>The change may not take effect immediately after exit the command, you can mount again like this:</p>

<pre><code class="language-shell">$ sudo mount -o remount /
</code></pre>

<p><a id="org5f572fb" id="org5f572fb"></a></p>

<h2 id="disable-overlayfs-when-booting" id="disable-overlayfs-when-booting">Disable OverlayFS when booting</h2>

<p>The overlayroot-chroot method may solve 90% of the problem, but it do has some limitation.</p>

<p>The <strong>overlayroot-chroot</strong> just like chroot into the lower filesystem, and remount with writable.</p>

<p>If you have some scripts-say postinstall in some package, checks the chroot mode, it may refuse to execute under this case.</p>

<p>To fix this problem, we can disable <strong>OverlayFS</strong> during the booting phase.</p>

<p>We can edit the boot command line, append <strong>overlayroot=disabled</strong> and boot again.</p>

<blockquote><p>linux /vmlinuz-4.15.0-123-lowlatency root=UUID=bfb40993-3xxxx ro systemd.unit=multi-user.target <strong>overlayroot=disabled</strong></p></blockquote>

<p>Under this case, the <strong>OverlayFS</strong> will be disabled completely.</p>

<p><a id="orga277402" id="orga277402"></a></p>

<h2 id="disable-by-overlayroot-conf" id="disable-by-overlayroot-conf">Disable by overlayroot.conf</h2>

<p>We can disable <strong>OverlayFS</strong> during the boot time, but if we want to keep it disabled after several reboots, we have a simple way.</p>

<p>You can change the <strong>overlayroot.conf</strong> config file using the remount method, and comment all the lines, and then reboot again.</p>

<p>If we want to enable, we can remount and un-comment the config lines, and after reboot, the <strong>OverlayFS</strong> will be enabled agian.</p>

<pre><code class="language-shell">$ cat /media/root-ro/etc/overlayroot.conf
# overlayroot=&#34;tmpfs:swap=1,recurse=0&#34;
</code></pre>

<p><a href="https://rex.writeas.com/tag:overlayfs" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">overlayfs</span></a> <a href="https://rex.writeas.com/tag:linux" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">linux</span></a></p>
]]></content:encoded>
      <guid>https://rex.writeas.com/use-overlay-filesystem-on-ubuntu</guid>
      <pubDate>Sun, 21 Nov 2021 04:29:06 +0000</pubDate>
    </item>
  </channel>
</rss>