The following instructions cover how to use a Raspberry Pi 5 as a home file server.
The Raspberry Pi is a small single board computer. Advantages include low cost and low power consumption. There is also a vast amount of information/help available, particularly on the Raspberry Pi website, click here.
The fan is temperature controlled and in general use it is mainly switched off. When used as described on this page the only noise generated is from the mechanical hard drives, but USB drives generally power down when not in use.
Items required:
Raspberry Pi 5 (8GB model recommended)
Official active cooler
Official power supply
Case
Small USB drive (SSD) for use as a boot drive
Larger mechanical USB hard drives for general storage
USB Hub(s) as required
The Raspberry Pi runs a number of different flavours of Linux, in this case the standard Raspberry Pi OS is used. There are a wide range of software packages available, including Homebridge and Gitea. This page will be updated to include installation instructions for a number of these packages.
If possible the Ethernet port should be used as it will provide a higher thoughput than the WI-FI (which can be disabled). It is also possible to use a 2.5GBit USB Ethernet adaptor for even higher speeds.
A form of software RAID can easily be achieved by setting up a CRON task to routinely sync the data from one drive to another.
Raspberry Pi 5 with the official active cooler fitted
There are a number of options for a boot drive. You can use a microSD card, any USB drive, or the newest option with the RPi 5 is an NVMe drive fitted to a M.2 add on card. The NVMe option provides the best performance, but any USB hard drive will be fast enough for use as a boot drive. The microSD card is the easiest/cheapest option but potentially the least reliable.
The latest version of the RPi OS can be downloaded from the Raspberry Pi website (https://www.raspberrypi.com) and then copied directly to the boot device using a second computer and the Raspberry Pi Imager application. The latest RPi 5 firmware also allows the downloading of the OS from an internet connection directly to a blank boot device (this requires a monitor/mouse/keyboard).
If you plan to use the RPi headless (no monitor/keyboard/mouse) then you should ensure that SSH is enabled. Enable the VNC service as this is a great way to interact with the RPi.
Use following commands to install Samba:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install samba
To create a basic folder to be shared:
sudo mkdir /srv
sudo mkdir /srv/General
sudo chmod 777 /srv/General
Use the nano text editor to add a “[General]” section to the end of smb.conf (this creates a share called “General”)
sudo nano /etc/samba/smb.conf
[General]
comment = General file storage
public = yes
writeable = yes
browsable = yes
path = /srv/General
create mask = 0777
sudo directory mask = 0777
To retart the Samba file server use the following command:
sudo service smbd restart
Add the following to the end of the “[Global]” section in smb.conf:
mdns name = mdns
fruit:metadata = stream
fruit:model = MacPro
fruit:posix_rename = yes
fruit:veto_appledouble = no
fruit:nfs_aces = no
fruit:wipe_intentionally_left_blank_rfork = yes
fruit:delete_empty_adfiles = yes
force user = pi
All of the fruit settings are intended for Mac users, and makes all file shares more compatible with Apple computers.
The “mdns name = mdns” allows the advertised name for a share to appear in upper/lower case rather than just capitals.
The “force user = pi” setting ensures that all files created within the shared directory by connected users are created with the root user “pi” security and ownership settings. This allows the root user on the RPi, called “pi”, to read / write / copy / archive the files without any access problems, and also allows all connected users full access to files regardless of who created them.
Rather than having network users connect to the file server using the “pi” username it is better to setup another username/password combination. The following commands will generate a user called Home, then add Home to the sudo group and Samba:
sudo adduser Home
sudo adduser Home sudo
sudo smbpasswd -a Home
As you enter these commands you will be asked to enter the password you decide to use for the Home user. If the first command fails due to username rules you can try it again with the “--allowbadnames” parameter added onto the end.
As you add extra hard drives to the system they should be formatted as EXT4 using the GParted application on the RPi. This easily achieved using either VNC or a monitor/keyboard/mouse. When formatting ensure you give the drive a sensible name and label.
When logged into the desktop on the RPi OS the user is normally prompted when a USB drive is atached as to whether it should be mounted on the desktop. To enable a drive to be automatically mounted at boot time when using the RPi without any user interaction each drive needs to be added to the linux “fstab" file. Before doing this you must find the UUID of the drive (each drive is given a unique UUID number when it is formatted).
Use the “blkid” command to list all of the connected drives and their UUID numbers. The following is an example of the UUID data returned for a drive called “data4":
/dev/sde1: LABEL="data4" UUID="0d8d766a-d0e6-4872-b6c4-0861608d865c" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="data4" PARTUUID="8860ddb5-3b97-4b16-b15c-d59722d786f0"
The following line should then be added to the end of the fstab file using the "sudo nano /etc/fstab” command:
UUID=0d8d766a-d0e6-4872-b6c4-0861608d865c /media/pi/data4 ext4 defaults,auto,users,rw,nofail 0 0
Create the mount point using the following commands:
mkdir /media/pi/data4
sudo chmod 777 /media/pi/data4
When all the external drives are added to fstab then they will all automatically mount on bootup and appear on the RPi OS desktop.
The following commands will create a “Software” directory onto the “data4” drive added above:
mkdir /media/pi/data4/Software
sudo chmod 777 /media/pi/data4/Software
Then add the following to the “smb.conf" file using the comand "sudo nano /etc/samba/smb.conf”:
[Software]
comment = Software
public = yes
writeable = yes
browsable = yes
path = /media/pi/data4/Software
create mask = 0777
directory mask = 0777
vfs objects = catia fruit streams_xattr
The following commands will create a “TimeMachine” directory on the “data6” drive:
mkdir /media/pi/data6/TimeMachine
sudo chmod 777 /media/pi/data6/TimeMachine
Then add the following to the smb.conf file using "sudo nano /etc/samba/smb.conf”:
[TimeMachine]
comment = Time Machine Backup
public = yes
writeable = yes
browsable = yes
path = /media/pi/data6/TimeMachine
create mask = 0777
directory mask = 0777
vfs objects = catia fruit streams_xattr
fruit:time machine = yes
Once Samba is restarted the TimeMachine share should be advertised on the network and will appear when adding a Time Machine location onto any connected Macs. The same share can be used by multiple Macs.