NFS mount on startup

Hi !
as there is no /etc/fstab which i can use, i tried to mount my nfs share with
/etc/rc.d/S95done and /etc/rc.local.
But this does not work:

Thu Mar 23 13:02:25 2023 daemon.notice procd: /etc/rc.d/S95done: mount: mounting 192.168.63.1:/development/openwrt/ap33 on /net/nfs4/ failed: Host is unreachable

Isnt the bridge up then ? my AP is connected with ethernet to the network where service is , and also has a static ip address.
How do you solve such things?

Ciao Gerd

I have added it in /etc/fstab

I read it will be deleted cyclic on some actions...

Ciao Gerd

I'm not sure what you mean.

I read somewhwere in documentation that /etc/fstab is not used by system and will be overwritten on some updates / scans
But i can give it a try :slight_smile:

Ciao Gerd

You are correct, sysupgrades will by default wipe out any existing fstab. You can tell sysupgrade/auc/asu to keep it (or any other file or directory) by appending the file name to /etc/sysupgrade.conf. Verify it using sysupgrade -l, which lists everything that is saved when doing an upgrade:

$ sysupgrade -l | grep fstab    # Should report nothing...

$ echo '/etc/fstab' >> /etc/sysupgrade.conf

$ sysupgrade -l | grep fstab
/etc/fstab
1 Like

in rc.local...

# Cool our heels until NFS server answers then mount
(
  while ! ping -c 1 nfs.address > /dev/null 2>&1; do sleep 2; done
  mount nfs.address:/mount /mnt/nfs
) &
2 Likes

/etc/config/fstab

1 Like

Hi !

all right works :slight_smile:

Do you have an example for nfs entry in uci fstab?

I'm not able to access my OpenWRT router at the moment (no external ports are open), so I didn't try to create an nfs mount stanza in /etc/config/fstab - I imagine given your response that you can't make it work?

Looking at the code for /sbin/block that does the actual mounts, it simply invokes the appropriate mount.xxx external executable to do the mount, so given that the stanza is constructed correctly, there doesn't appear to be any reason on the face of it that it would not work...?

static int exec_mount(const char *source, const char *target,
                      const char *fstype, const char *options)
{
	pid_t pid;
	struct stat s;
	FILE *mount_fd;
	int err, status, pfds[2];
	char errmsg[128], cmd[sizeof("/sbin/mount.XXXXXXXXXXXXXXXX\0")];

	snprintf(cmd, sizeof(cmd), "/sbin/mount.%s", fstype);

	if (stat(cmd, &s) < 0 || !S_ISREG(s.st_mode) || !(s.st_mode & S_IXUSR)) {
		ULOG_ERR("No \"mount.%s\" utility available\n", fstype);
		return -1;
	}

	if (pipe(pfds) < 0)
		return -1;

	fcntl(pfds[0], F_SETFD, fcntl(pfds[0], F_GETFD) | FD_CLOEXEC);
	fcntl(pfds[1], F_SETFD, fcntl(pfds[1], F_GETFD) | FD_CLOEXEC);

	pid = vfork();

	switch (pid) {
	case -1:
		close(pfds[0]);
		close(pfds[1]);

		return -1;

	case 0:
		to_devnull(STDIN_FILENO);
		to_devnull(STDOUT_FILENO);

		dup2(pfds[1], STDERR_FILENO);
		close(pfds[0]);
		close(pfds[1]);

		if (options && *options)
			execl(cmd, cmd, "-o", options, source, target, NULL);
		else
			execl(cmd, cmd, source, target, NULL);

		return -1;

	default:
		close(pfds[1]);

		mount_fd = fdopen(pfds[0], "r");

		while (fgets(errmsg, sizeof(errmsg), mount_fd))
			ULOG_ERR("mount.%s: %s", fstype, errmsg);

		fclose(mount_fd);

		err = waitpid(pid, &status, 0);

		if (err != -1) {
			if (status != 0) {
				ULOG_ERR("mount.%s: failed with status %d\n", fstype, status);
				errno = EINVAL;
				err = -1;
			} else {
				errno = 0;
				err = 0;
			}
		}

		break;
	}

	return err;
}

Is processed before the network is up.

Sort of, I was not able to find any working example.
I tried this:

config mount
        option device '10.0.2.5:/'
        option target '/mnt/backup'
        option enabled '1'
        option options 'nolock'

which works if set as
10.0.2.5:/ /mnt/backup nfs nolock in /etc/fstab, however it was not able to mount the folder either on boot or manually.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.