Add several IP for NFS share

Hi,
I’m a new user of PR4100.
I was looking to share folders in NFS and i’m quite disapointed as you can’t add several non consecutive IP with the UI.
There is only one edit field for host as you can see here and i need to add the following IP : 192.168.0.14 192.168.0.15 192.168.0.100 192.168.0.21 192.168.0.10

(edit : adding “*” or “192.168.0.0/24” in host is NOT an option )

I maybe wrong but I think i’ll have to manually edit

/etc/exports

with

“/nfs/repos” 192.168.0.100(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000) 192.168.0.14(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000) 192.168.0.15(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000) 192.168.0.21(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)

… Am i right ? In order to do it, I’ll have to install SSH too.

I’m coming from Synology and Qnap world and for now it seems WD’s OS is a lot worse than other existing NAS OS.

seems like it’s not a viable solution because every time you change something in UI, /etc/exports file is overwritten when browsing the ui or rebooting :’(
Can i make any permanent changes to /etc/exports ?

i think i 've just found out how to do it :
exportfs -ra should made the changes permanent.

1 Like

You can also hook the commands to overwrite exports into the init.sh of any app in /shares/Volume_1/Nas_Prog

how do you do such a thing ?

I’d recommend getting Entware (search forum) and append something like this to the entware init.sh

cp ${APPDIR}/exports /etc/exports
exportfs -ra

This init.sh is located at /shares/Volume_1/Nas_Prog/entware/init.sh
Then copy your custom exports file to /shares/Volume_1/Nas_Prog/entware/exports

I already got entware, I’ll try that asap ! Thanks for your help !

An alternative is using the proper place for init scripts in /opt/etc/init.d

Wierd, i got no such directory :

    root@NAS1 / # cd /opt/ && ll
    drwxr-xr-x    2 root     root             0 Aug  4 18:03 .
    drwxrwxr-x   20 root     root             0 Aug  4 18:05 ..
    lrwxrwxrwx    1 root     root            18 Aug  4 18:03 firefly -> /usr/local/firefly
    lrwxrwxrwx    1 root     root            27 Aug  4 18:03 perl5.10 -> /usr/local/modules/perl5.10
    lrwxrwxrwx    1 root     root            25 Aug  4 18:03 wd -> /usr/local/modules/opt/wd
    root@NAS1 /opt # cd ../etc/init.d/
    root@NAS1 init.d # ll
    drwxr-xr-x    2 root     root             0 Oct 16  2017 .
    drwxrwxr-x   27 root     root             0 Aug 21 18:17 ..
    -rwxrwxr-x    1 root     root          1782 May 15 04:20 AddVolumes.py
    -rwxrwxr-x    1 root     root            94 May 15 04:20 S14hwinit
    -rwxrwxr-x    1 root     root          2018 May 15 04:20 S14wdhws
    -rwxrwxr-x    1 root     root          2018 May 15 04:20 S15wdlcd
    -rwxrwxr-x    1 root     root          2035 May 15 04:20 S20wdpms
    -rwxrwxr-x    1 root     root          2398 May 15 04:20 S20wdtmsd
    -rwxr-xr-x    1 root     root          3530 Oct 10  2018 atop
    -rwxr-xr-x    1 root     root           777 Oct 17  2017 commgrd
    -rwxr-xr-x    1 root     root          5631 Oct 13  2017 onbrdnetloccommd
    -rwxr-xr-x    1 root     root          1052 Nov 13  2015 restsdk-serverd
    -rwxrwxr-x    1 root     root          1933 May 15 04:24 wdappmgrd
    -rwxr-xr-x    1 root     root          2422 Sep 10  2018 wdmcserverd
    -rwxr-xr-x    1 root     root          2086 Aug 19  2015 wdnotifierd
    -rwxr-xr-x    1 root     root          1865 Sep 10  2018 wdphotodbmergerd
    root@NAS1 init.d #

That means that Entware is not enabled / installed. Here’s how to initialize it again (after installation)

cd /shares/Volume_1/Nas_Prog/entware
./init.sh $(pwd)
ls /opt

Ok, I’ve re-installed entware and now i got the directory /opt/etc/init.d/
I added your command to overwrite /etc/exports in /shares/Volume_1/Nas_Prog/entware/init.sh but nothing seems to happen :frowning:
I logged the steps in init.sh and it seems every command completes successfully but something happen after the init.sh script and overwrite again the /etc/exports back to original values … :frowning:

When does the init.sh script run ?

NFS is managed by the readable /usr/sbin/nfs script.
But the NFS config is created by the binary /usr/sbin/nfs_config tool…
NFS is restarted during several functions of /usr/sbin/load_module

Now that I’ve been through these scripts, I suggest you override /usr/sbin/nfs_config in your entware init.
So entware should replace /usr/sbin/nfs_config by

#!/bin/sh

cat <<EOF > /etc/exports
/another/exported/directory 192.168.0.3(rw,sync)
EOF

Or even better, in entware init, rename nfs_config to /usr/sbin/nfs_config_orig and create a new /usr/sbin/nfs_config

#!/bin/sh

# create OS3 based exports
nfs_config_orig

# append custom exports
cat <<EOF >> /etc/exports
/another/exported/directory 192.168.0.3(rw,sync)
EOF

Dont’ forget to chmod +x here.

Thank you for your time and dedication ! I’ll try that asap. :crossed_fingers:

Now that I’ve been through these scripts, I suggest you override /usr/sbin/nfs_config in your entware init.

There is no such command line in entware /shares/Volume_1/Nas_Prog/entware/init.sh script.
I may not look in the right file.

Moreover, i’m not able to copy/rename nfs_config file to nfs_config_ori :slightly_frowning_face:

root@NAS1 usrsbin # cp nfs_config nfs_config_ori
cp: can't create 'nfs_config_ori': Read-only file system
root@NAS1 usrsbin # pwd
/usr/local/modules/usrsbin

Any suggestions ?

That because you’re in /usr/local/modules/usrsbin. Not the same as /usr/sbin
Add this to entware init

mv /usr/sbin/nfs_config /usr/sbin/nfs_config_orig
ln -sf /opt/sbin/nfs_config /usr/sbin/nfs_config 

EDIT: fixed symlink

Then create /opt/sbin/nfs_config

#!/bin/sh

# create OS3 based exports
/usr/sbin/nfs_config_orig

# append custom exports
cat <<EOF >> /etc/exports
/another/exported/directory 192.168.0.3(rw,sync)
EOF

Unfortunatly, the script created in /opt/sbin/nfs_config disapear after a reboot. :worried:

/shares/Volume_1/entware gets bind mounted to /opt during entware init.
As soon as this happens, /opt is persistent.
Eventually put the file in /shares/Volume_1/entware/sbin/nfs_config, which should become /opt/sbin/nfs_config during entware init.

Don’t put stuff in /opt when entware is disabled (= not bind mounted) as it will disappear on reboot.

If this still happens, please provide output of

ls /opt
ls -l /usr/sbin/nfs_config*

And the contents of entware init.

Hello, I’ve tried that but still the same :confounded:

root@NAS1 root # cat /etc/exports
root@NAS1 root # ls /opt
bin    etc    home   lib    root   sbin   share  tmp    usr    var    wd
root@NAS1 root # ls -l /usr/sbin/nfs_config*
lrwxrwxrwx    1 root     root            37 Aug 28 11:40 /usr/sbin/nfs_config.ori -> /usr/local/modules/usrsbin/nfs_config
root@NAS1 root # cat /shares/Volume_1/Nas_Prog/entware/init.sh
#!/bin/sh

[ -f /tmp/debug_apkg ] && echo "APKG_DEBUG: $0 $@" >> /tmp/debug_apkg

APPDIR=$1
LOG=/tmp/debug_apkg

echo "Entware init.sh linking files from path: $APPDIR" >> $LOG

# create link to binary...
OPKG=/opt/bin/opkg
OPTROOT=/shares/Volume_1/entware
if [ ! -f $OPKG ]; then
    [ ! -d $OPTROOT ] && echo "Entware root dir not found!" >> $LOG && exit 1
    mount --bind $OPTROOT /opt
    echo "Mounted Entware root to /opt" >> $LOG
fi

# add wd opt dir again
WDOPT=/usr/local/modules/opt/wd
ln -sf $WDOPT /opt/wd

# update profile
PROFILE=/etc/profile
[ ! -f $PROFILE ] && cp $APPDIR/profile $PROFILE

# restore home dir
mkdir -p /home/root
rsync -a ${APPDIR}/home/ /home/root

# link web to /var/www just for the app icon
WEBPATH=/var/www/entware/
mkdir -p $WEBPATH
ln -sf $APPDIR/web/* $WEBPATH
echo "Created Entware web dir symlink" >> $LOG

# script pour monter correctement mes partages nfs
# voir https://community.wd.com/t/add-several-ip-for-nfs-share/239604/14
mv /usr/sbin/nfs_config /usr/sbin/nfs_config.ori
ln -sf /usr/sbin/nfs_config /opt/sbin/nfs_config

Ola… my bad. The symlink source/target were swapped. See above.

Take care to use the correct paths when pointing to the original nfs_config!
You are using nfs_config.ori, use the same command to create OS3 based exports in /opt/sbin/nfs_config

no worries, I’m used to backup original files with .ori extension that’s why I’ve changed it in /shares/Volume_1/Nas_Prog/entware/init.sh AND in the new /shares/Volume_1/entware/sbin/nfs_config :slight_smile:

I couldn’t see the point of doing such a link but now it seems clear :slight_smile:
I got a link in /shares/Volume_1/entware/sbin/nfs_config pointing on /usr/sbin/nfs_config do i have to delete it ? i 've renamed it as /shares/Volume_1/entware/sbin/nfs_config.ori just to be sure.

Here is a summary :

  1. edit entware to execute our script at start:

    vi /shares/Volume_1/Nas_Prog/entware/init.sh
    

and add following :

mv /usr/sbin/nfs_config /usr/sbin/nfs_config.ori
ln -sf /opt/sbin/nfs_config /usr/sbin/nfs_config 
  1. (optional) backup already existing /shares/Volume_1/entware/sbin/nfs_config

    mv /shares/Volume_1/entware/sbin/nfs_config /shares/Volume_1/entware/sbin/nfs_config.ori
    
  2. create our new one :

    vi /shares/Volume_1/entware/sbin/nfs_config
    

paste the following :

#!/bin/sh

# create OS3 based exports
/usr/sbin/nfs_config.ori

# append custom exports
cat <<EOF > /etc/exports
"/nfs/Films"  192.168.0.100(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)       192.168.0.14(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)       192.168.0.15(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)       192.168.0.21(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)
"/nfs/Series" 192.168.0.100(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)       192.168.0.14(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)       192.168.0.15(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)       192.168.0.21(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)
"/nfs/Music"  192.168.0.100(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)       192.168.0.14(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)       192.168.0.15(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)       192.168.0.21(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)
"/nfs/Photo"  192.168.0.100(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)       192.168.0.14(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)       192.168.0.15(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)       192.168.0.21(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)
"/nfs/Public" *(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)
EOF

(Pay attention to the single > in line cat <<EOF > /etc/exports as otherwise, previous NFS configured UI settings gets written in it)

save it with :wq

  1. make it executable

    chmod +x /shares/Volume_1/entware/sbin/nfs_config
    
  2. reboot

  3. I don’t know why, but entware didn’t get initialized at boot so I had to run :

    cd /shares/Volume_1/Nas_Prog/entware
    ./init.sh $(pwd)
    ls /opt
    

it should now contains some directories.

  1. test with

    cat /etc/exports
    

It now should be as described in /shares/Volume_1/entware/sbin/nfs_config !

Thank you very much for your help Tfl !

1 Like