Problem with mounting on demand FS

Hello dears,

I’m trying to configure mounting on demand between RedHat machine which is the server machine in this case and CentOS which is the client machine. I have configured the following:

On RedHat server machine I’ve installed nfs-utils, started nfs-server service and edited /etc/exports file:

[armin@rhel-h1 ~]$ cat /etc/exports
/tmp/on_demand_srv 172.25.5.6(rw,sync,no_root_squash,no_all_squash,no_subtree_check)

On CentOS machine, I’ve installed autofs and configure the /etc/auto.master and /etc/auto.shares files:

[armin@centos-h1 ~]$ tail -1 /etc/auto.master
/shares /etc/auto.shares --timeout=400

[armin@centos-h1 ~]$ cat /etc/auto.shares
mynetworkshare -fstype=auto 172.25.5.7:/tmp/on_demand_srv

I also reloaded autofs service and stopped firewall on RHEL machine. But when I try to access on /shares/mynetworkshare I got the message there is no mynetworkshare dir. Please let me know if I’m right, we are supposed to install and configure autofs only on the client machine where we are going to access on desire dir which should be mounted on demand ?

If anyone could help me I’d be thankful.

I tried this out on a pair of Ubuntu VMs and it works for me. Verify that the nfs export is valid:

root@nfs-client:~# cat /etc/auto.master | grep -v '#'
+dir:/etc/auto.master.d
+auto.master
/shares /etc/auto.shares
root@nfs-client:~# cat /etc/auto.shares 
mynetworkshare -fstype=auto    192.168.66.3:/opt/autoshare
root@nfs-client:~# showmount --exports 192.168.66.3
Export list for 192.168.66.3:
/opt/autoshare *
root@nfs-client:~# cd /shares/mynetworkshare
root@nfs-client:/shares/mynetworkshare# ls
1  2  3  dir1  dir2  dir3  hello  world

I can’t understand where I’m making mistake. Configuration on the client side looks like this:

[armin@centos-h1 shares]$ cat /etc/auto.master | egrep -v '^#|^$'
+dir:/etc/auto.master.d
+auto.master
/shares /etc/auto.shares

[armin@centos-h1 shares]$ cat /etc/auto.shares
mynetworkshare -fstype=auto 172.25.5.7:/opt/on_demand_srv

On the server side configuration looks like this:

[armin@rhel-h1 ~]$ df -h --output=source,fstype,target -t ext4
Filesystem     Type Mounted on
/dev/sdb1      ext4 /opt/on_demand_server

[armin@rhel-h1 ~]$ sudo exportfs -v
/opt/on_demand_srv
                172.25.5.6(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)

Bu when I try to access on directory /shares/mynetworkshare, I got the following message:

[armin@centos-h1 ~]$ cd /shares/mynetworkshare
-bash: cd: /shares/mynetworkshare: No such file or directory

Currently I don’t have idea what I’m doing in the wrong way :frowning:

What does showmount --exports 172.25.5.7 show?

It shows the following output:

[armin@centos-h1 ~]$ sudo showmount --exports 172.25.5.7
Export list for 172.25.5.7:
/opt/on_demand_srv 172.25.5.6

You have mouted /opt/on_demand_server on rhel-h1 but you are exporting /opt/on_demand_srv

1 Like

Dear @al1, You’re right :slight_smile: I fixed it and edit /etc/exports on rhel-h1 machine:

[armin@rhel-h1 ~]$ cat /etc/exports
/opt/on_demand_server 172.25.5.6(rw,sync,no_root_squash,no_all_squash,no_subtree_check)

On the client side I also fixed /etc/auto.shares file:

[armin@centos-h1 mynetworkshare]$ cat /etc/auto.shares 
mynetworkshare -fstype=auto 172.25.5.7:/opt/on_demand_server

[armin@centos-h1 mynetworkshare]$ sudo showmount --exports 172.25.5.7
Export list for 172.25.5.7:
/opt/on_demand_server 172.25.5.6

Finally, everything works fine now:

[armin@centos-h1 mynetworkshare]$ pwd;ls -la
/shares/mynetworkshare
total 4
drwxr-xr-x. 2 root root 4096 Mar 20 13:15 .
drwxr-xr-x. 3 root root    0 Mar 20 13:11 ..
-rw-r--r--. 1 root root    0 Mar 20 13:15 something

Just one more question - is it ok if I can see /shares/mynetworkshare mountpoint as the output of df command or it should be mounted only if there is some r/w operation on this mountpoint ?

[armin@centos-h1 ~]$ df -h -t nfs4
Filesystem                        Size  Used Avail Use% Mounted on
172.25.5.7:/opt/on_demand_server  974M     0  907M   0% /shares/mynetworkshare

@al1 thank You a lot for your help.

It should only show in df when it is mounted.

I understand. I tested it and “df” shows it only when is mounted. Thank you for your time and effort.