Building a Raspberry Pi File and Media Server: A DIY Guide for Seamless Home Content Sharing (2024)

In the sea of videos and photos scattered across my home computer, sharing and accessing content within the family became a bit of a puzzle. I needed a central hub that could work as a file and media server, compatible with Windows, Linux, macOS, Android, and even our TV.

At first, I eyed commercial NAS solutions, but their price tags quickly put them out of reach. So, I decided to roll up my sleeves and turn my Raspberry Pi 4 and an old external hard drive into my very own file and media servers.

The main challenge was making sure the external hard drive could connect seamlessly to Windows, Raspberry Pi, and sometimes macOS. I chose the exFAT filesystem, formatted the hard drive, and had a single neat partition ready to roll.

Next, I stumbled upon OpenMediaVault, which seemed promising at first. Little did I know, it didn’t play well with exFAT. Hours turned into frustration, dealing with errors, reformatting, and reinstalling RaspberryOS. After a series of connectivity hiccups, I decided to ditch OpenMediaVault and set things up on my own using SMB (for file sharing) and MiniDLNA (for media).

Despite being comfortable with Linux terminals, I wanted something more user-friendly. That’s when I discovered the Cockpit project. Along with its handy addons — “File Sharing” to manage Samba and NFS, “Navigator” for a slick File Manager, and Web-based Terminal emulator — it worked like a charm. Now, my solution runs smoothly with Cockpit and MiniDLNA, turning my Raspberry Pi into a content hub for the whole family.

In the end, my Raspberry Pi 4, armed with exFAT rebelliousness, became the family’s go-to spot for files and media, all neatly managed through Cockpit. The story of a personal server — built, refined, and embraced.

I initially aimed to acquire the most recent Raspberry Pi OS, specifically the Desktop version of Bookworm. However, confronted with a series of software incompatibility hurdles, I concluded that the “Bullseye” release server image was a more pragmatic choice to fulfill my requirements.

My solution uses the following hardware and software.

  • Raspberry Pi 4 Model B Rev 1.4, quad-core CPU, 8GB RAM
  • 32 GB SD card with Raspberry Pi OS Lite Legacy (Bullseye, Server)
  • Power adapter for Raspberry Pi
  • External USB Hard Disk with exFAT filesystem
  • Powered USB 3.0 Hub — need this as Raspberry Pi could not deliver the power needed to run this hard disk when I connected it directly to RPi USB port.
  • PuTTY software for ssh into Raspberry Pi

Given the abundance of resources detailing the setup of Raspberry Pi and the process of formatting a hard disk with exFAT, these particular aspects will not be addressed in this article.

Building a Raspberry Pi File and Media Server: A DIY Guide for Seamless Home Content Sharing (2)

Ensure all connections are securely in place and power up your Raspberry Pi. For optimal stability, opt for a wired LAN connection over WiFi, as WiFi connectivity may pose challenges with configurations that require additional troubleshooting steps. Once the Raspberry Pi is operational, you’ll need to locate its IP address to establish an SSH connection. If you have access to your home router, you can easily find the Raspberry Pi’s IP address in the router’s DHCP client list.

Alternatively, you can connect a monitor and keyboard directly to the Raspberry Pi, eliminating the need for SSH. However, leveraging SSH from the machine where you’re running the setup, or using tools like PuTTY, offers a more streamlined approach. This method is not only convenient but also simplifies the process of copying and pasting commands from online sources, making your setup experience more efficient.

ssh into Raspberry Pi using the IP address or hostname (in my case it is “rpi-home”) and the user id setup while preparing the SD card (in my case it is “admin”). The rest of the document assumes this user id and hostname. You replace it as per your user id and hostname.

As a preliminary step, it’s essential to ensure that the operating system is fully updated.

sudo apt-get update
sudo apt-get upgrade

exFAT, is a file system developed by Microsoft for flash memory. It is a proprietary filesystem and is not officially part of Linux. FUSE allows us to use exFAT format.

Use the following commands to install FUSE.

sudo apt-get install exfat-fuse
sudo apt-get install exfat-utils

Make sure that the hard disk is connected to the RPi through the power USB Hub to the USB 3 port of the RPi.

The first step is to check if the hard disk is detected. The following command lists all the disks connected.

lsblk

I have only one USB hard disk and it appears as “sda”. It has only one partition in it, and it shows up as “sda1”.

We have to mount this disk onto some folder to be able to access the disk. Let’s create a folder and change the ownership to the current user, user “admin” in my case.

sudo mkdir /media/exthdd
sudo chown -R admin:admin /media/exthdd

First, manually mount the file system to make sure everything works fine.

sudo mount -t exfat /dev/sda1 /media/exthdd

If all goes well, you should be able to see the content of the disk with the following command:

ls /media/exthdd

We will configure this disk to be automatically mounted when the Raspberry Pi boots. First, unmount the disk.

sudo umount /media/exthdd

We need to find out the UUID of this disk as that is needed for the configuration. Run the following command.

sudo blkid

This command will give output something like this.

/dev/sda1: LABEL="Data" UUID="0AC8-A364" BLOCK_SIZE="512" TYPE="exfat" PARTLABEL="Basic data partition" PARTUUID="6ad9b0ee-2ecc-4b70–99b5-dce69e214493"

We need UUID “0AC8-A364” for the next step. Edit /etc/fstab file and add configure the mount.

sudo vi /etc/fstab

Add the following line at the end of this file and save it. Make sure you use your disk UUID.

UUID=0AC8-A364 /media/exthdd exfat rw,user,dmask=0000,fmask=0000,nosuid,nodev,nofail 0 0

Let’s mount it again this time using fstab.

sudo mount -a

Let’s check again whether the disk is accessible. Also, let’s check whether we can write onto the disk by creating and deleting a test file.

ls /media/exthdd
touch /media/exthdd/test.txt
rm -f /media/exthdd/test.txt

If everything works, then we have the disk mounted and accessible even after a reboot.

We will now set up a Samba server that allows sharing the folder over the network. With this setup, we will be able to share folders on this for read/write access.

Run the following command to install Samba.

sudo apt-get install samba samba-common-bin

While we can share the whole folder /media/exthdd with everyone, it is a good idea to keep a separate folder for sharing so that you can still use this disk to store other data that you don’t want to share. Let’s create a folder for sharing called “media-library”.

mkdir /media/exthdd/media-library

We have to give access to specific users to this shared folder. These users have to be Linux users. We can create a user per family member with write access and a common “guest” user with only read-only access. For now, Let’s create a common user called “family” with write access that all family members can use and set a password for this user.

sudo adduser family
sudo passwd family

We will give Samba access to “admin” and “family” users. These commands will ask you to give a separate password for Samba access.

sudo smbpasswd -a admin
sudo smbpasswd -a family

We have to tell Samba service that it has to expose this folder over the network. We have to update the Samba configuration. Let’s edit the configuration file.

sudo vi /etc/samba/smb.conf

Add the following section at the end of this file and save the file.

[media-library]
path = /media/exthdd/media-library
valid users = admin family
writeable=Yes
create mask=0777
directory mask=0777
public=no

The folder will appear as “\\rpi-home\media-library” (section header). The folder is accessible to the list of users in “valid users”. We will add a new user called “family” in a moment. The folder is writable. Permission is given to all logged-in users (777). However, public access is “no”.

Restart the service.

sudo systemctl restart smbd

You will be now able to access \\rpi-home\media-library folder from Windows File Explorer. You can also map this folder onto a drive from Explorer or from the command prompt with the following command.

net use Z: "\\rpi-home\media-library /user:<username> <password>

On macOS, you will be able to connect to the server from Finder using “smb:\\rpi-home\media-library” URL

We will be using miniDLNA to set up a media server. First, install miniDLNA.

sudo apt-get install minidlna

We have to configure miniDLNA to give it a name and expose the folders. Edit the configuration file.

sudo vi /etc/minidlna.conf

Find and edit the friendly name for the server in this file. Find lines starting with media_dir and add them as shown below.

friendly_name=rpi-mediaserver

media_dir=A,/media/exthdd/media-library/music
media_dir=P,/media/exthdd/media-library/photos
media_dir=V,/media/exthdd/media-library/videos

In this example, I have added separate folders for music, photos, and videos as I have structured my data that way. Also, A, P, and V are file types that tell the media server to expose those folders as Audio, Picture, and Videos respectively.

Restart the service.

sudo systemctl restart minidlna

“rpi-mediaserver” will show up on your TV if the TV is capable of connecting to DLNA and is connected to the same network. Windows Media Player will also be able to see this server and play the files.

Building a Raspberry Pi File and Media Server: A DIY Guide for Seamless Home Content Sharing (3)

While these steps are enough to get going, all the setup and maintenance have to be done from a terminal with ssh. However, there are tools available to manage all this over Web UI using Cockpit.

Cockpit is a user-friendly web-based interface designed for managing Linux servers. It provides a centralized dashboard for system administrators, offering real-time monitoring, configuration, and troubleshooting capabilities. With a clean and intuitive interface, Cockpit simplifies tasks such as user management, software updates, network configurations, and more. Its modular design supports various plugins, enhancing its functionality and making it a versatile tool for server administration across different Linux distributions.

Let’s first install the cockpit and check if it is running fine with the following commands.

sudo apt install cockpit
systemctl status cockpit.socket

You can now access the cockpit from http://rpi-home:9090. Ignore the security warning due to the self-signed certificate the setup is using. You have to log in using a Linux user into the cockpit. Go ahead and log in with “admin”.

The additional bonus is that there are many cockpit Application (addins) available to manage various services. We can actually manage Samba (and NFS) from the cockpit (File Sharing addin) and also manage the file system (Navigator addin). They are not directly available in the Raspberry Pi OS repository. We have to first set up the repository and then install those. The following command will do it all.

curl -sSL https://repo.45drives.com/setup -o setup-repo.sh
sudo bash setup-repo.sh
sudo apt install cockpit-navigator
sudo apt install cockpit-file-sharing

Under the File Sharing menu on the Cockpit console, you can import the existing samba.conf file and start managing Samba from the cockpit.

From now on, you can just use the web-based ssh terminal from Cockpit console.

Happy sharing and streaming!

Building a Raspberry Pi File and Media Server: A DIY Guide for Seamless Home Content Sharing (2024)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Twana Towne Ret

Last Updated:

Views: 5313

Rating: 4.3 / 5 (44 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Twana Towne Ret

Birthday: 1994-03-19

Address: Apt. 990 97439 Corwin Motorway, Port Eliseoburgh, NM 99144-2618

Phone: +5958753152963

Job: National Specialist

Hobby: Kayaking, Photography, Skydiving, Embroidery, Leather crafting, Orienteering, Cooking

Introduction: My name is Twana Towne Ret, I am a famous, talented, joyous, perfect, powerful, inquisitive, lovely person who loves writing and wants to share my knowledge and understanding with you.