4

I'm looking to set up a simple system for public usage, probably with Raspbian.

I would like to set it up to be a specific way, and have it stay that way. The goal is for the entire OS to wipe and reset itself on every boot, so that the user can't mess it up - if they accidentally touch something they shouldn't, they can just reboot the system and the OS will be back to the way it was.

I have heard that you can use Deep Freeze on Windows to do this, which I've never used, but I don't know how to accomplish the same thing on a Raspberry Pi.

2 Answers 2

7

The idea is to use a read only file system as you have it on a LiveCD together with a union filesystem.

(quote [1]) Generally speaking, a union filesystem combines multiple filesystems into a single virtual filesystem. There are mainly two union filesystems: overlayfs and aufs. Both have the same basic model. The following is a dramatic simplification:

  • Filesystems are stacked vertically.
  • Read accesses are attempted on each filesystem in turn from top to bottom. The first filesystem that contains the file being read is used for the read operation.
  • Write accesses are performed similarly, but files that are written to are stored in the top-most writable filesystem. This usually means there is a single writable layer in the union. If files that exist in a read-only layer are written to, they are first copied to the next highest writable layer.

If you use your default read only filesystem and overlay it with a read/writable tmpfs then all changes (they are only stored in tmpfs) will be lost on a reboot.

I prefer to use overlayfs because it is simple and part of the kernel. We only have to activate it. There are several scripts and HowTos on the web to do that but I prefer overlayroot. It is small, well documented, up to date and has nice features. You can simply update your read only filesystem and you can use semi permanent overlays like USB-Sticks, but default is to use tmpfs. If you add skipoverlay to /boot/cmdline.txt you can disable this.

Installing it is done in some minutes. Download the scripts and unzip them:

rpi ~$ curl -L https://github.com/chesty/overlayroot/archive/master.zip >overlayroot.zip
rpi ~$ unzip overlayroot.zip

Now follow the instructions from overlayroot or in overlayroot-master/README.md. I do not repeat it here to have it in one place because it may change in some time.

For debugging you can check the generated init.gz for its content [5]:

rpi ~$ mkdir /tmp/initramfs
rpi ~$ cd /tmp/initramfs
rpi ~$ gunzip -c /boot/init.gz | cpio -i -d -H newc --no-absolute-filenames


references:
[1] How To: Build A Read-Only Linux System
[2] aufsRootFileSystemOnUsbFlash
[3] How do I use OverlayFS?
[4] Raspberry Pi Overlay Root Filesystem
[5] initramfs-tools
[6] root-ro
[7] overlayroot

1

Start by separating changeable parts of the system, to different partitions. User changeable parts are in /home, but the OS also changes stuff in /var. Then mount the root partition as read-only. And mount the other parts on top. You can then wipe the variable parts without braking the immutable OS part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.