Flashing or backing up your SD card » History » Version 8

Version 7 (Giulio Moro, 2016-04-19 11:39 PM) → Version 8/9 (Giulio Moro, 2016-04-20 12:19 AM)

h1. Flashing or backing up your SD card

For both these tasks you will need the @dd@ software. It comes with many Linux distributions and is available for MacOS and Windows, although I have not tried to use it on Windows myself.

Put your SD card in the SD card reader. We assume for the rest of this document that your SD card is /dev/mmcblk0

Always start by unmounting the SD card in case it is currently mounted. On linux you would do: mounted:
<pre>
$ sudo umount /dev/mmcblk0
</pre>

On MacOS you would do:
<pre>
$ sudo diskutil unmountDisk /dev/mmcblk0
</pre>

h2. Flashing an SD card

Whether you got an image from somewhere else or you want to flash your own backup image after you bricked your Beaglebone, do as follows:
make sure that the SD card is inserted and that none of its partitions are mounted as explained above.
Then:
<pre>
$ sudo dd if=~/bbb_images/your_own_your_precious_backup_image.img of=/dev/mmcblk0
</pre>
As it happens, @dd@ is a very simple program, so simple that it does not even display a progress bar.
If you are lucky enough to be on Linux, you can probably easily install pv which will display a progress bar for you:

pv ~/bbb_images/your_own_your_precious_backup_image.img | sudo dd of=/dev/mmcblk0

h2. Backing up your SD card

If you are planning to compress your image file (e.g.: for sharing over the network, or for archiving), you may want to run this command, which fills the unused space with zeros, so that the compressed file will have a smaller size.
To do this, the lines below will create a file to fill the empty space in the partition and fill it with zeros. The second line will delete the file.
size:
<pre>
$ sudo dd if=/dev/zero of=/path/to/the/mounted/sdcard/bigfile bs=1M
$ sudo rm /path/to/the/mounted/sdcard/bigfile
</pre>

Make sure that the SD card is inserted and unmount all of its partitions as explained above.

In case your partition is smaller than the size of the SD card, you do not need to backup the whole card, so if this is the case, run:
<pre>
$ sudo fdisk -u -l /dev/mmcblk0
</pre>
You might get something along the lines of
<pre>
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 * 63 144584 72261 c W95 FAT32 (LBA)
/dev/mmcblk0p2 144585 3743144 1799280 83 Linux
</pre>
You are interested in the higher value in the "End" column. Pass that value to dd as the count parameter:
<pre>
$ sudo dd conv=sparse count=3743144 if=/dev/mmcblk0 of=~/bbb_images/your_own_your_precious_backup_image.img
</pre>

If, instead, you want to backup the entire the SD card, simply use:
<pre>
$ sudo dd conv=sparse if=/dev/mmcblk0 of=~/bbb_images/your_own_your_precious_backup_image.img
</pre>