Header Image - charles newman's blog

Category Archives

18 Articles

How to back up and restore your Raspberry Pi SD card to your Mac

I periodically take a “snapshot” of my Raspberry Pi’s SD cards, especially before I make a major change, by copying the SD card image to one of my Macs.  Subsequently, that image file gets backed up again by Time Machine running on the Mac. This allows me to return the pi to some determinate state if the card gets corrupted or if I mess something up experimenting.

Note these instructions are for Mac OS X but you can probably figure out other platforms by looking at this page.

These are Terminal commands. Therefore…
DISCLAIMER: if you don’t know what you’re doing on the command line leave this post now. I take no responsibility for you obliterating either your Mac or your SD card. I use both of these procedures on a regular basis but again, you need to understand what you’re doing here, don’t just type away blindly.

Back up the SD card to OS X:

  1. Type “diskutil list” to find the SD Card (it’s helpful to do this before you insert the SD card into your reader, it will be obvious which one is the pi’s SD card). If your Mac doesn’t have an SD card reader you can find a USB card reader fairly cheap, such as this one.
  2. Note the disk number of SD card. I’ll use disk2 in this example.
  3. Type “sudo dd if=/dev/disk2 of=~/Desktop/raspberrypi-[date].img” to create a disc image of the SD card on the desktop.
    Obviously you can supply a directory path there other than Desktop.
    Note: If you are running as a non-admin user on a Mac, type “su <adminusername>” and it will prompt you for the password for that account. This will switch your session to an admin session. Then include the sudo in the command above and type the admin user password again.

Restore the SD card from an OS X back up:

  1. Type “diskutil list” before you insert the card so it’s obvious which one is the SD card.
  2. Insert a blank SD card into the Mac’s SD card reader. If your Mac doesn’t have an SD card reader you can find a USB card reader fairly cheap, such this one.
  3. Type “diskutil list” to find the SD Card to be restored. I’ll use disk2 in this example. Again, you need to know what you’re doing here. Don’t blame me if you wipe out your Mac’s system drive. If you don’t understand these commands don’t type them into a terminal window.
  4. Unmount the SD card with this command: “diskutil unmountDisk /dev/disk2”.
  5. Format the SD Card: “sudo newfs_msdos -F 32 /dev/disk2”. Make damn sure you’ve got the correct disk number.
  6. To restore from the SD card image in the backup sample above: “sudo dd if=~/Desktop/raspberrypi-[date].img of=/dev/disk2”. This may take a very long time and you’ll get no feedback while it’s working. Don’t touch anything until you get the command prompt again, it will give you a summary of the blocks written when it’s complete.

Using an AirPort Express to extend your wifi network

On a whim, I bought an Apple AirPort Express to see if I could extend my wifi signal to my backyard.  My existing setup was an Apple AirPort Extreme connected to an Arris cable modem.  Very solid and reliable, but I wanted to do some geeky stuff with a Raspberry Pi on my property and for that, I needed wifi where my current signal was very poor or non-existent.

I had no idea if this would work, I did zero research, I was at Best Buy to buy a new surround sound amplifier and for some reason came up with this idea.

I opened the AirPort Express box and the directions contained nothing about using the device as a network extender.  So I started searching the Web and got a few ideas.  None of them worked.  Including launching the AirPort utility on my iMac.  It saw the Express, but kept getting a general connectivity error that was of no help.  I tried a lot of things like positioning the Express in the same room as the Extreme and even connecting it via an ethernet cable to the Extreme.  Same error.  I reset the Express with a paper clip and tried again while it was connected via wire.  Same error.

After muttering a few choice words I plugged it into an outlet where I originally started this whole exercise, in a location that would give me the best coverage in the far reaches of my property.  I’m not sure why, because this makes no sense, but I picked up my iPhone and launched “settings” then “wifi”.  The AirPort Express was in the list.  I selected it and it asked me if I wanted to extend my current network!  “Well, hell yes”.  It then prompted me for my wifi password and started working.  It was that easy.  If you launch the AirPort Utility on a Mac or any iOS device you’ll see the wifi routers.

I don’t know why this is such a secret but hopefully someone trying this will find this post before they give up.

 

