Flashing or backing up your SD card » History » Version 8
Giulio Moro, 2016-04-20 12:19 AM
1 | 1 | Giulio Moro | h1. Flashing or backing up your SD card |
---|---|---|---|
2 | 1 | Giulio Moro | |
3 | 6 | Giulio Moro | 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. |
4 | 2 | Giulio Moro | |
5 | 1 | Giulio Moro | Put your SD card in the SD card reader. We assume for the rest of this document that your SD card is /dev/mmcblk0 |
6 | 2 | Giulio Moro | |
7 | 8 | Giulio Moro | Always start by unmounting the SD card in case it is currently mounted. On linux you would do: |
8 | 1 | Giulio Moro | <pre> |
9 | 1 | Giulio Moro | $ sudo umount /dev/mmcblk0 |
10 | 1 | Giulio Moro | </pre> |
11 | 1 | Giulio Moro | |
12 | 8 | Giulio Moro | On MacOS you would do: |
13 | 8 | Giulio Moro | <pre> |
14 | 8 | Giulio Moro | $ sudo diskutil unmountDisk /dev/mmcblk0 |
15 | 8 | Giulio Moro | </pre> |
16 | 8 | Giulio Moro | |
17 | 3 | Giulio Moro | h2. Flashing an SD card |
18 | 3 | Giulio Moro | |
19 | 3 | Giulio Moro | 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: |
20 | 3 | Giulio Moro | make sure that the SD card is inserted and that none of its partitions are mounted as explained above. |
21 | 3 | Giulio Moro | Then: |
22 | 3 | Giulio Moro | <pre> |
23 | 3 | Giulio Moro | $ sudo dd if=~/bbb_images/your_own_your_precious_backup_image.img of=/dev/mmcblk0 |
24 | 3 | Giulio Moro | </pre> |
25 | 6 | Giulio Moro | As it happens, @dd@ is a very simple program, so simple that it does not even display a progress bar. |
26 | 3 | Giulio Moro | If you are lucky enough to be on Linux, you can probably easily install pv which will display a progress bar for you: |
27 | 3 | Giulio Moro | |
28 | 3 | Giulio Moro | pv ~/bbb_images/your_own_your_precious_backup_image.img | sudo dd of=/dev/mmcblk0 |
29 | 3 | Giulio Moro | |
30 | 1 | Giulio Moro | h2. Backing up your SD card |
31 | 1 | Giulio Moro | |
32 | 8 | Giulio Moro | 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. |
33 | 8 | Giulio Moro | 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. |
34 | 7 | Giulio Moro | <pre> |
35 | 7 | Giulio Moro | $ sudo dd if=/dev/zero of=/path/to/the/mounted/sdcard/bigfile bs=1M |
36 | 7 | Giulio Moro | $ sudo rm /path/to/the/mounted/sdcard/bigfile |
37 | 7 | Giulio Moro | </pre> |
38 | 1 | Giulio Moro | |
39 | 7 | Giulio Moro | Make sure that the SD card is inserted and unmount all of its partitions as explained above. |
40 | 7 | Giulio Moro | |
41 | 7 | Giulio Moro | 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: |
42 | 2 | Giulio Moro | <pre> |
43 | 2 | Giulio Moro | $ sudo fdisk -u -l /dev/mmcblk0 |
44 | 2 | Giulio Moro | </pre> |
45 | 2 | Giulio Moro | You might get something along the lines of |
46 | 2 | Giulio Moro | <pre> |
47 | 2 | Giulio Moro | Device Boot Start End Blocks Id System |
48 | 2 | Giulio Moro | /dev/mmcblk0p1 * 63 144584 72261 c W95 FAT32 (LBA) |
49 | 1 | Giulio Moro | /dev/mmcblk0p2 144585 3743144 1799280 83 Linux |
50 | 2 | Giulio Moro | </pre> |
51 | 2 | Giulio Moro | You are interested in the higher value in the "End" column. Pass that value to dd as the count parameter: |
52 | 2 | Giulio Moro | <pre> |
53 | 1 | Giulio Moro | $ sudo dd conv=sparse count=3743144 if=/dev/mmcblk0 of=~/bbb_images/your_own_your_precious_backup_image.img |
54 | 4 | Giulio Moro | </pre> |
55 | 4 | Giulio Moro | |
56 | 5 | Giulio Moro | If, instead, you want to backup the entire the SD card, simply use: |
57 | 4 | Giulio Moro | <pre> |
58 | 4 | Giulio Moro | $ sudo dd conv=sparse if=/dev/mmcblk0 of=~/bbb_images/your_own_your_precious_backup_image.img |
59 | 2 | Giulio Moro | </pre> |