Jul 21, 2014

Make a copy of your SD card: Raspberry Pi drive recorder with GPS logger

With previous steps, we installed required hardware/software and finished basic configuration so we can now take photo, shoot video, output data to external touchscreen and fetch location data. Before writing some Python code to let those modules work together, I think we should take some time to make a copy of the disk we worked on. This way, even if you make a huge mistake in the near future and everything is messed up, you can install this saved disk image and start from where we are now. It's just like playing your favorite RPG. You don't wanna start from scratch, right?

Making a copy

Just like when we installed Raspbian OS to empty SD card, we use dd command to make a disk image. You insert your SD card to your iMac and hit `diskutil list` to see which disk we are going to use. Then execute `sudo dd if=/dev/disk1 of=Odyssey-Mk1_20140721.dmg`. You should change 'if(input file)' and 'of(output file)' value to suit your environment and preference. My 8GB SD card took 20-30 minutes to complete. It will be longer if you have SD card with larger space.
Oklahomer@Oklahomers ~ » diskutil list
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *1.0 TB disk0
1: EFI EFI 209.7 MB disk0s1
2: Apple_HFS Macintosh HD 999.3 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
/dev/disk1
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *8.1 GB disk1
1: Windows_FAT_32 boot 58.7 MB disk1s1
2: Linux 8.0 GB disk1s2
Oklahomer@Oklahomers ~ » cd proj
Oklahomer@Oklahomers ~/proj » sudo dd if=/dev/disk1 of=Odyssey-Mk1_20140721.dmg
Password:
15759360+0 records in
15759360+0 records out
8068792320 bytes transferred in 1534.748566 secs (5257403 bytes/sec)
Oklahomer@Oklahomers ~/proj » ls -lh Odyssey-Mk1_20140721.dmg
-rw-r--r-- 1 root staff 7.5G 7 21 14:59 Odyssey-Mk1_20140721.dmg
Oklahomer@Oklahomers ~/proj » diskutil eject /dev/disk1
Disk /dev/disk1 ejected

Installing

When you want to install the saved disk image, the process is almost the same as when we installed Raspbian to a fresh SD card. First you insert an SD card that you want to install this disk image to. Then unmount this just like the initial installation. Then `sudo dd if=Odyssey-Mk1_20140721.dmg of=/dev/disk1`. Again, you must set 'if ' and 'of' value to suit your environment.
Oklahomer@Oklahomers ~/proj » sudo dd if=Odyssey-Mk1_20140721.dmg of=/dev/disk1
Password:
15759360+0 records in
15759360+0 records out
8068792320 bytes transferred in 6044.582938 secs (1334880 bytes/sec)
Oklahomer@Oklahomers ~/proj » diskutil eject /dev/disk1
Disk /dev/disk1 ejected
It takes longer than making an OS image. In my case it took me more than 2 hours. You must be really patient.

My trick

If your SD card has larger space and you have chosen to 'Expand Filesystem' on the initial configuration, both steps take longer time to complete. So I make my 8GB SD card to be a master and make a copy of it. This way it doesn't have to copy each and every byte of 64GB. Then I install this to Micro SD card with larger volume. Right after this installation, this Micro SD card only utilizes 8GB of the entire space because I made a copy of 8GB SD card.
Oklahomer@Oklahomers ~/proj » ssh pi@192.168.0.4
pi@192.168.0.4's password:
Linux raspberrypi 3.6.11+ #26 PREEMPT Tue Nov 26 18:19:51 SGT 2013 armv6l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Jul 21 04:55:04 2014 from 192.168.0.2
pi@raspberrypi ~ $ df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 7.4G 2.3G 4.8G 33% /
/dev/root 7.4G 2.3G 4.8G 33% /
devtmpfs 180M 0 180M 0% /dev
tmpfs 38M 216K 38M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 75M 0 75M 0% /run/shm
/dev/mmcblk0p1 56M 21M 36M 38% /boot
view raw gistfile1.txt hosted with ❤ by GitHub
So I `sudo raspi-config` again and choose 'Expand Filesystem' to utilize all spaces left.
pi@raspberrypi ~ $ df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 59G 2.3G 54G 5% /
/dev/root 59G 2.3G 54G 5% /
devtmpfs 180M 0 180M 0% /dev
tmpfs 38M 216K 38M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 75M 0 75M 0% /run/shm
/dev/mmcblk0p1 56M 21M 36M 38% /boot
view raw gistfile1.txt hosted with ❤ by GitHub