A fun discussion at a geeky tech meetup lunches:
You have a Linux single board computer or "SBC" (or any Linux host) as the basis of a cool DiWHY audio project what is the best way to shut it down?
Easy!
sudo shutdown now #or something like this--depends on distro
....of course. The command makes the OS spin everything down without stressing the file system.
But what if the linux system is an appliance and someone yanks the power cable without issuing said command?
Any habitual Linux user knows: bad idea. The file system will attempt to recover from an abrupt shutdown, and usually will, but every now and then: not as much.
But--there must be a way to do this!
There are Linux based routers, set top boxes, Internet TV's and everything else, routinely surviving abrupt power loss.
How do they work?
Huge shout out to group member MVCL who pointed me to OpenWRT, a Linux based router appliance, and the technology it uses to survive power hits--overlayfs--more info here.
Could I get it to work?
Yep..
CHEAT CODE--OVERLAYFS ON A NOVEMBER 2025 RASPBERRY PI:
Reboot--
BAM! you are good--the OS is read only; contents on the SD card are copied to RAM during boot; end user changes are stored entirely in RAM.
If you pull power your OS configuration is safe; RAM contents are lost; at power up the process starts over.
- What about other distros (like Debian 13)? Same steps?
- How does overlayfs work at a deeper level?
- How do we change the read-only OS to do things like change configuration files and perform updates?
TESTING OVERLAYFS WITH VM's
For proofs-of-concept I created 2 VMware Workstation Pro Debian VM's: One to experiment with overlayfs basics, another to create a "kiosk system" that could survive power hits.
Creating the first VM was pretty easy, here are the steps:
#in Debian, add user your username to sudoers
#this makes sudo commands work like ubuntu.
su - #use the minus to preserve paths for normal user.
usermod -aG sudo charlie #I am user charlie, you are not.
#use your username instead of charlie, elmo.
#-----------------------------
#OverlayFS requires 4 directories to work.
#lower directory: the OS
#Upper directory: where changes are stored
#work directory: the kernel prepares files before moving them to #upper layer
#merged directory: the mountpoint the end user sees
# Create a main project folder
mkdir ~/overlay_lab
cd ~/overlay_lab
# Create the four required directories
mkdir lower upper work merged
#What these directories will be used for.
#overlay: The device name (can be anything, but overlay is standard).
#-o: Specifies we are adding options.
#lower dir: The bottom layer. This is a directory used by overlayfs.
#upper dir: The writable top layer.
#This is a directory used by overlayfs
#work dir: The directory for internal operations
#(must be on the same partition as upperdir).
#merged: The mount point. This is what the end user sees.
#-----------------------------------------------
#put data into lower dir. from overlay_lab dir:
echo "I am a base system file." > lower/base_config.txt
echo "Do not delete me." > lower/important_data.txt
#-----------------------------------------------
#run the overlayfs mount cmd. watch the line wrap!
sudo mount -t overlay overlay -o lowerdir=lower,upperdir=upper,workdir=work merged
#now you can see in merged these 2 files that came from lower.
#changes to files in merged directory are mimicked to upper
#deletions in merged directory cause a "whiteout" file in upper, #"masking" the deleted file
#files added to upper (copying a read only OS for instace are copied #to merge dir
#if you edit a file in upper the edits do not appear in merged.
#if you edit fstab incorrectly you'll brick your SBC. This is why we #snapshot experimental VM's!
#edit fstab so your new configuration isn't lost at reboot
#you are going to want to create a VM snapshot
#before you mess with fstab. (watch the wrap for the following cmd)
overlay /home/charlie/overlay_lab/merged overlay noauto,x-systemd.automount,lowerdir=/home/charlie/overlay_lab/lower,upperdir=/home/charlie/overlay_lab/upper,workdir=/home/youruser/overlay_lab/work 0 0
All of this means that you have created a new mount at startup; "merge" is the directory where your active files will reside. Other directories are hands-off--pretty easy.
No Sh*t Sherlock: Docker makes heavy use of overlayfs. Didn't know that! Video here.
AND NOW--A WORD FROM THE BLOG'S SPONSOR
CREATING THE "KIOSK" VM
On a second Debian VM here are the steps I used to configure the kiosk VM:
#root and login
su -
#make sure overlayroot is installed. Should be....if not....
apt-get update
apt-get install overlayroot
#add overlay module on next boot.
#we are adding overlay as a single line to the bottom of the modules #file.
echo "overlay" | tee -a /etc/initramfs-tools/modules
#edit grub; do this carefully
vi /etc/default/grub
#change the GRUB_CMDLINE_LINUX_DEFAULT to this (quotes are needed)
GRUB_CMDLINE_LINUX_DEFAULT="quiet overlayroot=tmpfs"
#save the file (":wq!)
#rebuild grub
update-grub
update-initramfs -u
#reboot.
#------------------
file system (dh -f) should look like this.
The main thing: overlayroot is now mounted as /
For me, I could force-power-off the VM and restart--yep, all seemed OK.
After several reboots I didn't see tons of inode rebuild errors and whatnot. The virtual machine survived the power hits A-OK.
So far, so good.
HOW DO I CHANGE THE READ-ONLY FS?
To make minor changes to the read only partition:
overlayroot-chroot
(make changes--apt installs, for instance)
when done...
exit
I could use this for apt installs and updates...."exit" sometimes threw errors, but my changes stuck.
-----------------
Another method: this flipped me back to normal Debian once; when I rebooted the OS it was back to overlayfs mode.
I read this is best for major OS changes and configuration file redo's.
Reboot the VM.
At the GRUB menu, press
e.Find the line with
overlayroot=tmpfs.Change it to
overlayroot=disabled.Press
F10to boot. (You are now in a standard, persistent Debian environment).to check: mount | grep overlay # produces no output. overlayfs is not #running.
Run your updates, then
rebootto re-enable protection.
Finally, I deployed a trick for advanced Linux nerds.....allowing a menu choice in GRUB to disable overlayfs, visible from the initial grub menu seen at startup--info here....
Editing grub configurations is not for the faint of heart and can potentially brick your SBC's OS configuration; if you aren't into moderate to advanced Linux tweaking you should probably skip this option.
#--------------------------------------------------
Follow the "go to normal once" mode using e key, above.
Once in normal mode create some text we will need later.
grep -A 20 "menuentry '" /boot/grub/grub.cfg >> grub.txt
Now use vi to open 2 files at once:
vi /boot/grub/grub.txt /etc/grub.d/40_custom
once in vi you see grub.txt....issue this command (no : needed)
20yy
this yanks the top 20 lines of the grub.txt file.
in vi, issue escape then this command
:bn
this flips you to the 40_custom file, then type
p
this pastes the 20 lines from the bottom of the grub.txt file
...now edit the 40_custom file to match what I have boxed in red:
reboot.
If all went well you get a new option each time you reboot: choosing what is boxed below puts you into "normal" mode. Make OS changes; reboot, and pick "Debian GNU/Linux" to go back to overlayfs.
MORE ABOUT OVERLAYFS ON MY RPI SBC
![]() |
| SBC setup for overlayfs. Most important component: the coffee. |




