I’m going to briefly explain how to setup a new Raspberry Pi as a basic desktop computer with file sharing and screen sharing so that Macs can connect to it. This will be useful for quickly transferring files over, and taking control of the Pi remotely. I will be assuming that you have basic command line knowledge (running commands, installing packages, editing text files), and some Mac knowledge. I am not going to be too paranoid about security as I only intend on using my Pi on my home network, but if your Pi is going to be Internet-facing, you may want to read up elsewhere on securing your Pi.
Installing the Raspbian image onto the SD card
- Download the raw Raspbian image from Raspberry Pi website.
- Use Mac’s Disk Utility to format the SD card into one FAT partition.
- Download RPi-sd card builder. Use it to load the Raspbian image onto the SD card. (It will take a while… don’t take the SD card out until you get the final prompt and the cogwheel stops spinning in the menu bar)
- Plug the SD card into the Pi and boot up.
- Use the raspi-config tool that starts the first time you boot up to set the following options:
- Expand the root partition to fill the disk
- Enable SSH
- Start desktop on boot
- Change the hostname
- Change the default password
- Reboot the Pi, you should get into the desktop.
Setting up file sharing (AFP) and screen sharing (VNC)
- On the Raspberry Pi, open up LXTerminal.
- In LXTerminal, execute
sudo apt-get install netatalk x11vncto install the necessary packages. (You may need to execute
sudo apt-get updateto update the package list if it complains about missing packages.)
x11vnc -storepasswdto setup the password required for your screen sharing connections.
- In order for the VNC server to start up at each boot, create the following file in
[Desktop Entry] Encoding=UTF-8 Type=Application Name=X11VNC Comment= Exec=x11vnc -forever -usepw -display :0 -ultrafilexfer StartupNotify=false Terminal=false Hidden=false
- To register the VNC server as a Bonjour service, create the following file in
/etc/avahi/services/rfb.service(you will need to save the file as root, so use sudo before opening your editor).
<?xml version="1.0" standalone='no'?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">%h</name> <service> <type>_rfb._tcp</type> <port>5900</port> </service> </service-group>
If you don’t see an /etc/avahi folder, you may need to install the avahi package separately — recent netatalk packages will install avahi as a dependency, so if you’re doing a new install it shouldn’t be a problem.
- Reboot. You should then be able to go into Finder and find your Raspberry Pi on the network. File sharing and screen sharing should be accessible as well.
After doing some customization of the Raspberry Pi, you may want to take a backup of it so that in case the SD card gets corrupted, you can easily restore the image. I found an excellent guide on this blog post. Summarizing it quickly:
- Plug the SD card into the Mac.
- In Terminal, execute
diskutil listto find your SD card make note of the disk number (/dev/diskX)
- Then execute the following command for a backup:
sudo dd if=/dev/rdiskX bs=1m | gzip > /path/to/backup.img.gz
Replace the X with your disk number that you found in the previous step. Note the ‘r’ in
/dev/rdiskXis intentional to take advantage of better performance (see the blog post I linked for details).
- For a restore, the command would be:
gzip -dc /path/to/backup.img.gz | sudo dd of=/dev/rdiskX bs=1m
That’s it! This was a quick overview of getting a Raspberry Pi setup and talking with Macs for easy file transfers and remote control, and also backed up in case something bad happens.