-1

Every time I try to build a little project with my various raspberry pis, I tend to end up abandoning them because of disk corruption.

I’ll have a functioning pi (eg running Recalbox as a games emulator), but then one day the system will freeze up- keyboard and games pads are unresponsive, so the only option is to pull the power.

Doing this a few times results in the SD card getting corrupted- and images like the one shown: disk error on boot of Recalbox on Pi Then the only option is to restore the drive image and start again. Am I doing this wrong? Why doesn’t everyone end up with issues like this?

  • 1
    Not the answer to your question, but if you've customized the SD card extensively, you could make a copy before using it. It could still fail, but you wouldn't have to re-do the customization. – Bob Brown Feb 16 at 16:16
  • 1
    What power supply are you using? What type of sd card? – CoderMike Feb 16 at 17:08
  • Official Raspberry Pi starter kit with their PSU and SD card amazon.co.uk/dp/B01CI58722 – tomh Feb 16 at 17:31
  • re bob - I have imaged the card to save time reinstalling after a corruption, but I'm wondering if this is something everyone just deals with - if it's the cost of using RPi, or if there's a better way to manage power and clean shut downs, if that makes sense! – tomh Feb 16 at 17:33
  • 1
    @tomh, I deleted my answer. I don't think there is any one correct answer if that is what you are looking for. What I've heard in the past are a collection of good practices (some of where are here in these comments). Let me know if you want me to provide such an answer. Otherwise good luck. – st2000 Feb 16 at 22:46
2

I use an external USB HDD for the majority of my pi projects which will tolerate power interruptions.

The majority of SD card corruptions occur when there is a power interruption in the middle of a write operation. Reducing this activity by moving it to an HDD/SDD that can be effectively fsck'd will substantially reduce the chance of SD corruption.

Think of /tmp and working project file locations that have substantial IO.

| improve this answer | |
  • 1
    But if the pi has crashed, and you need to pull the plug to reboot, and the pi was in the middle of writing to the external HDD, how does that help prevent corruption? – tomh Feb 16 at 15:49
  • 2
    It doesn't but the file system recognises it's dirty and cleans up on booting up whereas an sdcard often gets damaged beyond repair. – Bra1n Feb 16 at 18:00
1

Enable a journal on your root partition:

tune2fs -O has_journal /dev/mmcblk0p2

The journal enables the filesystem to revert to a consistent state after a crash. You may still lose data that was being written when you pulled the plug (so pulling the plug during a system upgrade may still result in an unbootable system), but it will not be possible for a game emulator to screw up system files.

| improve this answer | |
0

Depending on your specific project, you could also just mount the rootfs partition (or any other which is written to) as read-only via changing the mount options in /etc/fstab : in the (normally) third line it mounts the root partition, so you add ,ro after the default defaults,noatime.

Note, that after a reboot, you won't be able to write to that partition (e.g. for updates or modifying your project) until you remount it as read-write. This is possible by issuing sudo mount -o remount,rw /dev/mmcblk0p2 /. And if you're done with your work sudo mount -o remount,ro /dev/mmcblk0p2 / or just rebooting.

If you have to have to save something (game progress or logfiles for example), you could create an extra partition for that or use an external drive (e.g. an USB-stick) that you automount as read-write via fststab

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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