I'm not going to write about checking your HW and compatible SD card lists, because you most probably have already checked all these. What I'm about to write is the permanent solution, that allows to nip the problem in the bud, and permanently fix the issue.
If you don't want your SD card to get broken when you flip the power switch, you have to use it in a read-only mode. If there's nothing being written to your SD card, it won't get damaged no matter what you do.
Obvious (but non-working) solution would be an attempt to flip "read-only" switch on the side of the SD card, unfortunately this does not work because the schematics shows this switch is routed nowhere and its position is generally ignored.
Another, more subtle (but working) approach would be modifying your
/etc/fstab to mount all your partitions read-only. The drawback of this approach is your logs have to be written somewhere else (USB stick, RAM drive?) and in case of RAM drive the logs won't persist during reboot.
Here's a sample
/etc/fstab you might want to use:
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat ro 0 0
/dev/mmcblk0p2 / ext4 ro 0 0
none /var/run ramfs size=1M 0 0
none /var/log ramfs size=1M 0 0
I haven't personally tested this setup (I have the UPS keeping my Pi powered on 24/7), but other people have reported no issues while flipping power switch as often as possible.
UPDATE: here's a quick how-to regarding this method. you'll need an empty SD card 4GB+ in size and a linux box, so you can access non-microsoft file systems easily in case something goes wrong.
- copy an raspberry image to your sd card, use any method you like.
- boot from SD, it will start
- do not "Expand filesystem", just set up your time zone and international settings.
sudo fdisk /dev/sda, press 'p', check your partition.
- press 'n', create a new partition, that would become your
fdisk, add the following to your
/dev/mmcblk0p3 /home ext4 defaults,errors=remount-ro 0 1
format your new partition with
sudo mkfs -type ext4 /dev/mmcblk0p3 and reboot.
now you may install all your software, write scripts and prepare your RasPi.
After the preparation is finished, you have to change the two lines in
/dev/mmcblk0p2 as shown above. Next reboot will make your boot and system partitions read-only, but you still may write your data to your
If for some reason you need to make changes to your system, you cannot change
/etc/fstab on read-only partition, so here's where your linux box comes handy. Take your SD card and put it into the linux computer, find
/etc/fstab and change
ro back to
defaults. Then you'll have write access to the system partitions again.