# 📘 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.

<div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary" id="bkmrk-bash"><div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]">bash</div></div>```bash
sudo nano /usr/local/bin/fix-nfs-permissions.sh
```

Paste inside the script:

```bash
#!/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

```bash
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:

```bash
sudo nano /etc/systemd/system/fix-nfs-permissions.service
```

Add this content:

```ini
[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

```bash
# 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

```bash
# 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! 🎯