I’ve a few Raspberry Pis which I run Headless (without their own screen and keyboard) from my Apple Mac using a combination of Finder, VNC and SSH to run the applications. I recently decided to upgrade one of them (a Pi3) to Stretch to see if it was any better (and to play with the latest version of Sonic Pi).
Having tried to upgrade from Jessie to Stretch using the instructions here (https://www.raspberrypi.org/blog/raspbian-stretch/) and failed miserably as the system hung at various places in the upgrade, I decided I would create a new system on a brand new SD Card and start all over again.
Previously, I’ve created put NOOBS onto the SD card and created the system from scratch using a screen and keyboard. This time I thought I would do it all without the need to unpack the keyboard and mouse and to occupy the family TV for a while.
Easier said than done. However, eventually I worked it all out and, having looked around the web, realised that most people in the Raspberry Pi community don’t use Apple Macs and those that do seem to know a lot more about using them than I do.
Here’s how I did it, step by step.
Although you won’t need a screen or keyboard, you will need to connect the Raspberry Pi to your network using an Ethernet Cable (I have a feeling that you might be able to get it connected to the network using WiFi but I found that step easier to do as part of the Raspberry Pi Configuration after the software was up and running).
You’ll also need to have an SDFormatter Application installed on your Mac.
Most of the work uses terminal on the Mac, either directly on the Mac or through SSH to the Raspberry Pi so its best if you are relatively familiar with that as well.
- Use SD Formatter to format your SD Card. Eject the SD Card and remove it from your Apple Mac.
- Open Safari and head to raspberrypi.org/downloads and click on the latest version. Click Download ZIP under Raspbian (the full version, not the Lite version). (For the sake of argument lets call this “2017-xxx.img”)
- Open Terminal.
- Enter “diskutil list“. You will see a list of all your drives. If you’re using a Mac with just one hard drive, then two appear: /dev/disk0 and /dev/disk1. If you have external hard drives, or more volumes, then there will be more drives.
- Connect the Micro SD Card to your Mac.
- Enter “disktuil list” again. Check carefully to locate the new disk. It will be one more on from the last list (ours is /dev/disk2) and have “(external, physical)” after it. Check that its SIZE matches the SD Card. It’s important that you get this right so you don’t end up overwriting content on the wrong drive.
- Enter sudo diskutil unmountDisk /dev/disk[n] (replacing with the number of the disk, e.g.: /dev/disk2).
- Enter this carefully: sudo dd bs=1m if=~/Downloads/2017-xxx.img of=/dev/rdisk[n] – replacing [n] with the number of the disk
- Tip: you can use tab to expand file paths in Terminal. Enter “if=~/Downloads/2 ” and press Tab to get the rest of the filename (you may need to add “img” to the end).
The image file will be copied to the SD Card. You won’t get any feedback while it copies, and it can take several minutes. Leave Terminal to do its thing (I find its best to make a cup of coffee because on my machine a 32Gb disk can take about 45 minutes).
- When the copy finishes enter sudo diskutil eject /dev/disk[n] to eject the disk.
- Remove the disk and its holder from the mac and then re-insert.
- Open Finder and there should be a disk called boot.
- Open Text Edit and create a new file called ssh in the boot disk. (Text editor will add an extension .rtf to the file, you’ll need to remove the extension. (I’ve created a suitable file on my Mac so I can just copy it across to the boot disk).
- Put the disk into the raspberry pi, connect it to the ethernet network using a cable and power it up.
- You should now see raspberrypi on the network. (I open finder and browse the network using cmd K)
- At this point you may be able to ssh to the Raspberry Pi by ssh firstname.lastname@example.org. However, if you’ve had other raspberrypi hosts on your network in the past there will be a security issue so you’ll need to:
- cd /Users/youruser/.ssh
- ls (to check for known_hosts)
- rm known_hosts (remove known_hosts file) now when you connect to any remote host it will ask you to re-verify.
- Now you can carry out the rest of the configuration through sudo raspi-config
- Change the hostname (choose a new name)
- Change the password for the pi user (for security)
- enable WiFi (you’ll need to know the Network SSiD and Password)
- Enable VNC
- Enable 1-wire
- Enable the Camera
- Set the screen resolution (to 1024×768) (DMT Mode 16)
- Enable Netatalk to allow the Mac Finder to access the Pi as follows:
- sudo apt-get update
- sudo apt-get install netatalk
- Stop the netatalk service (sudo /etc/init.d/netatalk stop)
- Now, in order to keep track of what you’re looking at from your hosting Mac, I find it best to change the name of the host volume. (sudo nano /etc/netatalk/AppleVolumes.default)
- Then scroll down to the bottom to find ~/ “Home Directory” and change the text in quotes to whatever you want. I find it best to change it to the same name as the Raspberry Pi Hostname.
- Finally restart netatalk and the Raspberry Pi will appear in the list of shared devices in Finder (sudo /etc/init.d/netatalk start)
- Finally reboot the Raspberry Pi (sudo reboot).
Now you should be able to see the Raspberry Pi under the new Hostname on your network and be able to connect to it using SSH in terminal, VNC, and Finder.