I had a little annoying issue. Just updated my Proxmox host and rebooted it. Later, my Home Assistant backup sync to NAS failed because its NFS destination wasn’t mounted.
The NAS was on. The host had come back up. But three NFS mounts had timed out during boot and stayed down. But, when i mount them manually, it worked.
The boot log showed a brief network link interruption while the mounts were starting. That gave me a hint, though it didn’t explain the whole timeout. I wanted the host to try again once things had settled, then leave a clear failure in the journal if it still couldn’t mount the shares.
This is the recovery pattern I used, adapted here for either NFS or CIFS/SMB shares. It works with normal
/etc/fstabmounts on systemd-based Debian, Ubuntu, and Proxmox hosts.
TL;DR
- Keep your working mount definitions in
/etc/fstab. - Check them 10 minutes after boot, with up to three recovery attempts and 10-minute gaps between attempts.
- Stop when the shares are working. After the third failure, log
MOUNT_RECOVERY_FAILEDand leave a failed systemd service to investigate.
This handles mounts that fail during startup. Once recovery succeeds, the timer stops for that boot. It won’t keep watching for a NAS outage later in the day.
1. Check the mount before adding retries
Run these instructions as root in Bash. On Debian or Ubuntu, start with sudo -i. The Proxmox shell normally already runs as root.
Install the client helper for the share you use:
# NFSapt install nfs-common
# CIFS / SMBapt install cifs-utilsThe script also uses findmnt, mountpoint, flock, and timeout, normally available through the standard util-linux and coreutils packages.
I’ll use these example mounts. Replace the addresses, shares, and local paths with yours. Keep only the entries you need.
192.0.2.10:/exports/backups /mnt/nas-backups nfs _netdev,nofail,vers=4.1 0 0//192.0.2.20/team /mnt/team-share cifs _netdev,nofail,credentials=/root/.smb-team,vers=3.0 0 0These addresses are placeholders. The CIFS example assumes /root/.smb-team already contains working credentials and is readable only by root. Keep your existing, tested options rather than replacing them just to match mine.
After editing fstab, create the mount directories and reload systemd’s generated units:
mkdir -p /mnt/nas-backups /mnt/team-sharesystemctl daemon-reloadCheck one share manually before installing recovery:
mount -v /mnt/nas-backupsfindmnt --mountpoint /mnt/nas-backupsFor CIFS, use /mnt/team-share instead. A successful findmnt result should show the remote share and its filesystem type. A plain local directory at that path isn’t enough.
If mounting fails every time, fix that error first. Retries won’t correct an NFS export permission or an expired SMB password.
The _netdev option identifies a network mount. nofail lets boot continue if it is unavailable, so programs using the path must still check it before writing. See the systemd mount options (opens in a new tab).
For NFS, I haven’t added soft just to make failures return faster. That changes how filesystem I/O fails and can risk data corruption. The NFS manual explains the tradeoff (opens in a new tab). The timeout below limits the recovery command, not normal application I/O.
2. Create the recovery script
Create /usr/local/sbin/mount-recovery with the complete script below. Edit the two rows under SHARES to match your fstab entries exactly. Remove a row if you only use one share. Use simple mount paths without spaces for this example.
Each row is a local mount path followed by its expected remote source. Checking the source helps avoid treating the wrong mounted filesystem as a successful recovery.
#!/usr/bin/env bashset -euo pipefail
state=/run/mount-recoverymkdir -p "$state"exec 9>"$state/lock"flock -n 9 || exit 0
attempt=0if [[ -f "$state/attempt" ]]; then read -r attempt < "$state/attempt"fi
if [[ ! "$attempt" =~ ^[0-3]$ ]]; then systemctl stop mount-recovery.timer echo '<3>MOUNT_RECOVERY_FAILED: invalid attempt counter' exit 1fi
if (( attempt >= 3 )); then systemctl stop mount-recovery.timer echo '<3>MOUNT_RECOVERY_FAILED: retries exhausted, reset before trying again' exit 1fi
attempt=$((attempt + 1))printf '%s\n' "$attempt" > "$state/attempt"echo "<6>MOUNT_RECOVERY_ATTEMPT: $attempt/3"failed=()
while read -r path expected; do if ! mountpoint -q "$path"; then echo "<6>Mounting $path from fstab" if ! timeout --kill-after=5s 60s mount "$path"; then echo "<4>Mount command failed or timed out: $path" fi fi
actual=$(findmnt -rn -M "$path" -t nfs,nfs4,cifs -o SOURCE || true)
if [[ "$actual" != "$expected" ]]; then echo "<4>Missing mount or unexpected source: $path" failed+=("$path") elif ! timeout --kill-after=5s 10s ls -U -- "$path" >/dev/null; then echo "<4>Mounted but directory check failed: $path" failed+=("$path") else echo "<6>Healthy: $path ($actual)" fidone <<'SHARES'/mnt/nas-backups 192.0.2.10:/exports/backups/mnt/team-share //192.0.2.20/teamSHARES
if (( ${#failed[@]} == 0 )); then systemctl stop mount-recovery.timer echo '<6>MOUNT_RECOVERY_OK: all shares healthy, stopping timer' exit 0fi
if (( attempt < 3 )); then echo "<4>MOUNT_RECOVERY_RETRY: ${failed[*]}, next attempt in 10 minutes" exit 0fi
systemctl stop mount-recovery.timerecho "<3>MOUNT_RECOVERY_FAILED: after 3 attempts: ${failed[*]}"exit 1Make it executable and check its syntax:
chmod 0755 /usr/local/sbin/mount-recoverybash -n /usr/local/sbin/mount-recoveryI don’t want a recovery script force-unmounting a share while another job might be using it.
The directory check doesn’t provide any proof if the write access enabled or backup process was completed.
Kernel I/O stuck in an uninterruptible wait can also outlast a timeout signal.
3. Add the service and timer
Create /etc/systemd/system/mount-recovery.service. It runs the script once as root each time the timer activates it.
[Unit]Description=Recover failed NFS and CIFS mounts after bootWants=network-online.targetAfter=network-online.target remote-fs.target
[Service]Type=oneshotExecStart=/usr/local/sbin/mount-recoveryRuntimeDirectory=mount-recoveryRuntimeDirectoryMode=0700RuntimeDirectoryPreserve=yesTimeoutStartSec=5minStandardOutput=journalStandardError=journalSyslogIdentifier=mount-recoverySyslogLevelPrefix=yesUMask=0077RuntimeDirectoryPreserve=yes keeps the counter between attempts. It lives under /run, so it resets at reboot. The <6>, <4>, and <3> prefixes become info, warning, and error priorities in the journal. The prefixes themselves are removed. Both settings are covered in systemd’s execution options (opens in a new tab).
Five minutes gives these two shares room for their mount attempts and directory checks. Increase TimeoutStartSec if you add several more shares. Otherwise systemd could stop the script before it reaches its final failure message.
Now create /etc/systemd/system/mount-recovery.timer:
[Unit]Description=Retry failed network mounts at ten minute intervals
[Timer]OnBootSec=10minOnUnitInactiveSec=10minAccuracySec=1sUnit=mount-recovery.service
[Install]WantedBy=timers.targetThe first check is due 10 minutes after boot. Further attempts run 10 minutes after the previous run finishes, so slow mount commands extend the schedule. The normal boot mount attempt is separate from these three retries. The systemd timer reference (opens in a new tab) explains those starting points.
Earlier failures return exit code 0 so the timer can continue. The third unsuccessful attempt returns 1, which leaves the service failed. A successful run stops the timer immediately.
4. Enable it and inspect the first run
Check the files, reload systemd, then enable the timer:
systemd-analyze verify /etc/systemd/system/mount-recovery.service \ /etc/systemd/system/mount-recovery.timersystemctl daemon-reloadsystemctl enable --now mount-recovery.timersystemctl list-timers --all mount-recovery.timerIf the machine has already been up for more than 10 minutes, the first run is due immediately. Otherwise you can wait, or run one check now:
systemctl start mount-recovery.servicejournalctl -b -u mount-recovery.service --no-pagerA manual run uses one attempt too. After success, the timer is enabled but inactive. That’s expected: it stopped for this boot and will start again at the next boot.
On my Proxmox host, the live check found all three NFS shares healthy and stopped its timer. I also checked the retry limit with simulated failures. The mixed NFS/CIFS example here uses generic paths, and I haven’t fully verified its CIFS behavior against a real SMB server or tested a reboot with it.
5. Find the mount failure in journald
Start with the current boot’s recovery log:
journalctl -b -u mount-recovery.service --no-pagerFor warnings and errors, then only errors and higher priorities:
journalctl -b -u mount-recovery.service -p warning --no-pagerjournalctl -b -u mount-recovery.service -p err --no-pagerTo find the final message directly:
journalctl -b -u mount-recovery.service \ --grep='MOUNT_RECOVERY_FAILED' --no-pagersystemctl --failedAn example final log entry looks like this sample below:
Nov 26 10:35:00 server mount-recovery[1234]: MOUNT_RECOVERY_FAILED: after 3 attempts: /mnt/nas-backupsRemove the -p filter when investigating the cause. The earlier mount helper error is usually more useful than the final summary. You can also watch the next attempt live with:
journalctl -f -u mount-recovery.serviceFor the previous boot, use journalctl -b -1 -u mount-recovery.service. That needs retained logs from that boot. You can find more filters in the journalctl reference (opens in a new tab).
If the error still isn’t clear, inspect the original mount unit and kernel messages:
mount_unit=$(systemd-escape --path --suffix=mount /mnt/nas-backups)journalctl -b -u "$mount_unit" --no-pagerjournalctl -k -b --no-pager | grep -Ei 'nfs|cifs|smb|link.*(up|down)'Replace the path for your CIFS share when needed. systemd-escape handles hyphens in mount paths, so you don’t have to guess the generated unit name.
| What the log says | What to check next |
|---|---|
| Mount timed out or host unreachable | NAS availability, routing, firewall, and whether the host’s link dropped during boot. |
| NFS access denied | Export path and the client address allowed by the NAS. |
| CIFS permission denied | Credentials file, account permissions, and share access. Check kernel messages for more detail. |
| Missing mount or unexpected source | The fstab entry and the script’s SHARES rows. Compare them with findmnt --mountpoint PATH -o SOURCE,FSTYPE. |
| Mounted but directory check failed | The share is attached but the read check failed. Investigate NAS responsiveness and permissions before deciding how to recover it. |
Reset the three attempts, or remove the timer
Stop the units before clearing the counter:
systemctl stop mount-recovery.timersystemctl stop mount-recovery.servicerm -f /run/mount-recovery/attemptsystemctl reset-failed mount-recovery.servicesystemctl start mount-recovery.timerOn a host already past the 10-minute boot mark, that schedules the first check immediately.
To remove recovery later:
systemctl disable --now mount-recovery.timersystemctl stop mount-recovery.servicesystemctl reset-failed mount-recovery.servicerm /etc/systemd/system/mount-recovery.timerrm /etc/systemd/system/mount-recovery.servicerm /usr/local/sbin/mount-recoverysystemctl daemon-reloadrm -rf /run/mount-recoveryYour existing fstab entries and mounted shares stay in place. Before rerunning a backup, check its destination again.
Did you came across similar issues? How did you fix it? Let me know in the comment below.
Comments
Loading comments…