项目作者: mr-bt

项目描述 :
Apple Time Machine with raspberry Pi
高级语言:
项目地址: git://github.com/mr-bt/raspberrypi-timemachine.git
创建时间: 2017-10-23T13:57:28Z
项目社区:https://github.com/mr-bt/raspberrypi-timemachine

开源协议:MIT License

下载


Apple Time machine on RaspberryPI

The following step are the ones that enable Time Machine backups with Raspberry Pi plus a bit of polishing to my taste.

1. Format the hard drive

I had a hard-drive serving as Time Machine disk. However, I couldn’t mount the disk due to Apple Core Storage:

  1. Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
  2. Units: sectors of 1 * 512 = 512 bytes
  3. Sector size (logical/physical): 512 bytes / 512 bytes
  4. I/O size (minimum/optimal): 512 bytes / 512 bytes
  5. Disklabel type: gpt
  6. Disk identifier: DE07BD84-C4E1-4229-81CD-E146E04D46C6
  7. Device Start End Sectors Size Type
  8. /dev/sda1 40 409639 409600 200M EFI System
  9. /dev/sda2 409640 975539735 975130096 465G Apple Core storage
  10. /dev/sda3 975539736 975801879 262144 128M Apple boot
  11. /dev/sda4 975802368 1953523711 977721344 466.2G Microsoft basic data

StackOverflow thread mounting hfs partition on arch linux didn’t work for me. Since the backups on that disk were a bit outdated I decided to format the partition and give it a go. Another alternative would be to use Disk Utility to get rid of Apple Core Storage but in my case not worth the effort.

So, format the HD on your Mac using Disk Utility. Settings used:

  • Name: Time Machine
  • Format: Mac OS Extended (Journaled)
  • Scheme: GUID Partition Map

2. Ensure Pi has permissions to control the drive

Go to the Finder, then right-click the drive in the sidebar. Click “Get Info”.

Click the lock at bottom right, then enter your password. Next, check Ignore ownership on this volume. and give Read & Writepermissions to everyone.

Linux cannot write data into journaled hfs+ file system, so you also need to disable that:

  1. diskutil list

Then find your drive and partition identifier (like: disk*s*), and run:

  1. diskutil disableJournal /dev/disk*s*

Dont forget to replace the asterisks. You’ll see:

  1. Journaling has been disabled for volume MyTimeMachine on disk*s*

3. Install tools for Apple-formatted drives

Go to Pi (ssh’ed it!) and run:

  1. $ sudo apt-get update
  2. $ sudo apt-get upgrade
  3. $ sudo apt-get --assume-yes install hfsprogs hfsplus

4. Mount the drive

Find the drive:

  1. $ sudo fdisk -l
  2. ...
  3. Device Boot Start End Sectors Size Id Type
  4. /dev/mmcblk0p1 8192 3292968 3284777 1.6G e W95 FAT16 (LBA)
  5. /dev/mmcblk0p2 3292969 62333951 59040983 28.2G 5 Extended
  6. /dev/mmcblk0p5 3293184 3358717 65534 32M 83 Linux
  7. /dev/mmcblk0p6 3358720 3500031 141312 69M c W95 FAT32 (LBA)
  8. /dev/mmcblk0p7 3506176 62333951 58827776 28.1G 83 Linux
  9. Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
  10. Units: sectors of 1 * 512 = 512 bytes
  11. Sector size (logical/physical): 512 bytes / 512 bytes
  12. I/O size (minimum/optimal): 512 bytes / 512 bytes
  13. Disklabel type: gpt
  14. Disk identifier: DE07BD84-C4E1-4229-81CD-E146E04D46C6
  15. Device Start End Sectors Size Type
  16. /dev/sda1 40 409639 409600 200M EFI System
  17. /dev/sda2 409640 975539735 975130096 465G Apple HFS/HFS+
  18. /dev/sda3 975802368 1953523711 977721344 466.2G Microsoft basic data

In my case my HD is connected to USB and the device is /dev/sda2. A good hint is the fs type Apple HFS/HFS+ or on other tools hfsx.

