Mounting SSD with Raspberry Pi and using NFS Kernel Server

Overview

This guide provides steps to share an SSD connected to a Raspberry Pi (referred to as the NFS server) with other devices on the network via the NFS protocol.

Set up automatic mounting

You can modify the fstab file to define where storage devices will be automatically mounted when the Raspberry Pi boots. For this we will need the UUID of the disk partition:

sudo blkid

Now open the fstab file:

sudo nano /etc/fstab

and add the following lines, replacing with your UUID and mount location:

UUID=abc-4def-4615-9ac6-xyz /home/shashank/ssd/ ext4 defaults 0

Now test with

sudo mount -a

Integrating NFS Kernel Server

  1. Install NFS Kernel Server:

    Update the package list and install the NFS Kernel Server package on the Raspberry Pi:

    sudo apt update
    sudo apt install nfs-kernel-server
  2. Create an Export Directory:

    Create a directory on your SSD where you’d like to store the files you want to share:

    sudo mkdir -p /mnt/ssd/nfs_shared
  3. Set Appropriate Permissions:

    Set the ownership and permissions of the export directory to allow access from network clients:

    sudo chown nobody:nogroup /mnt/ssd/nfs_shared
    sudo chmod 777 /mnt/ssd/nfs_shared

    Note: You might want to adjust permissions and ownership to match your specific security requirements.

  4. Configure NFS Exports (Optional):

    Edit the /etc/exports file to add the export directory:

    sudo nano /etc/exports

    Add the following line, replacing 192.168.1.0/24 with the subnet that matches your network:

     /home/shashank/ssd 192.168.1.11(rw,sync,no_subtree_check,no_root_squash) # Other machine IP
     /home/shashank/ssd 172.17.0.0/16(rw,sync,no_subtree_check,no_root_squash) # Any other docker intenal IP
     /home/shashank/ssd 172.18.0.0/16(rw,sync,no_subtree_check,no_root_squash) # Coolify internal IP
  5. Export the NFS Shares:

    After editing the /etc/exports file, export the shared directory:

    sudo exportfs -ra
  6. Start the NFS Service:

    Enable and start the NFS Kernel Server:

    sudo systemctl enable nfs-kernel-server
    sudo systemctl start nfs-kernel-server
  7. Verify NFS Server Status:

    Check that the NFS server is running properly:

    sudo systemctl status nfs-kernel-server
  8. Configure Firewall (Optional):

    If you have a firewall enabled, make sure to allow traffic on the necessary NFS ports (2049 for NFS):

    sudo ufw allow from 192.168.1.0/24 to any port 2049
    sudo ufw enable
    sudo ufw status
  9. Mount on the Client:

    On a client machine, mount the shared directory to access the SSD:

    sudo mount -t nfs 192.168.1.x:/mnt/ssd/nfs_shared /path/to/local/mountpoint

    Replace 192.168.1.x with the actual IP address of your NFS server, and /path/to/local/mountpoint with your chosen local mount point.