4 comments on “Reduce or eliminate SD card corruption on Raspberry Pi

  1. Wow – such a great write up. Firstly, it worked. But the clarity of explaining what to do and what was happening was also excellent – a little learning is always a good thing. Also, I saw several other “how to’s” that were immensely more complicated. Being a low/mid-grade hack, this was much appreciated. I have had so many SD cards corrupt over the years (my doing no doubt) – I need a stable implementation for a kiosk I don’t want to have to service often and this is perfect. thanks again Wizworks and K1WIZ for the post

  2. Its just another flash drive with /var on it.

    I would have a look at overlayFS as many kiosk mount the whole system in the lower readonly and then use tmpfs or zram for the upper.
    Being copy-up COW only writes are in upper but the system just sees the merge of the 2.

    I do something similar in https://github.com/StuartIanNaylor/zram-config for any directory bind mount it elsewhere mount a zram drive then place a union at the original directory tree.
    Doesn’t require a copy on start and just merge down on stop.

    Hack,copy as you wish.

  3. Thank you for your feedback. I will have a look at it. Do you have any projects in which you employed this technique?

  4. Very useful info
    I assume since swap is now on the external USB stick, there is no real need to disable swapping
    since that will no longer affect the internal flash card?.

    I simply made the ext4 filesystem on a new usb stick:
    mkfs.ext4 var /dev/sda – this uses the whole stick without creating two partitions!
    Then, rather than using ‘mv’ to transfer the files, I used ‘cp’ instead as below, as this leaves the original
    files on /var intact, just in case anything goes wrong:
    mount LABEL=var /mnt
    cp -p -r /var/* /mnt
    (note -p is vital, to ensure all files have correct ownership and attributes)
    umount /mnt
    add var to /etc/fstab as ‘LABEL=var /var ext4 defaults,noatime 0 1 ‘
    as this avoids any problems if more than one usb stick is in the pi at boot time

Leave a Reply

Your email address will not be published. Required fields are marked *