Overview:
This document contains setup guide for building Network Attached Storage (NAS) out of Raspberry Pi running in home network. NAS to be accessed remotely from the internet providing a personal Google Drive alternative for free.
Note: Full codebase and scripts will be added soon!
- Table of Content
- Setting Up Raspberry Pi as a NAS
- Samba Setup
- Access Shared Storage:
- Mount Drives
- Shared Storage Access Management
To turn your Raspberry Pi into a Network Attached Storage (NAS) that can also be accessed remotely, consider the following options:
-
Install an Operating System for NAS:
Raspberry Pi can run various NAS operating systems or configurations:- OpenMediaVault (Recommended): Lightweight, with features similar to TrueNAS.
- DietPi: A lightweight OS where you can configure Samba for file sharing.
- Raspberry Pi OS + Samba: A simple and flexible setup.
- Nextcloud: If you want a personal cloud storage solution.
-
Enable Remote Access:
- Use Dynamic DNS (e.g., No-IP, DuckDNS) to access your NAS from the internet.
- Configure port forwarding on your router to allow external access.
- For security, set up a VPN on your Raspberry Pi or use SSH tunneling.
-
Considerations:
- Ensure your Pi has adequate storage attached (via USB).
- Secure your system with strong passwords and keep software updated.
Here we will setup the NAS using RaspberryPi OS + Samba approach.
-
Install Samba:
Run the following command on your Raspberry Pi:sudo apt update sudo apt install samba samba-common-bin
-
Create a Directory to Share:
For example, create a directory namednasin thepiuser's home directory:mkdir /mnt/storage
-
Configure Samba:
Open the Samba configuration file:sudo nano /etc/samba/smb.conf
Add the following to the end of the file to share the
nasdirectory:[Shared] path = /mnt/storage/shared available = yes valid users = petrinax, @nas_admin, @nas_rw, @nas_ro read only = no browsable = yes public = no read list = @nas_ro write list = petrinax, @nas_admin, @nas_rw create mask = 0777 directory mask = 0777More details on configurations here.
-
Set a Samba Password for the User:
sudo smbpasswd -a <existing_linux_user> sudo smbpasswd -e <existing_linux_user>
-
Restart Samba:
sudo systemctl restart smbd
- Open File Explorer and type
\\<Raspberry_Pi_IP>\NAS.
- Use a file manager or mount the share with
smbclient.
- Open Finder and press
Command + Kto open theConnect to Serverwindow - Enter the SMB address of your Raspberry Pi
smb://100.x.x.x/shared_folder
- Replace 100.x.x.x with your Raspberry Pi's Tailscale IP and shared_folder with your Samba share name.
- Click Connect and enter your Samba username and password.
- The shared folder will appear in Finder under Locations.
Use a File Manager App with SMB Support.
- Open the file manager app and configure a new Network Storage (SMB) connection.
- Use the IP of your Raspberry Pi (e.g.,
100.x.x.x). - Enter your Samba credentials.
- Provide the path to the shared folder (e.g., shared_folder).
- Save the connection and browse your NAS files through the file manager.
List information about block devices, their file systems, and mount points:
lsblk -fMount FAT32 drive with specific ownership and permission settings:
sudo mount -o uid=1000,gid=1005,umask=0000 /dev/sda1 /mnt/storageMore details on filesystem specific mounts here.
Command Breakdown:
-
sudo: Runs the command with superuser privileges. mount: Mounts the file system. -
-o: Specifies additional options for the mount command.
Options Passed:
-
uid=1000: Sets the user ID for ownership of the files and directories. 1000 is the default UID for the first user (e.g., pi on Raspberry Pi). You can check your UID with id username. -
gid=1000: Sets the group ID for ownership of the files and directories. 1000 is the default GID for the primary group of the first user. -
umask=0000: Sets the permissions mask for files and directories. 0000 results in: Directories & Files: rwxrwxrwx (Owner, group and others have full access read/write/execute). -
/dev/sda1: Specifies the device name of the FAT32 drive to mount. -
/mnt/storage: Specifies the directory where the drive will be mounted.
Adding an entry for your FAT32 drive in /etc/fstab ensures it's mounted automatically at boot with the desired options.
/dev/sda1 /mnt/storage vfat uid=1000,gid=1000,umask=0022 0 0Explanation:
-
/dev/sda1: The device name of the drive. -
/mnt/storage: The mount point for the drive. -
vfat: The file system type (used for FAT32). -
uid=1000,gid=1000,umask=0022: Ownership and permission options. -
0 0: The first0disables file system dumps. The second0disables file system checks during boot.
Check the ownership and permissions of the mount point:
ls -ld /mnt/storagels: Lists files and directories.-l: Displays detailed information, including permissions, owner, and group.-d: Shows information about the directory itself (not its contents).
sudo umount /mnt/storagesudo systemctl daemon-reloadRemount all file systems based on the updated /etc/fstab:
sudo mount -aIt will remount all the file systems defined in /etc/fstab that are not already mounted.
If unmounting fails with umount: /mnt/storage/: target is busy. error. Try stopping Samba service:
sudo systemctl stop smbdOnce unmounted restart smb daemon:
sudo systemctl start smbd- Configured NAS drive: Shared
- Mount path:
/mnt/storage/shared
Users needs to be added to following groups for Shared Storage access.
| Group | Description |
|---|---|
nas_admin |
Full access to all files and configurations. |
nas_rw |
Can read and write to shared directories. |
nas_ro |
Can only read files in shared directories. |