← cd ../blog

Build Your Own Mini-NAS with Raspberry Pi 5 + 128 GB USB Drive

A step-by-step guide to building a mini network-attached storage using a Raspberry Pi 5 and a USB drive.

nasraspberry-pihardwaretutorial

What you're making (in kid-sized words)

Think of your Raspberry Pi like a tiny library computer at home.

Your USB stick is the bookshelf.

We'll teach the Pi to share that bookshelf with everyone on your home Wi-Fi or Ethernet so any phone or laptop can save and read files there.

Four ideas to keep in your head:

  1. Disk (the USB stick)
  2. Folder where it lives (a mount point: /srv/nas)
  3. Sharing language for the network (SMB, also called "Samba")
  4. Permissions (who can read/write)

What you'll need

  • Raspberry Pi 5 with power supply
  • microSD card with Raspberry Pi OS (64-bit, Lite is fine)
  • 128 GB USB drive (plug into the blue USB 3 port)
  • Ethernet cable (faster/more stable than Wi-Fi)
  • A computer/phone on the same network

Tip: Give your Pi a fixed IP in your router's DHCP settings so the address doesn't change.


Big picture map (why each step matters)

  • Update the Pi → fewer bugs
  • Find the USB → don't touch the wrong disk
  • Format as ext4 → fast & safe for Linux
  • Mount at /srv/nas → one predictable place
  • Set permissions → you can write without sudo
  • Install Samba → other devices can connect
  • (Optional) Apple tweaks → iPhone/macOS friendlier
  • Backups → a NAS is not a backup until you copy it somewhere else

Step-by-step (copy/paste friendly)

Run these on the Pi (SSH or terminal). Lines starting with # are notes.

1) Update the Pi

sudo apt update && sudo apt full-upgrade -y
sudo reboot

2) Find your USB

lsblk -o NAME,MODEL,SIZE,FSTYPE,MOUNTPOINT

Look for ~128 GB. You'll see a disk like sda and maybe a partition like sda1.

3) Make the USB clean and Linux-friendly (ext4)

If your desktop auto-mounted the stick (shows a MOUNTPOINT like /media/...), unmount first:

udisksctl unmount -b /dev/sda1

# wipe any old signatures (be sure the letter is right!)
sudo wipefs -a /dev/sda
 
# new, modern partition table and one big partition
sudo parted -s /dev/sda mklabel gpt
sudo parted -s /dev/sda mkpart primary ext4 0% 100%
 
# make an ext4 filesystem with a friendly label
sudo mkfs.ext4 -F -L NAS128 /dev/sda1

Why? ext4 is fast and robust on Linux. If you must plug this USB into Windows often, use exFAT instead (different command), but ext4 is better for a NAS.

4) Mount it at a permanent place

# create the "bookshelf" place
sudo mkdir -p /srv/nas/public
 
# get the stable ID of the partition
UUID=$(blkid -s UUID -o value /dev/sda1)
 
# auto-mount on every boot (and reduce tiny writes to save USB life)
echo "UUID=$UUID /srv/nas ext4 defaults,nofail,noatime,lazytime 0 2" | sudo tee -a /etc/fstab
 
# mount now
sudo systemctl daemon-reload
sudo mount -a
 
# check
df -h | grep /srv/nas

If you see /srv/nas listed with ~128 GB → you're mounted.

5) Give yourself the right to write

sudo groupadd nas 2>/dev/null || true
sudo usermod -aG nas $USER
sudo chown -R $USER:nas /srv/nas
sudo chmod -R 775 /srv/nas
 
# make a handy shortcut in your Home folder
ln -s /srv/nas/public ~/NAS

If a write fails now, log out/in (or reboot) once so the new group membership takes effect.

Quick test:

touch /srv/nas/public/hello.txt

No error? Great—you can write.

6) Share it on your network (Samba/SMB)

sudo apt update
sudo apt install -y samba
sudo smbpasswd -a $USER   # set an SMB password for your Pi user

Add a share:

sudo nano /etc/samba/smb.conf

Append this to the bottom:

[Public]
   path = /srv/nas/public
   browsable = yes
   read only = no
   guest ok = no
   force group = nas
   create mask = 0664
   directory mask = 0775
   vfs objects = recycle
   recycle:repository = .recycle
   recycle:keeptree = yes
   recycle:versions = yes
   veto files = /._*/.DS_Store/Thumbs.db/

Enable + verify:

testparm
sudo systemctl enable --now smbd nmbd

7) Connect from your devices

  • macOS: Finder → Go → Connect to Server → smb://<Pi-IP>/Public
  • Windows: File Explorer → \\<Pi-IP>\Public
  • iPhone/iPad: Files app → "..." → Connect to Server → smb://<Pi-IP>/PublicRegistered User
  • Android: Use a file manager that supports SMB (e.g., CX/FE File Explorer)

Username: your Pi's Linux username (run whoami to confirm)

Password: the one you set with smbpasswd