Configuring wifi for your Raspberry Pi using your Mac

This walkthrough assumes a pretty simple set up – and in my case I just grabbed a “latest wheezy SD card” off Amazon. I booted once with an ethernet connection so I could do the initial Raspi-config steps.

Caveat: backup your files!

Next I powered down, plugged in the wifi usb dongle – but then how do I tell the Pi which network to connect to?

I know that my Raspberry Pi won’t always connect to the same wifi connection, so I wanted a simple way to quickly add a new SSID and credentials using my Mac. Ideally I could swap the SD card in to my mac, make a small change, then drop it back to the Pi. This is a short walkthrough explaining how to do just that.

Note there is an alternative process that doesn’t require Fuse which I’ve included in the footer of this post.

Alternatively…

I’ve decided to put this solution up first since it’s the least destructive! If you can avoid using Fuse, then it’s worth it.

If you don’t like the idea of messing with the main partition that the Pi runs with on your mac, you can just make a simple change during your initial setup. Edit /etc/network/interfaces and change the wpa-roam to point to a location no your /boot partition, ie.:

wpa-roam /boot/wpa_supplicant.conf

The /boot partition is the one that’s read and writable by default without needing Fuse. Now you can put your wpa_supplicant.conf file in the root of this directory, and you can quickly add new networks for your Pi to connect to.

1. Install Fuse

Fuse for OSX with the MacFuse compatibiltiy layer enabled during installation.

You also need to install fuse-ext2 – which doesn’t come with Fuse for OSX.

2. Change fuse mount to read/write

By default (I found), the SD card’s 2nd mounted drive (i.e. the Pi drive) would have read-only permissions set (you can see this if you cmd+i on the drive – mine was called “disk1s2″).

This means we can’t modify anything, but let’s change that. On your Mac, in the terminal, run:

sudo sed -e 's/OPTIONS="auto_xattr,defer_permissions"/OPTIONS="auto_xattr,defer_permissions,rw+"/' -i .orig /System/Library/Filesystems/fuse-ext2.fs/fuse-ext2.util

This tip comes from Google Groups which also explains how to revert that change. Note that you’re now forcing all mounted drives with Fuse to be read/write.

Important you could (like I did) slightly corrupt the drive by mounting it on the Mac. I had to run a fsck -y /dev/root to fix it – but it had to be attached to my TV and with my backup usb keyboard (which frankly I could have thrown away years ago). Equally, you can edit /etc/default/rcS and set FSCKFIX=yes so it’ll fix itself in headless mode (via ask Ubuntu).

3. Edit wpa_suppliment

Now, from your Mac you can edit the Pi drive, which means write access to /etc. So (again, I had a default set up, you may need a few more steps than this – Google is your friend).

Append the network you want to connect to the file /etc/wpa_supplicant/wpa_supplicant.conf.

network={
   ssid="<MY_SSID>"
   proto=RSN
   key_mgmt=WPA-PSK
   pairwise=CCMP TKIP
   group=CCMP TKIP
   psk="<MY_SSID_PASSWORD>"
}

4. Boot your Pi

If the Pi can see the network you specified, it should be able to connect to it.

Now the question is how do you get the IP address of your Pi to connect over ssh. I’m thinking about having it automatically email me it’s IP which can be determined using:

/sbin/ifconfig wlan0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'

Then (and this isn’t tested…yet), I can add a script to /etc/network/if-up.d/ to email me the address:

#!/bin/bash

# Ignore the loopback
[ "$IFACE" != "lo" ] || exit 0

/sbin/ifconfig wlan0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' | mail -s 'Pi online' [email protected]

Mailing isn’t quite as easy as that, but that’s your problem to solve. I did it with nodemailer and some JavaScript (which was basically the example code).

4 Responses to “Configuring wifi for your Raspberry Pi using your Mac”

  1. Thanks for the tip! It’s worth noting that if you download fuse, you will have to download fuse-ext2.util separately, as described in the google group you linked to.

  2. Fabrizio Bartolomucci June 15th, 2013 at 8:47 am

    I followed instructions but now not even the lan works and I am totally stuck outside given I have no keyboard nor video to attach. What may I do? I have all my file inside not expecting such a problem.

  3. Chris Clearfield July 27th, 2013 at 7:11 am

    Just a heads up — I followed these instructions with OS 10.7.5, and totally hosed the pi.

    Files that I edited were strangely deleted after I unmounted the disk. I think fuse is in read only mode for a reason. :)

  4. You could also run a Linux virtual machine using VirtualBox on your Mac. Plug the SD card into a USB SD card reader, and tell VirtualBox that the Linux VM “owns” the USB SD card reader. The Linux VM should be able to mount the ext4 filesystem with no trouble at all.

    If you don’t want to create a fully installed Linux VM for this purpose, download a “Live CD” image of something like Ubuntu and boot it under VirtualBox. You won’t even need to allocate a disk for the VM. Just boot live, connect the USB reader, mount the SD card and change your files.

    Alan Porter

Leave a Reply
Not required

CODE: Please escape code and wrap in <pre><code>, doing so will automatically syntax highlight