Mounting NFS Shares from TrueNAS in Proxmox

Mounting NFS Shares from TrueNAS in Proxmox

There are a few reliable ways to ensure Proxmox mounts NFS shares from a TrueNAS VM only after TrueNAS has fully booted:

1. Use a systemd service in Proxmox

Create a systemd service that mounts the NFS shares after the TrueNAS VM has started. This ensures the shares are available before any containers or VMs that depend on them boot.

  1. Create the service file:
cat > /etc/systemd/system/mount-truenas-nfs.service <<EOF
[Unit]
Description=Mount TrueNAS NFS shares
After=vzdump.service
Requires=vzdump.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/mount-truenas-nfs.sh
[Install]
WantedBy=multi-user.target
EOF
  1. Create the mount script:
cat > /usr/local/bin/mount-truenas-nfs.sh <<EOF
#!/bin/bash
mount -a
EOF
chmod +x /usr/local/bin/mount-truenas-nfs.sh
  1. Enable and start the service:
systemctl enable mount-truenas-nfs.service
systemctl start mount-truenas-nfs.service

2. Use a Proxmox hook script

Create a Proxmox hook script that mounts the NFS shares after the TrueNAS VM has started.

  1. Create the hook script:
cat > /etc/pve/hooks/after-start-vm.d/mount-truenas-nfs.sh <<EOF
#!/bin/bash
mount -a
EOF
chmod +x /etc/pve/hooks/after-start-vm.d/mount-truenas-nfs.sh
  1. Assign the hook to the TrueNAS VM:
pvesh set /nodes/$(hostname)/hooks/after-start-vm/100 --hookscript /etc/pve/hooks/after-start-vm.d/mount-truenas-nfs.sh --vmid <TRUENAS_VM_ID>

3. Use a startup script in TrueNAS

While not as reliable as the systemd service or hook script methods, you can create a startup script in TrueNAS to mount the NFS shares on the Proxmox host.

  1. Create the script in TrueNAS:
#!/bin/bash
ssh root@<PROXMOX_HOST_IP> mount -a
  1. Set the script to run at TrueNAS startup

Using these methods, Proxmox will reliably mount the NFS shares from TrueNAS after the TrueNAS VM has fully booted, ensuring the shares are available to any containers or VMs that depend on them.