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 blkidNow open the fstab file:
sudo nano /etc/fstaband add the following lines, replacing with your UUID and mount location:
UUID=abc-4def-4615-9ac6-xyz /home/shashank/ssd/ ext4 defaults 0Now test with
sudo mount -aIntegrating NFS Kernel Server
-
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 -
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 -
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_sharedNote: You might want to adjust permissions and ownership to match your specific security requirements.
-
Configure NFS Exports (Optional):
Edit the
/etc/exportsfile to add the export directory:sudo nano /etc/exportsAdd the following line, replacing
192.168.1.0/24with 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 -
Export the NFS Shares:
After editing the
/etc/exportsfile, export the shared directory:sudo exportfs -ra -
Start the NFS Service:
Enable and start the NFS Kernel Server:
sudo systemctl enable nfs-kernel-server sudo systemctl start nfs-kernel-server -
Verify NFS Server Status:
Check that the NFS server is running properly:
sudo systemctl status nfs-kernel-server -
Configure Firewall (Optional):
If you have a firewall enabled, make sure to allow traffic on the necessary NFS ports (
2049for NFS):sudo ufw allow from 192.168.1.0/24 to any port 2049 sudo ufw enable sudo ufw status -
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/mountpointReplace
192.168.1.xwith the actual IP address of your NFS server, and/path/to/local/mountpointwith your chosen local mount point.