- Raspberry Pi for Secret Agents(Third Edition)
- Matthew Poole
- 957字
- 2021-07-14 11:09:57
Backing up your SD card
It happens to everyone at one point or another—you've put hours into perfecting your Raspbian installation, setting up applications, and hacking away at clever code, when out of nowhere your cat/dog/next-of-kin swoops down on your keyboard and triggers the self-destruct mechanism from the Erasing the Pi should it fall into the wrong hands section in Chapter 5, Taking Your Pi Off-Road.
Not to worry, Agent, backing up an SD card is quite simple as long as you've got the required disk space to store it.
Complete SD card backup in Windows
We'll be making a complete mirror image of your SD card. The data will be stored in a single file that will be the same size as that of your SD card. To do this, we'll use the Win32 Disk Imager application we installed earlier on to create our SD card image:
- Power off your Pi safely by running the following command and wait for the green activity LED to stop flickering:
$ sudo shutdown -h now
- Move the SD card to your computer's card reader.
- Start the Win32 Disk Imager application on your PC.
- Ensure that the correct volume of your SD card is shown under Device.
- Click on the folder icon and navigate to the folder where you'd like to store the image.
- Enter a good file name for your image and click on Open. The standard file extension for image files is
.img
. - Finally, after verifying that the full Image File path looks good, click on Read:
Once your image backup has completed successfully, you can compress it to save quite a bit of disk space. Just right-click on the image file and select Send to, then click on Compressed (zipped) folder.
Complete SD card backup in MAC OS X
We'll be making a complete mirror image of your SD card. The data will be stored in a single compressed file, which should result in a smaller size than that of your SD card. The steps to be followed for a data backup are as follows:
- Power off your Pi safely by running the following command and wait for the green activity LED to stop flickering:
$ sudo shutdown -h now
- Move the SD card to your computer's card reader.
- Open up a terminal (located in
/Applications/Utilities
on the Mac). - Type
diskutil
list
to obtain a readout of all connected storage devices. - To correctly identify your SD card, we're looking for a disk that has at least one Windows and one Linux entry under TYPE (there will be two of each type if we installed Raspbian through NOOBS).
- Take note of that disk's first IDENTIFIER field (disk1 in the screenshot).
- As a security precaution, we will first unmount the SD card so that no applications running in the background can change data as we make our backup. Use the following command, but replace
[disk]
with the IDENTIFIER field of your SD card:$ diskutil unmountdisk [disk]
- Now we'll do a complete copy of the SD card and store it in a file called
agent_sdcard.img.gz
on your desktop. Type the following command, but replace[disk]
with the IDENTIFIER field of your SD card (note the letter r in front of disk):$ sudo dd if=/dev/r[disk] bs=4m | gzip > ~/Desktop/agent_sdcard.img.gz
- You might be asked to input your user password so that
sudo
is allowed to start. The backup process doesn't produce much output as it runs, but a status report can be produced by pressing Ctrl + T in theTerminal
window:Backing up an SD card in Mac OS X
To restore your SD card from a backup image, repeat the previous steps, but use this command instead at step 7:
$ gzip -dc ~/Desktop/agent_sdcard.img.gz | sudo dd of=/dev/r[disk] bs=4m
Tip
If you type the wrong disk you could potentially overwrite your Mac's internal hard drive without any warning. Do triple-check!
Complete SD card backup in Linux
We'll be making a complete mirror image of your SD card. The data will be stored in a single compressed file, which should result in a smaller size than that of your SD card:
- Power off your Pi safely by running the following command, and wait for the green activity LED to stop flickering:
$ sudo shutdown -h now
- Move the SD card to your computer's card reader.
- Open up a terminal session (Ctrl + Alt + T).
- Type
sudo lsblk -f
to obtain a readout of all connected storage devices. - To correctly identify your SD card, we're looking for a disk that has at least one
vfat
and oneext4
entry underFSTYPE
(there will be two of each type if we installed Raspbian through NOOBS). - Take note of that disk's
NAME
(sdb
in the screenshot). - If any of the partitions under your disk's
NAME
have aMOUNTPOINT
listed, you should unmount it first. Use the following command, but replace[mountpoint]
with the mountpoint of your partition:$ sudo umount [mountpoint]
- Now we'll do a complete copy of the SD card and store it in a file called
agent_sdcard.img.gz
in yourhome
directory. Type the following command, but replace[disk]
with theNAME
of your SD card:$ sudo dd if=/dev/[disk] bs=4M | gzip > ~/agent_sdcard.img.gz
- The backup process doesn't produce much output as it runs, but a status report can be produced by typing
sudo
pkill
-USR1
dd
in anotherterminal
console:Backing up an SD card in Linux
To restore your SD card from a backup image, repeat the previous steps, but use this command instead at step 7:
$ gzip -dc ~/agent_sdcard.img.gz | sudo dd of=/dev/[disk] bs=4M
Tip
If you type the wrong disk you could potentially overwrite your computer's internal hard drive without any warning. Do triple-check!
- 數據庫程序員面試筆試真題與解析
- Mastering phpMyAdmin 3.4 for Effective MySQL Management
- R語言數據可視化實戰
- Magento 1.8 Development Cookbook
- Mastering Android Development with Kotlin
- OpenStack Orchestration
- Natural Language Processing with Java and LingPipe Cookbook
- ServiceNow:Building Powerful Workflows
- 計算機應用基礎教程(Windows 7+Office 2010)
- Struts 2.x權威指南
- 深入實踐DDD:以DSL驅動復雜軟件開發
- PHP 8從入門到精通(視頻教學版)
- Penetration Testing with the Bash shell
- 零基礎學C++(升級版)
- SCRATCH編程課:我的游戲我做主