Baremetal dd » Historie » Version 2
Jeremias Keihsler, 12.01.2017 15:39
1 | 1 | Jeremias Keihsler | h1. dd disaster recovery |
---|---|---|---|
2 | |||
3 | h2. Backup (make image of system) |
||
4 | |||
5 | h3. Requirements |
||
6 | |||
7 | To install such a system you will need the following: |
||
8 | |||
9 | * A working linux system with SD-card-reader |
||
10 | * root access |
||
11 | |||
12 | h3. Preliminary Note |
||
13 | |||
14 | This information is taken from [[http://elinux.org/RPi_Easy_SD_Card_Setup]] |
||
15 | |||
16 | Please note that the use of the "dd" tool can overwrite any partition of your machine. If you specify the wrong device in the instructions below you could delete your primary Linux partition. **Please be careful!** |
||
17 | |||
18 | <pre><code class="bash"> |
||
19 | dd bs=4M if=/dev/mmcblk0 of=~/2012-10-28-wheezy-raspbian_140107.img |
||
20 | </code></pre> |
||
21 | |||
22 | alternative compressed image |
||
23 | <pre><code class="bash"> |
||
24 | dd bs=4M if=/dev/mmcblk0 | gzip > ~/2012-10-28-wheezy-raspbian_140107.img.gz |
||
25 | </code></pre> |
||
26 | |||
27 | 2 | Jeremias Keihsler | h2. Restore the system |
28 | 1 | Jeremias Keihsler | |
29 | # Run @df -h@ to see what devices are currently mounted |
||
30 | # If your computer has a slot for SD cards, insert the card. If not, insert the card into an SD card reader, then connect the reader to your computer. |
||
31 | # Run @df -h@ again. The device that wasn't there last time is your SD card. The left column gives the device name of your SD card. It will be listed as something like "/dev/mmcblk0p1" or "/dev/sdd1". The last part ("p1" or "1" respectively) is the partition number, but you want to write to the whole SD card, not just one partition, so you need to remove that part from the name (getting for example "/dev/mmcblk0" or "/dev/sdd") as the device for the whole SD card. Note that the SD card can show up more than once in the output of df: in fact it will if you have previously written a Raspberry Pi image to this SD card, because the Raspberry Pi SD images have more than one partition. |
||
32 | # Now that you've noted what the device name is, you need to unmount it so that files can't be read or written to the SD card while you are copying over the SD image. So run the command below, replacing "/dev/mmcblk0" with whatever your SD card's device name is (including the partition number) |
||
33 | 2 | Jeremias Keihsler | ## @umount /dev/mmcblk0p1@ |
34 | ## If your SD card shows up more than once in the output of df due to having multiple partitions on the SD card, you should unmount all of these partitions. |
||
35 | 1 | Jeremias Keihsler | # In the terminal write the image to the card with this command, making sure you replace the input file @if=@ argument with the path to your .img file, and the "/dev/mmcblk0" in the output file @'of=@' argument with the right device name (@'this is very important:@' you @'will@' lose all data on the hard drive on your computer if you get the wrong device name). Make sure the device name is the name of the whole SD card as described above, not just a partition of it (for example, sdd, not sdds1 or sddp1, or mmcblk0 not mmcblk0p1) |
36 | 2 | Jeremias Keihsler | ## @dd bs=4M if=~/2012-10-28-wheezy-raspbian.img of=/dev/mmcblk0@ |
37 | Please note that block size set to 4M will work most of the time, if not, please try 1M, although 1M will take considerably longer. |
||
38 | ## The dd command does not give any information of its progress and so may appear to have frozen. It could take more than five minutes to finish writing to the card. If your card reader has an LED it may blink during the write process. To forcibly stop the copy operation you can run @pkill -USR1 -n -x dd@ in another terminal. |
||
39 | 1 | Jeremias Keihsler | # Instead of dd you can use dcfldd; it will give a progress report about how much has been written. |
40 | # You can check what's written to the SD card by dd-ing from the card back to your harddisk to another image, and then running diff (or md5sum) on those two images. There should be no difference. |
||
41 | # Run the command @sync@ (this will ensure the write cache is flushed and that it is safe to unmount your SD card) |
||
42 | # Remove SD card from card reader, insert it in the Raspberry Pi, and have fun |
||
43 | |||
44 | alternative compressed image |
||
45 | <pre><code class="bash"> |
||
46 | gzip -dc ~/2012-10-28-wheezy-raspbian_140107.img.gz | dd of=/dev/mmcblk0 |
||
47 | </code></pre> |