Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Raspberry Pi for Secret Agents - Second Edition

You're reading from   Raspberry Pi for Secret Agents - Second Edition Turn your Raspberry Pi into your very own secret agent toolbox with this set of exciting projects

Arrow left icon
Product type Paperback
Published in Jan 2015
Publisher
ISBN-13 9781784397906
Length 206 pages
Edition 2nd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Stefan Sjogelid Stefan Sjogelid
Author Profile Icon Stefan Sjogelid
Stefan Sjogelid
Arrow right icon
View More author details
Toc

Table of Contents (7) Chapters Close

Preface 1. Getting Up to No Good FREE CHAPTER 2. Audio Antics 3. Webcam and Video Wizardry 4. Wi-Fi Pranks – Exploring Your Network 5. Taking Your Pi Off-road Index

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.

  1. Power off your Pi safely and move the SD card to your computer's card reader.
  2. Visit http://sourceforge.net/projects/win32diskimager/ and download the latest version of the Win32 Disk Imager application (Win32DiskImager-0.9.5-install.exe at the time of writing).
  3. Install the application by running the installer.
  4. Start Win32DiskImager from the shortcut in your Start menu.
    Complete SD card backup in Windows

    Backing up an SD card in Windows

  5. Ensure that the correct volume of your SD card is shown under Device.
  6. Click on the folder icon and navigate to the folder where you'd like to store the image.
  7. Enter a good file name for your image and click on Open. The standard file extension for image files is img.
  8. 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.

To restore your SD card from a backup image, simply point Win32 Disk Imager to your image file, and click on the Write button.

Tip

Win32 Disk Imager is also used to write the operating system images available for download at http://www.raspberrypi.org/downloads directly to the SD card without using NOOBS.

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:

  1. Power off your Pi safely and move the SD card to your computer's card reader.
  2. Open up a terminal (located in /Applications/Utilities on the Mac).
  3. Type diskutil list to obtain a readout of all connected storage devices.
  4. 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).
  5. Take note of that disk's first IDENTIFIER field (disk1 in the screenshot).
  6. 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]
    
  7. 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
    
  8. 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 the Terminal window.
    Complete SD card backup in MAC OS X

    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

Note

If you type the wrong disk you could potentially overwrite your Mac's internal hard drive without any warning. Do triple check!

Tip

The restore image method is also used to write the operating system images available for download at http://www.raspberrypi.org/downloads directly to the SD card without using NOOBS.

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.

  1. Power off your Pi safely and move the SD card to your computer's card reader.
  2. Open up a terminal.
  3. Type sudo lsblk -f to obtain a readout of all connected storage devices.
  4. To correctly identify your SD card, we're looking for a disk that has at least one vfat and one ext4 entry under FSTYPE (there will be two of each type if we installed Raspbian through NOOBS).
  5. Take note of that disk's NAME (sdb in the screenshot).
  6. If any of the partitions under your disk's NAME have a MOUNTPOINT listed, you should unmount it first. Use the following command, but replace [mountpoint] with the mountpoint of your partition:
    $ sudo umount [mountpoint]
    
  7. Now we'll do a complete copy of the SD card and store it in a file called agent_sdcard.img.gz in your home directory. Type the following command, but replace [disk] with the NAME of your SD card:
    $ sudo dd if=/dev/[disk] bs=4M | gzip > ~/agent_sdcard.img.gz
    
  8. 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 another terminal console.
    Complete SD card backup in Linux

    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

Note

If you type the wrong disk you could potentially overwrite your computer's internal hard drive without any warning. Do triple check!

Tip

The restore image method is also used to write the operating system images available for download at http://www.raspberrypi.org/downloads directly to the SD card without using NOOBS.

You have been reading a chapter from
Raspberry Pi for Secret Agents - Second Edition - Second Edition
Published in: Jan 2015
Publisher:
ISBN-13: 9781784397906
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at AU $24.99/month. Cancel anytime