I'm running my Pi as an Airplay server(using Shairport). Now I'm wondering if there is any way to prevent the SD-card from getting corrupted if I cycle power unexpectedly? I read about mounting the root filsystem read-only and ramdisks, but couldn't find a good explantation anywhere.

Is it possible to configure the os in such a way that it is safe to cycle power at any time? I don't need to store any changes after the system is booted, just boot the same state every time power is cycled.

Thanks in advance!


Ok, after some more research, this is my current /etc/fstab. It works, but / is still mounted in rw mode. At least I'm using sync and noatime which should reduce the probability of the SD card getting corrupted.

# /etc/fstab: static file system information
# <file system>        <dir>         <type>    <options>          <dump> <pass>
/dev/mmcblk0p1  /boot                   vfat    ro,noatime                 0       0
/dev/mmcblk0p2  /                       ext4    noatime,nodiratime,sync    0       0
ramfs           /tmp                    ramfs   defaults,noatime,mode=1777 0       0
ramfs           /var/cache/pacman       ramfs   defaults,noatime,mode=1777 0       0
ramfs           /var/log                ramfs   defaults,noatime,mode=1777 0       0
ramfs           /var/tmp                ramfs   defaults,noatime,mode=1777 0       0

Just mounting / in ro mode won't work. Well, the Pi boots but some serives (like Logger Daemon) can't start and the shell gets flooded with error messages.

Does anybody know a way to mount /var in a ramfs and load the original files on boot? I found many sources on how to do it, but the Arch distro seems to have changed the way you run bootscript to systemd recently and I can't get it to work that way.


I tried mounting /var on a ramdisk, but the system didn't boot afterwards so I can't post my original code.

What I did was copying /var to /var-new and adding an entry to my fstab

ramfs           /var                ramfs   defaults,noatime,mode=1777 0       0

I removed the entries for the subdirectories of /var, of course. Then I added a systemd "bootscript" called mountramfs.service which ran the script /mountramfs. Activated this with

systemctl enable mountramfs.service
systemctl start mountramfs.service

the /mountramfs contained something like

cp -R /var-new/ /var/

What I tried to achieve with all this was that /var-new would be copied to the empty /var directory on the ramdisk. This would have made it possible to use the same directory every time the system reboots. It started, but couldn't run some services(including ssh) so i couldn't access it anymore and only watch the messages on my tv(via hdmi).

What's wrong with this approach? can anybody help?

  • This question is about mount options for increased safety, but in a case where read only is not an option. What you ask for must be possible, since live CD:s work that way. I think there is a way to have a read-only file system combined with a ramdisk, so that you can write to any file, and the newly written data is stored on the ramdisk.
    – Frepa
    Mar 11, 2013 at 15:31
  • Which folders would I have to link to a ramdisk? I'm new to Arch. Mar 11, 2013 at 18:46
  • I found this link but I'm not advanced enough to understand all of the information and edit my files accordingly Mar 11, 2013 at 19:37
  • That was a good link. Indeed, you can just mount some directories read-only and some on ramdisk, no need for unionfs. My guess: /home, /var, /tmp on ramdisk. Look at the examples at the bottom of the linked page.
    – Frepa
    Mar 12, 2013 at 11:16
  • Just moving the folders to a ramdisk doesn't work, I need a way to copy their original content into the ramdisk as well (using systemd) Mar 12, 2013 at 14:06

1 Answer 1


Booting from a read only partition guarantees you to be able to boot. Then, if you have to write to other partitions you can always check their integrity first thing after booting. It is advised to write to preallocated file(s) who are ideally size of single sector, or at least an exact multiple. Using something like SquashFS could solve your problem. Berryboot allows you to do it in an easy way. If you want to do it on your own you can find some info here.

  • Hi, thanks for the answer. What would Berryboot do in my setup? I don't know Berryboot but it seems to be a Bootloader for the Pi. How would it solve my problem? Mar 13, 2013 at 12:30
  • Berryboot loads SquashFS read only images of various linuxes, and there is an instruction how to make SquashFS image of ArchLinux. That is your jump start. Once you see how to do it with Berryboot, it shouldn't be too hard to do it without Berryboot.
    – avra
    Mar 14, 2013 at 19:15
  • Yes, but Berryboot uses an external "container" to be able to store data. That's great because the image itself doesn't change but I'm trying to reduce write cylces to the SD-card and afaik Berryboot doesn't change those at all Mar 18, 2013 at 8:02
  • Reducing write to Pi with logging to RAM: raspberrypi.org/phpBB3/viewtopic.php?f=29&t=13889
    – avra
    Mar 21, 2013 at 14:50
  • I'm already doing that with: ramfs /var/log ramfs defaults,noatime,mode=1777 0 0 Mar 23, 2013 at 8:59

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.