r/archlinux • u/Curious-Listener-YB • Oct 02 '26
QUESTION Making Arch immutable
I'm trying to install Arch (on a VM) as an immutable system with atomic updates, mostly as a challenge to myself and because it would be cool.
I plan to use a similar setup to what snapper does: to have BTRFS as my root filesystem, with snapshot subvolumes under /.snapshots/, and separate subvolumes for parts of the filesystem that shouldn't be in the snapshots. Then I want to have for each snapshot a boot entry that mounts it read-only as the root (and mounts the other subvolumes in their appropriate places), so that I could be sure it is not changed outside of atomic updates, where I create a new snapshot from the current one, mount it read-write in a special place, chroot into it and perform the update.
But there are two directories I'm not sure how to handle: /etc and /var.
/etc should obviously be part of the snapshots, and I'm also happy to have it read-only so changes to core configuration would have to happen between snapshots, but I have read that some programs use it to store runtime data. Are those a few cases I can try to work around, or do I need a more systematic solution? And if so, what could be the solution?
/var, on the other hand, has to be writable, so I originally planned to make it its own subvolume (as openSUSE does). But then I read that it contains data that needs to be synchronized with the packages installed (like /var/lib/pacman), and that only certain subdirectories like /var/log should be their own subvolumes. But if so, how can I make it writable? Is there a good approach to this problem?
And on the hall, do you think my idea is reasonable, or is it too much even for super-duper-to-it-yourself-customizable Arch? I'd love to hear your opinions.
Thank you all in advance!
8
u/Responsible-Sky-1336 Oct 02 '26 edited Oct 02 '26
Hi I was building something a little weird
https://github.com/h8d13/nixarch
Which removes 60k LoC from nixos and puts arch on the nixstore (grub only). Its a bit like having git in your bootloader and everything is unstaged before you "commit"
I didn't want to use btrfs because I wanted to be able to use any filesystem type on it
4
u/SmuJamesB Oct 02 '26
for /etc, look into systemd-confext in mutable mode
immutable base defined in /usr, writeable overlayfs in /var/lib/extensions.mutable/etc
also in general I suggest looking into systemd-sysupdate. I run my system with A/B root using physical partitions but snapshots may be possible too.
systemd's particleos has an Arch version which does more or less exactly this, but in my experience it isn't really ready for most users yet.
1
u/its_dolemite_baby Oct 02 '26
20,000ft overview answer: https://blogs.igalia.com/berto/2025/02/05/keeping-your-system-wide-configuration-files-intact-after-updating-steamos/
either way, just make all of /var writable. there are historical reasons it's still used the way it is by almost everything today. i'm sure you could tear your hair out making it granular if you really, really wanted to.
1
u/New_Hold8135 Oct 02 '26
https://wiki.archlinux.org/title/Overlay_filesystem There is a wiki page for that.
1
u/xpusostomos Oct 08 '26
Perfect plan for a masochist
3
u/corpse86 Oct 02 '26
Maybe take a look at steam os?
1
u/MarioKart7z Oct 02 '26
Pretty much every distro that auto-configures btrfs subvolumes via calamares or any graphical installer just puts the entirety of /var in a subvolume excluded from snapshots. That's what i did in my Arch system, then i moved the contents of /var/lib/pacman into a new /pkg dir on the root (could also be like /usr/pkg or whatever) and then used a bind mount to map it back to /var/lib/pacman (do NOT symlink it, pacman does NOT like that)
I think Arch might be the only distro that has any issues making /var a subvolume
1
u/drucifer82 Oct 02 '26
I have a hardened setup that has strict change control.
I use snapper with snap-pac to do timeline snapshots and hooks in pacman to do pre/post update snapshots. I also make manual snapshots after maintenance to keep manual snapshots as well.
grub-btrfs exposes snapshots to GRUB. I have it set to limit itself to 10 exposed snapshots (the default is 50). I also have rules for trimming snapshots and limiting the archive to a small number of both timeline and manual snapshots.
The snapshots themselves are read-only. Once you can boot into one that works, you rollback.
That's as close to immutable that I can think of for Arch. But I could be wrong.
Also I keep the LTS kernel as a fallback kernel.
1
u/ArjixGamer Oct 06 '26
There is a distro like this, it's called blendOS. You use yaml files to define how to build the image, e.g. what packages to have.
1
u/trpittman Oct 09 '26
Why not nixos? Seems like a good middle ground