Hardware
Time Machine Backup Target

Time Machine Backup Target

We will install Net talk to provide APF and Avahi to advertise and host on a external drive. The RPI4B firmware natively supports USB 3.0 and booting from SSD drives. Will boot from the SD card as want separate data partition. Booting from SSD is not the issue. With a 4 and latest OS it is a case of selecting the SSD drive instead of a SD card when writing the image. I want to be able to replace the data directory as required so proceeding with an separate drive. The bigger picture is to replace the XEON based device that hosts ~ 4TB for backups. There must be a RAID option with external power for the capacity but for now going with a WD 240TB Green Drive to verify its operation.

Using the ‘Green’ range as they are designed to be low power / preformance. The SSD will consume 0.60A (2.8W) and transfer over SATA III (6 Gb/s). The RPI4B is able to supply a total of 1.2 amps to its 4 USB ports if the RPi4B is powered from a 3 amp power supply and supports USB3 interface (5 Gb/s) so will be a practical match.

First ensure OS is up to date;

# sudo apt-get update && sudo apt-get upgrade -y

hfsplus partition.

Here I will format an USB3 SSD hard drive using hfsplus.

# sudo apt-get install hfsutils hfsprogs -y

So this is what an fdisk -l shows when the device has the SD card to boot and OS (/dev/mmcdlk0p1/2) and ext SSD drive with single partition (/dev/sda);

 Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 sectors
 Units: sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disklabel type: dos
 Disk identifier: 0x74129c0a
 Device         Boot  Start      End  Sectors  Size Id Type
 /dev/mmcblk0p1        8192   532479   524288  256M  c W95 FAT32 (LBA)
 /dev/mmcblk0p2      532480 31116287 30583808 14.6G 83 Linux
 Disk /dev/sda: 223.6 GiB, 240065175552 bytes, 468877296 sectors
 Disk model: 40G2G0A-00JH30  
 Units: sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disklabel type: gpt
 Disk identifier: 7CEE32DA-6AA7-45DF-83B3-CBB22D661899
 Device     Start       End   Sectors   Size Type
 /dev/sda1   2048 468877262 468875215 223.6G Linux filesystem

Will format as hfplus as native filesystem of Mac OS X and label accordingly;

# sudo mkfs.hfsplus /dev/sda1 -v TimeMachine

Create mount point and update permissions to allow user access;

# sudo mkdir /media/tm && sudo chmod -R 777 /media/tm && sudo chown root:users /media/tm

Determine the UUID of your USB hard drive as will be use for fstab;

$ ls -lha /dev/disk/by-uuid
 total 0
 drwxr-xr-x 2 root root 100 Oct  7 13:13 .
 drwxr-xr-x 7 root root 140 Oct  7 13:13 ..
 lrwxrwxrwx 1 root root  15 Oct  7 13:13 7616-4FD8 -> ../../mmcblk0p1
 lrwxrwxrwx 1 root root  15 Oct  7 13:13 87b585d1-84c3-486a-8f3d-77cf16f84f30 -> ../../mmcblk0p2
 lrwxrwxrwx 1 root root  10 Oct  7 13:13 95042b43-d161-3363-b0a8-99291c5789d1 -> ../../sda1

then edit fstab to mount the USB hard drive on boot;

proc            /proc           proc    defaults          0       0
PARTUUID=74129c0a-01  /boot           vfat    defaults          0       2
PARTUUID=74129c0a-02  /               ext4    defaults,noatime  0       1
UUID=95042b43-d161-3363-b0a8-99291c5789d1    /media/tm hfsplus force,rw,user 0 0 
tmpfs /var/tmp tmpfs nodev,nosuid,size=512M 0 0 
tmpfs /tmp tmpfs nodev,nosuid,size=512M 0 0

Test that mounting works as expected;

$ sudo mount -a
$ df -h
 
Filesystem      Size  Used Avail Use% Mounted on
 /dev/root        15G  3.1G   11G  23% /
 devtmpfs        776M     0  776M   0% /dev
 tmpfs           937M     0  937M   0% /dev/shm
 tmpfs           937M  8.6M  928M   1% /run
 tmpfs           5.0M  8.0K  5.0M   1% /run/lock
 tmpfs           937M     0  937M   0% /sys/fs/cgroup
 tmpfs           512M     0  512M   0% /var/tmp
 tmpfs           512M  4.0K  512M   1% /tmp
 /dev/sda1       224G  184G   41G  82% /media/tm
 /dev/mmcblk0p1  253M   50M  204M  20% /boot
 tmpfs           188M     0  188M   0% /run/user/109
 tmpfs           188M     0  188M   0% /run/user/1001

