I’ve been tinkering around with a flexible little micro-processor called RaspberryPi for a few weeks now and would like to share some instructions on how to get it running.
The Raspberry Pi is a $35 linux computer, it fits in the palm of your hand and is a handy bit of hardware for prototyping your ideas that need both software/hardware experimentation. The first thing that I’ve been exploring is the different operating systems that are available for the rPi. There are a lot to choose, 28 at last count according to this list, I’ve been playing with Raspian (Debian, a light Linux system configured specifically for Raspberry Pi) and Occidentalis, Adafruit’s educational distribution that has a number of sensors enabled out of the box.
To get your Raspberry Pi working with these OS’s you’ll need to download them and put them on a Flash Card. They need to be transfered over in a very particular way. The following instructions walk you through the best way to install an operating system on a 8 or 16g flash card.
- These commands and actions need to be performed from an account that has administrator privileges on a mac.
- Download the image from a mirror or torrent
- Verify if the the hash key is the same (optional), in the terminal run:
Extract the image:
(or: just double click the zip, it will extract automatically)
- From the terminal run df -h
- Connect the SD card reader with the SD card inside
- Run df -h again and look for the new device that wasn’t listed last time. Record the device name of the filesystem’s partition, for example, /dev/disk3s1
- Unmount the partition so that you will be allowed to overwrite the disk:
- sudo diskutil unmount /dev/disk3s1
- (or: open Disk Utility and unmount the partition of the SD card (do not eject it, or you have to reconnect it)
- Using the device name of the partition work out the raw device name for the entire disk, by omitting the final “s1” and replacing “disk” with “rdisk” (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, rdisk3, not rdisk3s1. Similarly you might have another SD drive name/number like rdisk2 or rdisk4, etc. — recheck by using the df -h command both before & after you insert your SD card reader into your Mac if you have any doubts!):
- For example, /dev/disk3s1 => /dev/rdisk3
- In the terminal write the image to the card with this command, using the raw disk device name from above (read carefully the above step, to be sure you use the correct rdisk# here!):
- sudo dd bs=1m if=~/Downloads/2012-10-28-wheezy-raspbian/2012-10-28-wheezy-raspbian.img of=/dev/rdisk3
- if the above command report an error(dd: bs: illegal numeric value), please change bs=1M to bs=1m
- (note that dd will not feedback any information until there is an error or it is finished, information will show and disk will re-mount when complete. However if you are curious as to the progresss – ctrl-T (SIGINFO, the status argument of your tty) will display some en-route statistics).
- After the dd command finishes, eject the card:
- sudo diskutil eject /dev/rdisk3
- (or: open Disk Utility and eject the SD card)
- Insert it in the Raspberry Pi, and have fun
Dubbing existing cards
Additionally, it’s worth noting that the dd command can be used to duplicate the files of a working flashcard into a disk image. Here’s how:
If you want to preserve all of the data in your RaspberryPi SD card, you will have to create a disk image. And, Windows or Mac cannot recognize typical Linux filesystems, so you probably won’t even be able to see your files, when you plug in your SD card.
Creating a disk image will preserve not only files but also the filesystem structure and when you decide to flash your new SD card, you will be able to just plug it in and it will work.
On Mac, you can also use the standard dd tool with a slightly different syntax:
dd if=/dev/rdiskx of=/path/to/backup.img bs=1m
sudo dd bs=1m of=~/Desktop/2013-occidentalis.img if=/dev/rdisk2
Where /dev/diskx is your SD card.
Or, with gzip, to save a substantial amount of space:
sudo dd if=/dev/rdisk1 bs=1m | gzip > /path/to/backup.gz
And, to copy the image back onto the SD:
gzip -dc /path/to/backup.gz | sudo dd of=/dev/rdisk1 bs=1m
sudo dd bs=1m if=~/Desktop/2013-occidentalis.img of=/dev/rdisk2