$ webtoolist --read
Raspberry Pi File Server
medium · 2-3 hours
Turn a Raspberry Pi and an external drive into an always-on network file server with Samba shares and automated backups.
raspberry-pinassambaself-hostinglinux Safety notes:
- Power the drive from a powered USB hub or use a separately powered enclosure — the Pi's ports can only supply about 1.2 A total.
- Unmount drives before unplugging; pulling power mid-write corrupts filesystems.
- Shut down with 'sudo poweroff', never by yanking the power cord.
Parts
- Raspberry Pi 4 or 5 (2 GB+ recommended)
- Class 10 microSD card, 32 GB
- External USB drive, 1 TB+ (preferably an SSD or a powered HDD enclosure)
- 5V USB-C power supply, official Pi unit
- Ethernet cable (recommended over Wi-Fi for a server)
Tools
- Computer with an SD card reader
- Raspberry Pi Imager (free)
- Second USB drive or NAS space for backups
A Pi file server is the classic first homelab project: cheap parts, an afternoon of work, and a genuinely useful result — shared storage for every device in the house, running on ~4 W.
Steps
- Flash the OS. In Raspberry Pi Imager, choose Raspberry Pi OS Lite (64-bit). In the settings, set a hostname (
fileserver), enable SSH, and configure your user and password before the first boot. - Boot and connect. Insert the SD card, attach Ethernet and power, then SSH in:
ssh user@fileserver.local. Runsudo apt update && sudo apt full-upgrade. - Prepare the drive. Identify it with
lsblk(look for the size, e.g./dev/sda). Partition and format it as ext4:sudo mkfs.ext4 /dev/sda1. Ext4 preserves Linux permissions, which NTFS does not. - Mount it permanently. Find the UUID with
sudo blkid, create a mount point (sudo mkdir -p /mnt/storage), then add to/etc/fstab:
TheUUID=your-uuid /mnt/storage ext4 defaults,nofail 0 2nofailoption keeps the Pi bootable if the drive is absent. Runsudo mount -ato test. - Install Samba.
sudo apt install samba, then append a share to/etc/samba/smb.conf:
Set the SMB password:[storage] path = /mnt/storage browseable = yes writeable = yes valid users = pisudo smbpasswd -a pi, then restart withsudo systemctl restart smbd. - Connect from your devices. macOS Finder → ⌘K →
smb://fileserver/storage. Windows Explorer →\\fileserver\storage. Linux file managers handlesmb://natively. - Add automated backups. Install rsync and add a nightly cron job (
crontab -e):
Point it at a second drive — a mirror on the same disk protects against accidental deletion, not disk death.0 3 * * * rsync -a --delete /mnt/storage/ /mnt/backup/mirror/ - Harden the basics. Change the default password, install unattended upgrades (
sudo apt install unattended-upgrades), and enablefsckscheduling. Checksmartctl -a /dev/sdaoccasionally for drive health.
Troubleshooting
- Share visible but writes fail → check Linux permissions on the mount (
ls -ld /mnt/storage); Samba users need filesystem-level write access, not justwriteable = yes. - Drive shows up as
sdbafter a reboot → don’t rely on device names; always mount by UUID in/etc/fstab. fileserver.localnot resolving → mDNS can be flaky on some routers; usearp -aor your router’s client list to find the IP and set a DHCP reservation.- Random disconnects under load → almost always insufficient USB power. Use a powered hub or a drive with external power.
- Slow transfers over Wi-Fi → the Pi’s Wi-Fi shares bandwidth with the drive’s USB traffic; switch to Ethernet.