Skip to content

Instantly share code, notes, and snippets.

@arkon108
Created February 13, 2019 14:05
Show Gist options
  • Save arkon108/86cba0b742cb8791f9fe1e9639f5205b to your computer and use it in GitHub Desktop.
Save arkon108/86cba0b742cb8791f9fe1e9639f5205b to your computer and use it in GitHub Desktop.

Setting up Raspberry PI as a NAS

1. Install Raspbian

Once installed, connect online, open the terminal and run

sudo apt-get update && sudo apt-get upgrade

Open Preferences > Raspberry Pi Configuration and select to boot to CLI. Don't restart yet.

Enable SSH

On newer versions SSH is disabled by default. To enable it:

From Desktop:

  1. Launch Raspberry Pi Configuration from the Preferences menu
  2. Navigate to the Interfaces tab
  3. Select Enabled next to SSH
  4. Click OK

From the terminal with raspi-config

  1. Enter sudo raspi-config in a terminal window
  2. Select Interfacing Options
  3. Navigate to and select SSH
  4. Choose Yes
  5. Select Ok
  6. Choose Finish

2. Connect the Pi to the network

Disconnect from the display and keyboard, connect to router via LAN. Connect the drives which will be available from the Pi.

Plug in the power, and access it via SSH. Default hostname is raspberrypi, username pi and password is raspberry.

ssh pi@raspberrypi

If can't connect via hostname, try looking for Pi's IP address using

arp -a

3. Set up the drives

Install ntfs-3g to be able to access NTFS drives with:

sudo apt-get install ntfs-3g -y

Then find out the drives connected and their filesystems:

lsblk -f

It will output something like

NAME        FSTYPE LABEL              UUID                                 MOUNTPOINT
sda                                                                        
├─sda1      vfat   EFI                67E3-17ED                            
└─sda2      ntfs   qDrive             7206BEEA06BEAF0B                     
sdb                                                                        
└─sdb1      ntfs   Jebeno Veliki Disk 1450E3C750E3AE24                     

Mount points, UUID and filesystem can also be discovered using blkid.

sudo blkid
/dev/mmcblk0: PTUUID="000d59fd" PTTYPE="dos"
/dev/mmcblk0p1: LABEL="RECOVERY" UUID="6182-6A41" TYPE="vfat" PARTUUID="000d59fd-01"
/dev/mmcblk0p5: LABEL="SETTINGS" UUID="25655052-1f86-422f-ba13-95fb43cc5014" TYPE="ext4" PARTUUID="000d59fd-05"
/dev/mmcblk0p6: LABEL="boot" UUID="016B-29F2" TYPE="vfat" PARTUUID="000d59fd-06"
/dev/mmcblk0p7: LABEL="root" UUID="9a57d527-35a7-4743-abdc-f673efecd3c5" TYPE="ext4" PARTUUID="000d59fd-07"
/dev/sda1: LABEL="EFI" UUID="67E3-17ED" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="fabdb918-3ca6-4d82-9db5-9f1a5cfc3128"
/dev/sda2: LABEL="qDrive" UUID="7206BEEA06BEAF0B" TYPE="ntfs" PARTLABEL="QDRIVE" PARTUUID="1b7f7a1e-67c0-4309-97cc-f21d7a5cffd1"
/dev/sdb1: LABEL="Jebeno Veliki Disk" UUID="1450E3C750E3AE24" TYPE="ntfs" PARTUUID="00031541-01"

Mount drives

1. Create and endpoint for the drive
sudo mkdir /mnt/qDrive
2. Mount drive
sudo mount /dev/sda2 /mnt/qDrive
3. Update permissions
sudo chmod 777 /mnt/qDrive
4. Automounting drives

Run

sudo nano /etc/fstab

And add the following lines for drives

UUID=7206BEEA06BEAF0B /mnt/qDrive ntfs async,big_writes,noatime,nodiratime,nofail,uid=1000,gid=1000,umask=007 0 0
UUID=1450E3C750E3AE24 /mnt/JVD ntfs async,big_writes,noatime,nodiratime,nofail,uid=1000,gid=1000,umask=007 0 0

The UUIDs should be available from before by running blkid. uid and gid can be found by running

id -u pi && id -g pi
5. Test fstab & reboot
  1. Unmount any currently mounted drives in /mnt/ with sudo umount /mnt/qDrive
  2. Run sudo mount -a which will mount all currently unmounted drives
  3. Check if you can access the drives
  4. Reboot

Set up network shares

1. Install NFS

sudo apt install nfs-kernel-server -y

2. Edit the exports

Open the NFS exports file where you configure the paths to share and their permissions

sudo nano /etc/exports

Add the following lines

/mnt/qDrive *(rw,all_squash,insecure,async,no_subtree_check,anonuid=1000,anongid=1000)
/mnt/JVD *(rw,all_squash,insecure,async,no_subtree_check,anonuid=1000,anongid=1000)

This will allow anyone read/write access to the drives.

For other options, see link.

3. Export the config, enable the services on boot and start NFS

Trying to enable nfs-common ran into errors with masked service. Following this helped fix it.

sudo exportfs -ra
showmount -e localhost
sudo systemctl enable rpcbind
sudo systemctl enable nfs-kernel-server
sudo systemctl enable nfs-common
sudo systemctl enable nfs-common.service
sudo systemctl start rpcbind
sudo systemctl start nfs-kernel-server
sudo systemctl start nfs-common
sudo systemctl start nfs-common.service

3.a) Fix the problem with rpcbind starting before nfs-common

A known issue (examples)

Fix:

sudo nano /etc/rc.local 

Add the following, just above exit 0

sleep 20
systemctl restart nfs-common
systemctl restart nfs-common.service

Assign static IP to the PI

Run

sudo nano /etc/dhcpcd.conf

Add the following lines at the bottom

interface eth0

static ip_address=192.168.10.159/24
static routers=192.168.10.1
static domain_name_servers=192.168.10.1

interface wlan0

static ip_address=192.168.10.159/24
static routers=192.168.10.1
static domain_name_servers=192.168.10.1

Restart and test with

ip a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment