Raspberry PI 4B Network File Sharing Setup

What ⚡

  • Using my older Raspberry Pi 4B as a dedicated file share using Samba.
  • Understanding how fast I can get this to go in my home and outside it, when traveling, by testing drive read and write speeds under different conditions.

Why 🤷‍♂️

I use the latest model Raspberry Pi to self-host some open source tools but have an older model PI I want to put to use for storage, backup and access of photos and videos. I am sure buying a Synology is easier and more powerful, but I like how efficient the Pis are (low energy consumption and very quiet) given low actual usage.

Findings 📋

Pi4 Network Limit

It turns out this model Pi4 maxes out at about 900 Mbps (~110 MB/s) a second for either read or write. I summarized my drive speed readings in the table below. I wasn’t sure if it would work for testing network drives but Black Magic Disk Speed Test” tool came through and allows me to actually collect some stats. It’s a fun tool.

Speed Summary

Clearly the internal SSD in my MacBook Pro is about 13x faster than any of the attached Samba drives and even though each attach Samba varies in actual disk speed (i.e. spinning disk is about 50% slower than the SanDisk SSD when directly attached to my MacBook Pro), when using Samba they all cap out near 100MB/s because of the network limit.

Write Read via notes
MacbookPro SSD 1355 MB/s 2572.5 MB/s Direct transfer,
internal SSD
Samba with External 5TB 100.6 MB/s 107 MB/s Ethernet This is because this is the max speed of this drive
Samba with internal flash 68.5 MB/s 98.3 MB/s Ethernet Thought this would be faster but not …
Samba with Sandisk SSD, external 74 MB/s 103 MB/s Ethernet

Mbps vs. MB confusion

One confusing thing about Black Magic’s readings is that they are recorded in bytes instead of bits. ISPs and speed readings are usually reported in bits and not bytes so it’s important to run the proper conversion and then realize that even 75MB/s is approaching the limit of your PI’s networking possibilities.

Dongle Limits

If you are hardwired into an Ethernet connection at home, like I am, using a dongle it’s also possible this dongle maxes out at around 1000 Mbps as well. I bought a faster 2500 Mbps dongle but still run into the PI4’s limit.

Disk Spin Down

I found the Western Digital external drive I connected seems to spin down on its own when not being used to save the disk and energy which means I didn’t need to configure something on Ubuntu like HDParm … it’s either drive that is doing this itself or that the latest version of Ubuntu have built in disk power management built in. I’m not sure on this and have an inclination to look it up because my habit is to look up everything, but I do like that it is just working and perhaps if I keep trying to look up everything I would never actually publish anything and I should be okay with this existing as an imperfect log of my project finding.

ExFat vs Ext4

exFAT format allows me to also plug the drive into my Mac, if I need to, and have it work but Ext4 is apparently much more efficient just on Linux/Ubuntu so would be better if the drive was to be completely committed to it.

Connecting while traveling

I currently use Cloudflare tunnels to connect to many self-hosted apps, but tunnels does not support the SMB protocol. The workaround is to use Cloudflare by either directly installed it on your Mac or using Cloudflare’s WARP client to connect to your home network remotely and then just COMMAND + K (on a Mac) to trigger your network connections and connect to the internal, private IP for your SMB and it should work. I’d prefer to use WireGuard but this requires opening a port on my local network to public internet and my ISP has trouble opening a port for me and I gave up on trying to get them to make it happen because Cloudflare’s tunnels are usually so good.

Server Setup 📋

OS = Ubuntu Server

I install this on Raspberry Pi’s, headless, instead of Raspbian.

Panel = CockPit

Cockpit is kind of a cool, very simple panel. I also use aaPanel if I want to run and deploy code but because this was just a simple file sharing tool I tried it and generally like it. I have tried running Open Media Vault before but, unfortunately, really didn’t like the interface and the fact that system edits using the GUI take many seconds to save. Open Media Vault does have some more advanced NAS-related features but the main one I was interested in was disk spin down which seems to be handled, as mentioned above.

Basic setup steps

  1. Install samba
  2. Connect drives to PI and use the USB3 slots, if possible
  3. Make sure they are seen by Ubuntu via lsblk -f
  4. Create folders on file system to mount the drives to with something like this sudo mkdir -p /mnt/SSD_2TB
  5. Mount the visible drives you wish to use with proper permissions sudo mount -t exfat -o defaults,uid=1000,gid=1000 /dev/sdb2 /mnt/SSD_2TB … can check if mounted with df -h
  6. In previous command, uid=1000 is my current user id and maps to
    “myname” (my Ubuntu alpha username) and can be found via id myusername
  7. Persist the mounting of this drive when the PI reboots via sudo nano /etc/fstab and then something like this /dev/sdb2 /mnt/2TB-SanDiskSSD1 exfat defaults,uid=1000,gid=1003 0 0
  8. Finally, make Samba aware of the mounted drive so it knows to use it make it available via sudo nano /etc/samba/smb.conf and then add the Samba config at the end of the file and then restart Samba sudo systemctl restart smbd

Disks Used

SanDisk Ultra MicroSD Flash

Amazingly, these are now only $25 for a 256GB card. SanDisk reports they max out at 190MB/s so slower than the SanDisk external SSDs. I am using just an 32GB flash for this setup since I planned on storing all data on external disks but for many projects it’s fun that you may not even need to attach an external drive to a PI anymore given how much storage these inexpensive microSDs can store.

5TB Western Digital External Drive

I like this one because it doesn’t require an extra power source and just runs off PI’s power. At around $115 it’s pretty cheap for 5TB for storage. Purchased a few of them in 2020 for file backup.

2TB SanDisk External SSD

This is an earlier model I bought in 2020 with max of 550MB/s. Newer models have even faster max.

Concluding thoughts

I may eventually buy a Synology, but I wanted to max out this method first. It’s a bit annoying that it takes a few seconds for media files to populate, but after these do there is little to no lag for file interaction.

Resources 🌐

  • Using “NVMe via USB 3.0 adapter” was one tip from ChatGPT, but it was an afterthought, and it admitted that stuff like this and even tuning Samba would have limited upside give limit of the PI4

Leave a Reply

Your email address will not be published. Required fields are marked *