Netatalk

Netatalk provides Apple Filing Protocol (APF) which is Apple’s proprietary network protocol for delivering files over a network. It is Apple’s alternative to the Server Message Block (SMB) and Network File System (NFS) protocols. Version 3.x is now available from the Pi repository so can install wit apt-get .

# sudo apt-get install netatalk -y

check netatalk installed version 3.x;

# netatalk -V
 netatalk 3.1.12 - Netatalk AFP server service controller daemon
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
 Foundation; either version 2 of the License, or (at your option) any later
 version. Please see the file COPYING for further information and details.
 netatalk has been compiled with support for these features:
Zeroconf support:    Avahi  
Spotlight support:    Yes               
afpd:    /usr/sbin/afpd         
cnid_metad:    /usr/sbin/cnid_metad    
tracker manager:    /usr/bin/tracker daemon        
dbus-daemon:    /usr/bin/dbus-daemon           
afp.conf:    /etc/netatalk/afp.conf  
dbus-session.conf:    /etc/netatalk/dbus-session.conf 
netatalk lock file:    /var/lock/netatalk

update /etc/nsswitch;

# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         files
group:          files
shadow:         files
gshadow:        files

hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4 mdns
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

and update afp.conf;

# /etc/netatalk/afp.conf
;
; Netatalk 3.x configuration file
;
[Global]
  mimic model = TimeCapsule6,106

[Time Machine]
  path = /media/tm
  time machine = yes

Adding the following will allow support for home directories.

[Homes]
  basedir regex = /home

Avahi

Avahi is a software solution enabling an easy-to-use, zero-configuration local network. It is a GNU alternative to Apple’s Bonjour software solution allowing communication between your Pi and your Mac.

At first, we will install all the prerequired elements for Avahi :

sudo apt-get install db5.1-util libgcrypt11-dev avahi-daemon libavahi-client-dev libdb5.3-dev -y

Now that Avahi is installed, we need to make sure that it starts at the boot of the Raspberry Pi. To do this, just type the following command :

sudo update-rc.d avahi-daemon defaults
sudo service avahi-daemon start
sudo service netatalk start

then reboot the PI.

You should be able to see the device from the Mac in finder with Time Capsule icon. There wont be home directories as yet but will be able to select and use the disk for Time Machine.

Updates.

During the process of building mirrors and testing (decided to use HW over software) managed to break the config more that once. Issues would manifest as an inability to boot and connecting a screen to the device didn’t always enable a resolution. However being able to pull the SD card and mount in another device then edit proved invaluable. So the practice is to build the boot disk on SD card, test and once stable write the SD card to the SSD drive.

# Write SD card to SSD drive. dmesg to conform device names
dmesg
sudo dd of=/dev/sdf if=/dev/sde bs=4096k status=progress

# repair dirty fs
sudo fsck /dev/sda1

# use Disk ID in fstab
sudo blkid
ls -lha /dev/disk/by-uuid

# edit fstab once mounted in another device 
proc            /proc           proc    defaults          0       0
PARTUUID=75030815-01  /boot           vfat    defaults          0       2
PARTUUID=75030815-02  /               ext4    defaults,noatime  0       1
UUID=b878672f-e52f-451e-bd08-ebee78718437  /mnt/timemachine      ext4    defaults,errors=remount-ro 0	0 
tmpfs /var/tmp tmpfs nodev,nosuid,size=256M 0 0 
tmpfs /tmp tmpfs nodev,nosuid,size=1024M 0 0

sudo fsck.hfsplus -f /dev/sda1

Software RAID straight forward;


sudo apt-get install mdadm -y

sudo blkid
/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="E183-6233" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="75030815-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="1232a209-2596-48f0-a078-731d10b918ad" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="75030815-02"
/dev/sdb1: LABEL="4TB02" UUID="6ec671a5-b278-4c1f-b246-2c5a3b0327c2" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="67924807-e66f-3b47-9655-c62f6c2a4896"
/dev/sda1: LABEL="4TB01" UUID="74bd0e3c-332b-4b9a-a738-403e06a2ffdf" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="47d25b7e-39b9-2b49-adc8-61282cc279fd"

sudo mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sda1 /dev/sdb1
mdadm --detail --scan

sudo -i
mdadm --detail --scan >> /etc/mdadm/mdadm.conf
mkfs.ext4 -v -m .1 -b 4096 -E stride=32,stripe-width=64 /dev/md0

# Add to /etc/fstab
UUID=5af30b6a-2ce2-45ac-92ca-f4559c02c97e /mnt/raid0 ext4 defaults 0 0