Raspberry Pi Revivification, Part 1 

an awful & snarky guide to using "dd" 

August 20th, 2015

Today, my only real goal is to make sure my Raspberry Pi 2 isn't busted from having a wannabe light bulb in its card slot. (You can read about that here.)

To that end, I will be using a spare 4gb MicroSD card and putting a pre-compiled real-time Raspbian kernel on it. I once tried to compile a real-time Linux kernel myself (in fact, I tried to CROSS-COMPILE it on my Mac, because I clearly don't value my own time) and it came to nothing. Thankfully, there's this small autopilot company that uses Raspberry Pis in their systems. And, as it turns out, the real-time needs of autopilot systems are similar (or perhaps even more demanding) as those needed to do nice computer audio.

Read about it and download it from here. (Also check out their products and community programs, especially if you're into taking pictures from drones and so on.)

I'll assume you know how to unzip a zipped file…

Done? Great. Let's do the rest of this from the command line, because Fun. Fire up a terminal.

(I have my terminal set up to look like an awesome monochrome VT220 screen, like the public libraries in San Diego used when I was a kid. You can read about that font, and even download it as a TrueType file, here. Perhaps you'd prefer to put some other typographical anachronism on your machine. Do what feels right.)

Go to wherever your unzipped file is. In my case, I keep a lot of stuff in my Downloads folder on my Mac. So I do: $ cd ~/Downloads. Let's dissect this a bit. the $ is just shorthand for any old *nix (Unix, Posix, Linux, blahblahblah) prompt. Yours may look different depending on how your system is set up. After navigating to the Downloads directory, mine looks like this: Camera-Lucida:Downloads susieSontag$. This tells me that I named my laptop "Camera Lucida", that I'm presently in a directory called "Downloads" and that I am logged in as the user named "susieSontag". GREAT.

Now, connect your SD card reader with your SD card in it. The only card reader I have is my Zoom H4n which takes larger SD cards. Happily, most microSD cards come with an adapter, since physically manipulating AN EXTREMELY DELICATE WAFER OF PLASTIC AND SILICON THE SIZE OF A FINGERNAIL is really no fun.

(I just realized that this is going to be a Mac-centric tutorial, so whatever. For example, the command "diskutil" is specific to Macs. In fact, you really should just follow the tutorial at the Raspberry Pi site itself. You've been warned. Proceed only if you enjoy my snark.)

Back at the terminal, do diskutil list. You'll see a list of attached and mounted disk-type devices and their partitions. Make a note of the name of the device containing your SD card. It will be something like /dev/disk3. It is of extreme importance that you get this right, otherwise you may end up irrevocably overwriting some other hard drive in the steps that follow. To be absolutely sure, you can/should disconnect your card reader and run diskutil again to confirm that the device you wish to write to is no longer connected to your computer. Then you can reconnect it and check YET AGAIN. Or you can run diskutil before connecting your card reader, etc., &c., QED. Computing is fun and dangerous and capricious.

Now you need to unmount said disk. diskutil unmountDisk YOUR_DISK_DEVICE_NAME. This is different than ejecting the disk, which essentially totally disconnects your device from the system.

Great. Now this is the part that can destroy your computer if you do it wrong. Here is the general pattern of the command you should run: sudo dd bs=1m if=NAME_OF_THE_DISK_IMG.img of=YOUR_SD_CARD_READER_DEVICE_NAME. In my case, this was: sudo dd bs=1m if=emlid-raspberrypi2-raspbian-rt-20150327.img of=/dev/disk3. Let's vivisect this. sudo means "super user do". You need to use it to get anything important done on your computer, e.g. sudo rm -rf /. Just kidding. DO NOT RUN THAT LAST COMMAND. Seriously, it means to run the commands that follow it as the system super user — which usually means "root" on proper Linux systems, but in my case, it means susieSontag. The upshot is that you'll have to enter your password. OK. dd is of course the program we're using to transfer the disk image, and all the stuff that follows are parameters that tell it what to do. bs means "block size" and we've set it to what I am informed is a sensible size of 1 megabyte. if is "input file" and of is — wait for it — "onerous facetiousness".

You may be thinking to yourself, "Gosh, using Bash is so inconvenient. Look at how long that file name is! I have to type it all out manually and UGH, WHY LIFE" etc. and so on as your tissue-papery fingers bleed from the exertion. Actually, there is a shortcut for just these situations. You only have to type in as many letters of filenames or directories as needed to distinguish it from other filenames or directories, then you can press Tab and Bash will fill in the rest. Neat, huh?

Take a deep breath and press Return or Enter or whatever it is in the parlance of our times. You will see: nothing. dd is a very simple program (so far as UI is concerned) and doesn't really seem to have a "verbose" mode that shows you what its doing. HOWEVER. You can do ctrl+T which in Bash (that's the shell we're using in our terminal, and the one that's default in OS X) environments gets translated as SIGINFO and to which dd will respond with things like

load: 1.79  cmd: dd 84658 uninterruptible 0.00u 2.27s
250+0 records in
249+0 records out
261095424 bytes transferred in 59.209938 secs (4409655 bytes/sec)

Are you feeling enlightened yet? Anyway, with my USB 2 connection, transferring the 3.5gb disk image took this long: 3303014400 bytes transferred in 747.506025 secs (4418713 bytes/sec). That's what dd spits out at the end of its arduous task.

I gently moved THE EXTREMELY DELICATE WAFER OF PLASTIC AND SILICON THE SIZE OF A FINGERNAIL (hereafter referred to as "TEDWOPASTSOAF") to its new home in the Raspberry Pi 2 and applied power. Lights blinked as I know them to blink when the Pi is happy, as did the ethernet port lights when I connected it to my laptop. I can't be bothered to plug a monitor into it right now because I really just want to finish this extremely long post and get on with non-necromantic things today.

We'll see if it worked TOMORROW, when I'll guide you through one of my arbitrarily difficult tasks which I set for myself in order to Generally Improve my Knowledge of Being a Sysadmin. Specifically, I will be using a virtual machine running Ubuntu to access the SD card so that I can set up ethernet networking without ever having to plug a monitor or keyboard into the Pi itself. Or not. I may get lazy and just use a monitor and keyboard like a Person Who Values Their Own Time.

Can you tell that I get moody when I think about how many hours of time I lost when I destroyed TEDWOPASTSOAF?