Source: https://gregology.net/2018/09/raspberry-pi-time-machine/
Install Raspbian Buster Lite on the SD card. Follow the instructions on the Installing images tutorial on the Raspberry Pi site. Then enable SSH. Insert the SD card into the Pi, plug in the USB hard drive, plug in a network cable, and power on the Pi.
Open Preferences and Raspberr pi configuration. Change the hostname to: "AirPort"
Next set a static IP address for your Raspberry Pi. Depending on your setup, you can either set the Pi to have a manual ip address or have your router assign a static IP address.
Login to your Pi via SSH or old school with a keyboard & monitor. Run raspi-config to make any changes you want like changing hostname etc.
pi@AirPort:~ $ sudo raspi-config
And update your Pi
pi@AirPort:~ $ sudo apt-get update && sudo apt-get upgrade -y
Install hfsutils & hfsprogs
pi@AirPort:~ $ sudo apt-get install hfsutils hfsprogs
Preforme a reboot.
Format USB hard drive to hfsplus. This will erase all data on the USB hard drive.
Note: this assumes your USB hard drive is sda1
pi@AirPort:~ $ sudo mkfs.hfsplus /dev/sda1 -v Data
Create mount point
pi@AirPort:~ $ sudo mkdir /media/Data && sudo chmod -R 777 /media/Data && sudo chown pi:pi /media/Data
Determine the UUID of your USB hard drive (sda1)
pi@AirPort:~ $ ls -lha /dev/disk/by-uuid
pi@AirPort:~ $ ls -lha /dev/disk/by-uuid
total 0
drwxr-xr-x 2 root root 120 Sep 3 00:17 .
drwxr-xr-x 8 root root 160 Sep 3 00:17 ..
lrwxrwxrwx 1 root root 15 Sep 3 00:13 3725-1C05 -> ../../mmcblk0p1
lrwxrwxrwx 1 root root 10 Sep 3 00:17 6525d832-1a97-35a5-92a4-345253fcfd00 -> ../../sda1
lrwxrwxrwx 1 root root 10 Sep 3 00:17 67E3-17ED -> ../../sda1
lrwxrwxrwx 1 root root 15 Sep 3 00:13 fd695ef5-f047-44bd-b159-2a78c53af20a -> ../../mmcblk0p2
In my case the UUID is 6525d832-1a97-35a5-92a4-345253fcfd001.
Edit fstab to mount the USB hard drive
pi@AirPort:~ $ sudo nano /etc/fstab
and append this line (replacing 6525d832-1a97-35a5-92a4-345253fcfd00 with your specific UUID determined above).
UUID=6525d832-1a97-35a5-92a4-345253fcfd00 /media/Data hfsplus force,rw,user,noauto 0 0
It should end up looking something like this
proc /proc proc defaults 0 0
PARTUUID=d159f393-01 /boot vfat defaults 0 2
PARTUUID=d159f393-02 / ext4 defaults,noatime 0 1
UUID=6525d832-1a97-35a5-92a4-345253fcfd00 /media/Data hfsplus force,rw,user,noauto 0 0
Test that mounting works as expected
pi@AirPort:~ $ sudo mount /media/Data
pi@AirPort:~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 15G 1.4G 13G 10% /
devtmpfs 484M 0 484M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 13M 476M 3% /run
tmpfs 5.0M 8.0K 5.0M 1% /run/lock
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/mmcblk0p1 43M 22M 21M 51% /boot
/dev/sda2 699G 300M 668G 0% /media/tm
tmpfs 98M 0 98M 0% /run/user/1000
should show a line like /dev/sda1 699G 300M 668G 0% /media/Data
Note: we are not automatically mounting this USB hard drive as mounting USB on startup can be flakey
Install prerequisites
pi@AirPort:~ $ sudo apt-get install netatalk -y
and ensure everything worked
pi@AirPort:~ $ 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
Edit nsswitch.conf
pi@AirPort:~ $ sudo nano /etc/nsswitch.conf
append mdns4 and mdns to the line that starts with hosts. It should end up looking something like this.
# /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: compat
group: compat
shadow: compat
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
Finally edit afp.conf
pi@AirPort:~ $ sudo nano /etc/netatalk/afp.conf
and append
[Global]
mimic model = TimeCapsule6,106
[Data]
path = /media/Data
time machine = yes
Launch the two services
pi@AirPort:~ $ sudo service avahi-daemon start
pi@AirPort:~ $ sudo service netatalk start
Edit crontab
pi@AirPort:~ $ sudo crontab -e
and append
@reboot sleep 30 && mount /media/Data && sleep 30 && umount /media/Data && sleep 30 && mount /media/Data && sleep 30 && service avahi-daemon start && service netatalk start
Note: this mount / unmount / mount flow is required as HFS+ partitions may become read only if unmounted incorrectly. The 30 second sleeps give the USB hard drive time to spin up and become mounted before the avahi-daemon & netatalk services start
Read only drive If your drive becomes read only you can try either changing the permissions of the directory
pi@AirPort:~ $ sudo chown pi:pi /media/Data
or forcing fsck.hfsplus to check and repair journaled HFS+ file systems
pi@AirPort:~ $ sudo fsck.hfsplus -f /dev/sda1
Make a folder for your media.
pi@AirPort:~ $ sudo mkdir /media/Data/Plex && sudo chmod -R 777 /media/Data/Plex && sudo chown pi:pi /media/Data/Plex
? Maybe run 1777 /media/Data/Plex ?
Making the Disk Available Using SMB
You’ll need to install the Samba server software.
pi@AirPort:~ $ sudo apt-get install samba samba-common-bin
Then go ahead and edit the /etc/samba/smb.conf file, appending the following to the end of the file.
pi@AirPort:~ $ sudo nano /etc/samba/smb.conf
[Plex]
Comment = Plex Media Folder
Path = /media/Data/Plex
Browseable = yes
Writeable = Yes
only guest = no
create mask = 0777
directory mask = 0777
Public = yes
Guest ok = no
Create a user and start Samba
Before we start the server, you’ll want to set a Samba password - this is not the same as your standard default password (raspberry), but there’s no harm in reusing this if you want to, as this is a low-security, local network project.
pi@AirPort:~ $ sudo smbpasswd -a pi
Then set a password as prompted. Finally, let’s restart Samba:
pi@AirPort:~ $ sudo /etc/init.d/smbd restart
From now on, Samba will start automatically whenever you power on your Pi. Once you’ve made sure that you can locate your shared folder on the network, you can safely disconnect the mouse, monitor, and keyboard from your Pi and just leave it running as a headless file server.
Soruce: https://pimylifeup.com/raspberry-pi-plex-server/ and https://thepi.io/how-to-set-up-a-raspberry-pi-plex-server/
- To install the Plex packages to the Raspberry Pi, we will need to add the official Plex package repository. Before we do that we need to install the “apt-transport-https” package. This package allows the “apt” package manager to retrieve packages over the “https” protocol that the Plex repository uses. Install the package by running the command below.
pi@AirPort:~ $ sudo apt-get install apt-transport-https
- Let’s now add the Plex repositories to the “apt” package managers key list. This key is used to ensure the files that you are downloading are in fact from that repository and signed by that key. Run the following command to download and add the key to the package manager.
pi@AirPort:~ $ curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -
- With the Plex GPG key now added, we can finally add the official plex repository to the sources list by running the following command.
pi@AirPort:~ $ echo deb https://downloads.plex.tv/repo/deb public main | sudo tee /etc/apt/sources.list.d/plexmediaserver.list
- As we have just added a new repository to our sources, we will need to run the “update” command again to refresh the package list.
pi@AirPort:~ $ sudo apt-get update
- Now that we have set up our Raspberry Pi so that it can read from Plex’s official package repositories we can go ahead and finally install the Plex Media server package to the Pi. To install the “plexmediaserver” package, run the command below.
pi@AirPort:~ $ sudo apt install plexmediaserver
-
The installation process for Plex sets up a few different things for us. The first is that it creates a user and group for Plex to run under. This user and group is called “plex“. It also will set up two directories, one where to store files temporarily that Plex is transcoding. You can find this folder at
“/var/lib/plexmediaserver/tmp_transcoding“
. The second directory is where Plex will store all the metadata it retrieves for your media. This folder can be found at“/var/lib/plexmediaserver/Library/Application Support”
-
Permissions chores. Let’s set Plex to run under the Pi user.
pi@AirPort:~ $ sudo nano /etc/default/plexmediaserver.prev
Your terminal window will fill with a big text document. Look for the line that says PLEX_MEDIA_SERVER_USER=plex. Delete “plex” and type in “pi,” so that the line reads PLEX_MEDIA_SERVER_USER=pi. Now hit CTRL+X to exit. Type Y for “yes” to save your changes and hit Enter to stick with the same old file name. Then,
- Restart the server.
pi@AirPort:~ $ sudo service plexmediaserver restart
- IP address chores You’ll want your Raspberry Pi Plex server to have a static IP address, so that you only have to connect once on each client device. First, get your IP:
pi@AirPort:~ $ hostname -I
This will kick back your IP address. Copy it or write it down. Let’s open your command line txt file.
pi@AirPort:~ $ sudo nano /boot/cmdline.txt
At the bottom of the command line text file, type ip= followed by your IP address. Save and exit the file (CTRL+X, then Y, then Enter).
- Restart your Pi
pi@AirPort:~ $ sudo reboot