📘 NFS Permissions Fix -Boot Script
Purpose
Ensure that a mounted NFS share has correct ownership and permissions for Docker containers every time the server boots.
1. Create a Permission Fix Script
Create a simple script that will reset ownership and permissions on the NFS mount point after boot.
sudo nano /usr/local/bin/fix-nfs-permissions.sh
Paste inside the script:
#!/bin/bash
# Fix NFS ownership
chown -R youruser:yourgroup /srv/nfs-mount
chmod -R 775 /srv/nfs-mount
(Replace youruser
and yourgroup
with your actual username and group.)
2. Make the Script Executable
sudo chmod +x /usr/local/bin/fix-nfs-permissions.sh
3. Create a systemd Service
Create a small service that runs the script automatically at boot:
sudo nano /etc/systemd/system/fix-nfs-permissions.service
Add this content:
[Unit]
Description=Fix NFS Permissions at Boot
After=network.target nfs-client.target remote-fs.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/fix-nfs-permissions.sh
[Install]
WantedBy=multi-user.target
4. Enable and Start the Service
# Reload systemd to recognize the new service
sudo systemctl daemon-reload
# Enable it to start at every boot
sudo systemctl enable fix-nfs-permissions.service
# Run it now without rebooting (optional)
sudo systemctl start fix-nfs-permissions.service
🚀 Summary
- Creates a simple fix script for NFS permissions
- Automates it via systemd on every reboot
- Useful for Docker setups that rely on consistent NFS access
🛠️ Useful Commands
# Check service status
sudo systemctl status fix-nfs-permissions.service
# Manually trigger the script
sudo /usr/local/bin/fix-nfs-permissions.sh
Tip: You can combine this technique with your Docker container volumes to ensure permissions stay stable even after a server or NFS reboot! 🎯
No Comments