I recently received my second Raspberry Pi from Newark Element 14 and I was looking at all the possible projects found on various sites around the web. I made a NAS device and a XBMC client, but it was when I came across an article on creating a TimeCapsule for MacBooks I knew I had my next project.
I read and tried many of the procedures outlined on various websites. In the end, I had to create a custom procedure to suit my needs.
What I wanted was a TimeCapsule for two MacBook Pros to access wirelessly for two different users on separate partitions. I wanted it to be low power, compact, headless with access via SSH and VNC, use a 1TB external hard drive, work with OSX Mavericks, and be connected to the network via Ethernet.
Here is my procedure:
After installing Raspian I prepared it to work headlessly by assigning my Pi a fixed IP address on my home
router. You will have to look up how to do this for your specific router. This was to ensure I always knew the IP address of the Pi. I then rebooted the Pi.
$ sudo reboot
Then I removed the monitor, keyboard, and mouse and and attached the external drive. The rest of the installation was completed using SSH or VNC.
On a side note, the Pi kept rebooting after plugging the external drive into the USB port on the Pi. I added an external powered USB hub to the Pi and plugged the drive and the Pi into the hub and the problem went away. Seems my Pi was not providing enough power to the external drive and/or it did not have enough power to function properly.
2. Connect via SSH and update Raspbian by first using the following commands:
$ sudo apt-get update $ sudo apt-get upgrade $ sudo reboot
3. Connect via SSH and install netatalk to create an Apple accessible drive, gparted to format the USB drive, and tightvncserver to use the GUI interface.
$ sudo apt-get install netatalk gparted tightvncserver
4. To format the USB drive you will need to use the GUI application gparted. To access your headless Raspberry Pi you will need to turn on the VNC server and have it autoboot at startup. Here are the instructions to create the autostart for tightvnc.
$ cd /home/pi $ cd .config $ mkdir autostart $ cd autostart $ sudo nano tightvnc.desktop
Paste the following into the new file (tightvnc.desktop) to fit the geometry for a macbook pro.
[Desktop Entry] Type=Application Name=TightVNC Exec=vncserver :1 -geometry 1280x800 StartupNotify=false
5. Restart the Pi so that it can now be accessed via SSH or VNC.
$ sudo restart
6. Use VNC to access your Raspberry Pi. Your address will likely be something like, 192.168.x.x:1 to access the Pi.
7. Now that you can access the GUI on your Pi and you can use gparted to format the external drive. In the terminal type:
$ sudo gparted
I read a few tutorials and decided to format the drive as two 500GB partitions. They came up as sda1 and sda2, I also named them tmu1 and tmu2 for TimeMachine and user initials.
8. Now you need to make the directories accessible from your MacBook. In this tutorial it will be for the two partitions, one for each of the two users.
$ sudo mkdir /mnt/tmu1 $ sudo chmod 777 /mnt/tmu1
$ sudo mkdir /mnt/tmu2 $ sudo chmod 777 /mnt/tmu2
9. You will have to change fstab to automount the partitions.
$ sudo chmod 777 /etc/fstab $ sudo nano /etc/fstab
Add the following lines to fstab:
/dev/sda1 /mnt/tmu1 ext4 defaults 0 2 /dev/sda2 /mnt/tmu2 ext4 defaults 0 2
10. Mount the partitions and make them writable.
$ sudo mount /dev/sda1 $ sudo mount /dev/sda2
Something weird happened with permissions at this point and I had to reissue the chmod commands again to get things working.
$ sudo chmod 777 /mnt/tmu1 $ sudo chmod 777 /mnt/tmu2
11. Prepare netatalk so that TimeMachine on your Mac can access the partitions on the Pi.
$ sudo chmod 777 /etc/netatalk/AppleVolumes.default $ sudo nano /etc/netatalk/AppleVolumes.default
Add the following lines to AppleVolumes.default:
/mnt/tmu1 "tmusername1" options:usedots,upriv,tm /mnt/tmu2 "tmusername2" options:usedots,upriv,tm
12. Restart netatalk.
$ sudo service netatalk restart
13. On your Mac open the finder and connect to the Pi using the Pi’s username and password. Add this to your keychain so you don’t have to enter it everytime.
14. On your Mac open TimeMachine and select the appropriate partition for the user and let TimeMachine work its magic.
15. I cut some ventilation and access holes into a plastic container and put the drive, Pi, and USB hub into it. I then put it under my desk where it works silently and uses very little power.
I hope you found this tutorial helpful.