mahler ~ # mkdir /roroot
mahler ~ # mount -o bind,ro / /roroot
mahler ~ # chroot /roroot
mahler / # passwd
Enter new password:
Re-type new password:
passwd: Authentication token lock busy
passwd: password unchanged sudo systemd-nspawn --directory=/ --read-only --ephemeral --volatile=yes
[systemd-nspawn](https://man7.org/linux/man-pages/man1/systemd-nspawn.1.html) would normally be used to run a command inside of a container (a directory), but in some modes you can specify the system root as the "container" path.I believe this specific set of options relies on (BTRFS) file system snapshots for performance. It's possible that you can get it to work on non-BTRFS systems by providing another combination of command line variables, but the default setting is to copy the file system tree to a temporary path.
You can also pass parameters like --volatile=state (so you can write to /var) and --volatile=overlay (so you can "write" to state, but all changes are discarded after the container exits). --volatile=state is useful for extracting data from a temporary read-only system, --volatile=overlay is useful for running tools that crash if they run on a read-only filesystem.
You can use overlayfs + chroot.
I created a seccomp DSL to make this kind of stuff easier [0] (an example of dropping network access is at [1])
[0] https://chiselapp.com/user/rkeene/repository/bash-drop-netwo...
[1] https://chiselapp.com/user/rkeene/repository/bash-drop-netwo...
Maybe this would help:
https://serverfault.com/questions/136515/read-only-bind-moun...