Mac OS X – change a string in multiple files on the command line

by Charles Newman

Let’s say your team has been using the same license agreement in all source files for the entire year and during a code review someone happens to notice a misspelled word, or maybe the new year has arrived and you want to update the copyright notice.  You can ask the new intern to open all 300 source files in your code repository and change each one, or even better, you can do it on the command line with a single line.

This command, typed into an OS X terminal will recursively change the misspelled word ‘auther’ to ‘author’ in every file with a “.as” extension in the current directory and below:

find . -name ‘*.as’ | xargs perl -pi -e ‘s/auther/author/g’

Mac Ant Build – Error: PermGen space

This is worthy of a post because it took me a while to figure it out.

I created a fairly large Ant build script that kicks off builds for a project’s dependencies and it was working great until I added a few more things. It started failing with this:

[compc] Loading configuration file /Applications/Adobe Flash Builder 4/sdks/4.1.0/frameworks/flex-config.xml
[compc] Error: PermGen space

I’m not a hard core Java guy but I figured this had something to do with the Java Virtual Machine running out of memory. So after digging a bit and trying a few different things the solution I came up with was this:

export ANT_OPTS=-XX:MaxPermSize=512m

Try it on the command line first. If that works for you, you might want to add it to your .bash_profile. Once I added that, my build script was able to complete.

Mac OS X – Quick way to get a long path into a terminal window

by Charles Newman

As noted in this post, there is no way to right-click a folder in the Finder and copy it’s full path to the clipboard. This is an annoying omission in OS X that can make life difficult for software developers and power users.  But I just discovered a neat trick: you can simply drag the folder icon from the Finder into the Terminal window.

So for example, bring up a terminal window and type “cd ” (notice the space after “cd”). Then simply drag your folder from the Finder onto the terminal window, let go and you’ll be ready to hit the return key to change directory to that long path rather than having to type the whole thing out.

Mac OS X – Rename a bunch of files quickly

by Charles Newman

Let’s say I have a bunch of files with the extension “.abc” and I want to change all of them to end with “.doc”.  I can rename each one individually in the Finder, but that could take a long time if there are a lot of files.  Especially considering the warning the Finder gives you about changing the file extension.

A much faster way to do it is to launch the Terminal application, “cd” to the directory where your files exist, and use this command:

for f in *.abc; do mv ./”$f” “${f%abc}doc”; done

All of  your “*.abc” files will be changed to “*.doc”.

Adobe Media Encoder CS4 for Mac – Can’t set the CBR bitrate

by Charles Newman

So you sit down to encode some content at varying bitrates so you can dynamically stream your content. You start with a low bitrate. Then you duplicate that one so you can do another at a higher bitrate with the same settings. But before you hit “Start Queue” you decide to double check that last one and make sure you set the bitrate to what you thought you set it to. But no, it’s set to the first one. You do it a few more times and… …what the f*#%! The bitrate change will not stick! This is an incredibly annoying bug.

The only way I’ve found to make it “stick” is to select VBR, set your desired bitrate, then choose CBR. It sticks when you do that. How this got past the QE’s at Adobe I have no idea.

Mac OS X – Firefox preferences and windows open off screen

If you use two monitors and then remove one, for example from your laptop, you may notice that Firefox thinks the other monitor is still there and opens it’s preferences and windows off screen. To fix this without re-connecting the monitor:

1) Quit Firefox
2) Hold down the option key while you start Firefox
3) Select “Reset toolbars and controls” and click “Make Changes and Restart”.

ff-reset

Mac OS X – show the full path in the Finder window

by Charles Newman

One of the things missing from OS X is the ability to ctrl+click a file and copy it’s full path to the clipboard. It amazes me that this feature is missing from such a robust OS. This tip should make your life easier. You can see the full path in the title bar when you select a file in the Finder.

1) Open a Terminal window and type this command:
defaults write com.apple.finder _FXShowPosixPathInTitle TRUE
Of course replacing TRUE with FALSE will turn this feature off.

2) Restart the Finder:
Cmd+Option click the Finder in the Dock and select "Relaunch"

Note this works from User accounts as well as Admin accounts. No need to “sudo” from within the User account.