Dealing with Raspberry Pis failing SD-cards

11 December 2021


I have for a long time used a Raspberry Pi as a file server with samba. The problem is that every 6 months or so, the SD-card gets corrupted and then I have to set everything up again from scratch. This is very annoying since it takes a bit of time to configure and install everyting correctly. I usually follow a combination of these two tutorials:

I recently saw a video about how you don’t need to use the dd command to flash disks in Linux. Apparently you can just copy the ISO to the /dev/whatever as in this video. Which I did for my Raspberry Pi SD-card. It worked great.

I also figured that you could then just copy from /dev/whatever to get an image of the disk. One you could later boot from.

So I installed and set up samba on the Raspberry Pi. Then I put the SD-card in the computer and made an image of it. It worked, but the file was as large as the SD-card (64GB).

I then found this repo which makes the image smaller and resizes it on boot. I used the script on the imgage. Then I reformatted the SD-card and flashed the smaller image to it to test if it still works. Which it did.

So, the next time the SD-card breaks, I can just flash this old image on a new SD-card and get back up and running directly. Since the fileserver files are on a hard drive they will not be affected.

One potential risk could be missing out on security updates. But since I only run it on the local network I don’t think it matters.