Skip to content

Read Only Overlaying a File System

A. Why isn't overlaying a read-only root filesystem with a editable filesystem more popular in Linux?

B. I would like to mount my root partition as read-only and changes to files and directories have overlayed on a seperate partition / file system - what are my leads and options to try something like this

C. One reason I am interested in this is because it allows me to have a boot entry that I can boot incase anything goes wrong.

I currently use BTRFS and am aware of the time based snapshots via TimeShift - I'm looking for Brainstorming, Leads, Pros and Cons - thanks :)

2 points9 comments
Open on Reddit
About this post
Posted
Archived
Score
2 · 100% up
Kind
Text
ID
5m16pl

Author

11
posts
533
comments
4
media
View profile

9 comments

A) Because it's stupid. Depending on how many layers you have, you waste at least the space of the ro rootfs. You'll probably also run into library errors. ro-root gets mounted, parts of it's system are accessed, overlay gets mounted, parts of that get accessed. Now you're running old and new libraries and programs.

B) OverlayFS, unionfs and aufs. OverlayFS however is in the default kernel, so that's probably the best way to go.

C) Either you fuck up or you don't. The overlay won't save you, as the mounts are done via fstab. The broken overlay will get mounted anyway and you're back at square one.

Opinion: I see the idea behind it and it isn't that bad. For the most part, having the linux-lts kernel additionally should be enough. If you really want the overlay, it's a lot of work:

  • Identify which parts need to be ro (example excludes: home, tmp, run. I'm sure there are more that shouldn't reside on the squashed root).
  • Create a new squashfs (the ro part) regularly (I'd say every two weeks).
  • Create correct mounts and mountorders (realroot -> squash -> home, tmp, mnt).

As you've mentioned btrfs: The way with btrfs would be to create a snapshot before updates, update, and if necessary roll back. IMO it's easier and faster than the resquashing.

2 points

Because it's stupid.

It's not stupid, it depends on your use case. Since Arch Linux is a rolling distribution, primarily used on x86, I'd say it doesn't make the most sense. But maybe OP wants to use Arch Linux on some ARM device he's deploying to the field (hint: you want to use OpenEmbedded which supports this use case without any additional effort).

you waste at least the space of the ro rootfs

Yes and no. On embedded systems like routers, the rootfs is typically squashfs and compressed. Anything you put on the overlay filesystem which is already present in squashfs is wasted space. But anything not in squashfs which you install to the overlay isn't wasted.

You'll probably also run into library errors. ro-root gets mounted, parts of it's system are accessed, overlay gets mounted, parts of that get accessed.

No, initramfs will handle mounting the ro-rootfs and overlay before pivoting.

Either you fuck up or you don't. The overlay won't save you, as the mounts are done via fstab. The broken overlay will get mounted anyway and you're back at square one.

No, because the fallback initramfs could skip mounting the overlay and dump you into the ro-rootfs environment. But then I'm not really sure what the advantage is over the normal initramfs recovery shell.

As you've mentioned btrfs: The way with btrfs would be to create a snapshot before updates, update, and if necessary roll back. IMO it's easier and faster than the resquashing.

Yeah if OP is worried about botching updates, btrfs snapshots or LVM snapshots are definitely the way to go here.

/u/electricprism if you're really interested in this concept, take a look at how OpenWrt/LEDE operate in space constrained environments. I don't think they ship this with their x86 image though, as it's assumed you have space.

Yocto/OpenEmbedded also support a read-only rootfs. You can build them pretty easily, but you'll need patience, lots of internet, and hard drive space (>20GB) to build an image. Architecturally OE is closer to Debian than Arch.

Also there aren't that many packages available for OE, so don't expect it to have things like Chromium or GNOME. The OE package definition is quite similar to Gentoo's EBUILD format though, so if you understand that it's easy to add packages.

2 points

Embedded, yes. However, u/electricprism mentions none of that, so plain arch is assumed. Anything else isn't supported anyways. Thus, for the given use-case it is stupid.

Initramfs / fallback: Then you'd have to handcraft your initramfs, AND include the fstab. Unless I'm horribly wrong (and correct me if I am), the initramfs is given the real root and mounts this as ro. Mount-wise, everything after that is handled by /sbin/init, which reads... fstab. This makes your real root rw (or ro, in this case), and afterwards mounts the overlay.

2 points

Thanks, hard drive space isn't an issue, also my target will be x86_64 systems.

I am hoping to create a sort of "Fallback Vanilla Install", maybe Snapshots could accomplish this on some level, however I would need all Snapshot filesytem changes to be temporary and forgotten on reboot. I plan to implement it as a systemd-boot UEFI menu entry.

One of the main goals is to provide a fallback GUI Interface to provide for users in the event that a update borks the system.

I have at least 10 users on Arch that I setup and failing to CLI vs failing to GUI is a huge difference in "failing gracefully" and to be perfectly fair - no system is perfect all of the time.

I'm not a huge fan of Debian systems, thanks for all the text dumps it helps me understand some of the concepts and scope of what I need to know to make it happen.

1 points

Thanks for the data,

A ) Given my understanding of BTRFS the data wouldn't require duplicate space if it was a RO BTRFS Subvolume if I understand BTRFS correctly.

B) I Have heard of OverlayFS, thanks for the UnionFS and AuFS lead - I'm not precluding the possibility of compiling a custom kernel if it turns out to a better solution overall.

C) Well the think about fucking up is part of the idea is to be able to have a boot entry to mount the RO Root Vanilla without the Overlay - this is part of the benefit that I'm looking for - the ability to freeze the system after a complete Arch Install to go back to incase anything were to go wrong.

  1. The squashing vs btrfs snapshots part is pretty interesting.

  2. I recall Android has the system read-only until jailbroken if I recall right.

3 ) I've already successfully extracted ArchUSB ISO into a subvolume and provided that as a Fallback Entry for UEFI systemd-boot to launch which is nice so I don't need to keep the Arch Rescue USB around since it's embedded in the drive

4 ) One of my goals is to provide a failsafe distro / GUI in the event of System bootup error -- it seems like a RO foundation with file change overlay might be a way to accomplish this and help show user changes to the filesystem at the same time.

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.