Create your mounting point:

  1. $ sudo mkdir -p /media/time_machine

Check if Pi already auto-mounted your drive:

  1. $ sudo mount

If it’s mounted, you need to un-mount it or give it write permissions. In my case I didn’t want to have it mounted on /media/pi/Time\ Machine so I un-mounted it:

  1. $ sudo umount /dev/sda2

Mount drive using your editor of choice:

  1. $ sudo nano /etc/fstab

Add to the end of the file:

  1. /dev/sda2 /media/time_machine hfsplus force,rw,user,noauto,x-systemd.automount 0 0

Mount the drive

  1. $ sudo mount -a

Check if it’s mounted by finding the line like the bellow:

  1. $ sudo mount
  2. ...
  3. /dev/sda2 on /media/time_machine type hfsplus (rw,nosuid,nodev,noexec,relatime,umask=22,uid=0,gid=0,nls=utf8,user)

Install Netatalk

Netatalk simulates AFP, the network protocol Apple currently users for Time Machine backups.

Install dependencies

  1. sudo aptitude install build-essential libevent-dev libssl-dev libgcrypt11-dev libkrb5-dev libpam0g-dev libwrap0-dev libdb-dev libtdb-dev avahi-daemon libavahi-client-dev libacl1-dev libldap2-dev libcrack2-dev systemtap-sdt-dev libdbus-1-dev libdbus-glib-1-dev libglib2.0-dev libio-socket-inet6-perl tracker libtracker-sparql-1.0-dev libtracker-miner-1.0-dev

Install Netatalk via apt-get

  1. apt-get install netatalk
  1. whereis netatalk

6. Configure Netatalk

First let’s set up nsswitch.conf by adding to the end of hosts: files mdns4_minimal [NOTFOUND=return] dns line mdns4 mdns.

  1. $ sudo nano /etc/nsswitch.conf

It should look like this:

  1. # /etc/nsswitch.conf
  2. #
  3. # Example configuration of GNU Name Service Switch functionality.
  4. # If you have the `glibc-doc-reference' and `info' packages installed, try:
  5. # `info libc "Name Service Switch"' for information about this file.
  6. passwd: compat
  7. group: compat
  8. shadow: compat
  9. gshadow: files
  10. hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4 mdns
  11. networks: files
  12. protocols: db files
  13. services: db files
  14. ethers: db files
  15. rpc: db files
  16. netgroup: nis

This means your Time Machine drive will show up in Finder’s sidebar.

Next set up afp.conf

  1. $ sudo nano /usr/local/etc/afp.conf

add to the end

  1. [Global]
  2. mimic model = TimeCapsule6,106
  3. [Time Machine]
  4. path = /media/time_machine
  5. time machine = yes

At last set AppleVolumes.default (might not be necessary)! I did it anyway…

  1. $ sudo nano /etc/netatalk/AppleVolumes.default

and add to the end of the file

  1. /media/time_machine "Time Machine" options:tm

7. Launch network services

  1. $ sudo service avahi-daemon start
  2. $ sudo service netatalk start
  1. $ sudo systemctl enable avahi-daemon
  2. $ sudo systemctl enable netatalk

8. Give your Pi a static IP

Go to your router and assign a static IP to your Pi.

9. Connect to time machine

Go to your Mac Finder you should see your Raspberry Pi there.
Click on Connect as and insert your credentials (user: timemachine). If doesn’t work, connect to your Pi through its static IP. Open Finder, then hit Command+K on your keyboard and insert:

  1. afp://<you Pi ip>

10. Configure your Mac Time Machine

Go to System Preferences > Time Machine and clik on Select Disk.... Your Pi should show on the list. Select and use the settings that work best.

Notice

  • Make sure that erveryone has permissions to read & write your disk drive.

  • If aptitude install ... at the last of step 5 shows an eror like Package 'libmysqlclient-dev' has no installation candidate, please try default-libmysqlclient-dev.

Reference Articles