Write and read image files for the Raspberry Pi
The Raspberry Pi is this small cool ARM based board that you can use for endless projects and is compatible with many GNU/Linux distributions!
It main storage is a simple SD card that goes into a slot in the board and in this card is where you must install the linux distro you choose to use.
- Attention
- In this article, to exemplify the installation of a distro, we will use the ARM compatible version of Arch Linux, being installed in a Ubuntu environment.
Writing the image
To write an image file to a SD card follow these steps:
- Download the the latest zip containing the image:
- Extract the zip file to your hard drive, giving you the image archlinux-hf-*.img.
- Open a terminal window and go the the directory where the image was extracted.
- Insert the card in your computer (at least 2GB1).
- Find out the path to the card:
- With the command
df -h
list all mounted partitions. - Your card partition will be listed as something like /dev/mmcblk0p1.
- The sd card itself is the partition path minus the pX part, so something like /dev/mmcblk0, take note of it.
- With the command
- Unmount the card with the command:
$ sudo umount /dev/mmcblk0
- To write the image to the card use:
$ sudo dd bs=1M if=archlinux-hf-*.img of=/dev/mmcblk0
- It could take a while, so relax.
- After is done run the command
sync
to ensure the cache is flushed and it safe to remove the card:$ sudo sync
- Remove it, insert it in the Pi.
- Have fun!
Reading the image
After a while using your system you will have a fully personalized linux installation with your favorite programs in it.
But not everything are roses, SD cards are susceptible to corruption and a bad block can ruin your system, because of that is always handy to have a backup copy for easy recover!
And backing it up is pretty similar to how we write it in the first place:
- Insert the card with your system image in your computer.
- Like when writing your image, use the
df -h
command to find the path to the card. - Unmount it with
sudo umount /dev/path_to_card
. - Now, use the
dd
command to write an image of the card to a file:$ sudo dd bs=1M if=/dev/path_to_card of=mylinux.image
- Execute the
sync
to flush the cache:$ sudo sync
- Remove your card.
That’s it! Now you have a full backup of your customized system, if you have any problem just write it to a card line we did in the first part of this article and it will be as good as new!
- Attention
- The generated image can only be written to a card with the same (or larger) size, so the backup of a 4GB card can be written to a 8GB card, but not to a 2GB one.
-
Each system have it’s own minimum space spec, make sure to check it in the systems site ↩