Why the Raspberry Pi micro-sd might fail
There are many reasons why a storage device, such as a micro-sd card, can fail. If we do not have much experience within Linux operating systems, it is easy that, when making changes in the configuration, or when updating, the system is damaged and, by not knowing how to recover it, we lose everything we had. Generally, everything that refers to configuration errors of a Linux system has a solution, the thing is, how?
But software bugs are not the only ones that can give us headaches. There are also other reasons why we can lose the operating system of this microcomputer. For example, there may be a critical error with the system that causes partition table is cleared and the memory card appears as “blank”. This can easily happen if we disconnect the Raspberry as we should not. It may also happen that, over time, memory card stop working because it has exhausted the read and write cycles of its chips. This happens, especially, when we use low-quality SD cards. And there is no choice but to give up all the content and buy a new one.
The advantage of this storage system is that, if it breaks, or if we want to change to a higher capacity one, we can do it very easily, since it is enough to buy a new memory card, configure it and put it in the Raspberry Pi to start to use it. The only thing we will lose is the time necessary to leave everything as we had it at the beginning.
And to avoid it, there are backups.
There are several ways to back up a Raspberry Pi card. Depending on whether we do it from Windows, or from Linux (even from the micro-computer itself) the process that we must follow will be one way or another. Let’s see it in detail.
To back up the memory card from Windows, the only thing we will need is that our computer has a memory card reader. If not, we must buy one in any store (they can be around 10 euros, and even less) and connect the card to our computer through it. It is likely that we will see a message that tells us that the memory card is not formatted and that we have to format it. It is important not to do it and ignore the message. This appears because the micro-sd will be on a Linux file system (such as ext4) and therefore Windows will not be able to read its files.
Next, we will download a free and open source program called Win32 Disk Imager and install it on the computer. Once installed, we execute it and we will see a window like the following one.
We click on the folder button that appears in the «Image File»And we will select the directory where we want the backup we are going to make to be saved. We will also select in the section «Device»The unit from which we are going to make the copy.
How is it possible to make a copy of the data if Windows does not recognize it? Because this program makes a copy «RAW«, That is to say, in crude, of the 1 and 0 of the data. No matter the content, a literal copy of the drive is created (even the free space on it) so that there is no problem.
Once everything is ready, we click on the button «Read»And the image creation process will begin. This process can take several minutes, and will occupy the same capacity as the original memory card.
When the reading process is finished, we will have the image (a file, with .img format) in the directory that we have specified. We can now remove the card from the computer, and reconnect it to the Raspberry Pi.
From Linux or the Raspberry Pi itself
If we are going to do it from a Linux system (and even from the Raspberry Pi itself to an external drive that we have, for example, via USB or network), what we must do is connect the card to the computer (if we do not already have it ) and locate your mount point using the following command:
sudo fdisk -l
Assuming it is / dev / sdb (which will vary depending on the drives connected to the PC), then we will use the command “Dd” to clone the RAW data of the main unit (the card) to the directory that we want. This command has the following structure:
sudo dd if=/dev/sdb of=[directorio]/raspbackup.img
We must change [directorio] along the path where we want to save the image. Either a network drive, or a different mount point. What is logical is that we should not create the backup on the same micro-sd, since, if the data is lost, and the backup, it is of little use to us.
Restore a copy of the SD
To restore the backup in case the original card fails, or we change it for a bigger one, literally what we have to do is follow the steps in reverse.
In the case of Windows, for example, we will again use the Win32 Disk Imager programSelecting in “Image File” the backup image, in “Device” the drive letter of the micro-sd where we are going to write the image, and we will click on the “write” button. The process will erase all the data, and when it is finished we will have the memory card ready to work again on the Raspberry Pi.
In the case of Linux, what we must do is use again the dd command, but in reverse. In other words, in the “if” parameter we can find the directory of the backup image (img), and in the “of” parameter, the mounting point of the memory card where we are going to dump said image.
sudo dd if=[directorio]/raspbackup.img of=/dev/sdb
In case we were wondering, copying the file “raspbackup.img” (or whatever we call it) to the memory card is of no use. A bit-by-bit RAW dump of the content has to be made, just as the copy was made.