nfs automount at system startup

Discussion about using NAS on Linux and Unix OS.
mw_orion
New here
Posts: 9
Joined: Tue Sep 11, 2012 8:18 pm

Re: nfs automount at system startup

Post by mw_orion » Fri May 01, 2015 6:21 pm

Hi,

I watched the forum for some time, the first post from my side. I tried to implement the proposed method for autostart. I got it set up (link for /etc/config/autostart.sh is there and executable).

The problem so far: not autostart of the script. Some logs after a reboot:

Code: Select all

-rw-r--r--    1 admin    administ         0 May  1 12:03 autorun.ran

manually mounted /tmp/config to look, if there is everything:

Code: Select all

-rw-r--r--    1 admin    administ        21 Apr  9 17:11 .sys_update_time
-rwxr-xr-x    1 admin    administ       196 May  1 11:57 autorun.sh*
-rwxr-xr-x    1 admin    administ         0 Apr 18 19:22 autorun.sh.OLD*
drwx------    2 admin    administ     12288 Jan 11  2010 lost+found/
-rw-r--r--    1 admin    administ      8076 Apr 19 18:39 smb.conf

Content of autostart.sh there:

Code: Select all

#!/bin/sh
# AUTORUN.SH - "Boot strap"
# This script forces the NAS to run "/etc/config/autorun.sh" at every startup (if this file exists).
#
/etc/config/autorun.sh
touch /tmp/autorun.ran
# done

content of /etc/config (extract):

Code: Select all

-rwxr-xr-x    1 admin    administ       237 Apr 19 19:54 autorun.sh*

content of that autorun.sh:

Code: Select all

#!/bin/sh
#
# /etc/config/autorun.sh - These commands run at every NAS Startup
#
/opt/etc/init.d/S56dnsmasq start
# mount -t nfs -o rw,intr 192.168.1.106:/volume/share /share/backup 1>> /tmp/remoteNFS.log &2>> /tmp/remoteNFS.log
# done

What definitely did't work to start dnsmasq. If I start autostart.sh manually is works fine.

Any help appreciated !

Sorry I missed the type: It's an Qnap 470 Pro Model

Michael

User avatar
forkless
Experience counts
Posts: 1914
Joined: Mon Nov 23, 2009 6:52 am
Location: The Netherlands

Re: nfs automount at system startup

Post by forkless » Fri May 01, 2015 8:34 pm

When you are running an autorun script it will be executed before the QPKG init script is started, in other words /opt is simply not symlinked at that point then.

I suggest reading http://wiki.qnap.com/wiki/Install_Optwa ... on_startup

User avatar
pwilson
Guru
Posts: 22568
Joined: Fri Mar 06, 2009 11:20 am
Location: Victoria, BC, Canada (UTC-08:00)

Re: nfs automount at system startup

Post by pwilson » Fri May 01, 2015 11:14 pm

mw_orion wrote:

Code: Select all

#!/bin/sh
# AUTORUN.SH - "Boot strap"
# This script forces the NAS to run "/etc/config/autorun.sh" at every startup (if this file exists).
#
/etc/config/autorun.sh
touch /tmp/autorun.ran
# done

content of /etc/config (extract):

Code: Select all

-rwxr-xr-x    1 admin    administ       237 Apr 19 19:54 autorun.sh*

content of that autorun.sh:

Code: Select all

#!/bin/sh
#
# /etc/config/autorun.sh - These commands run at every NAS Startup
#
/opt/etc/init.d/S56dnsmasq start
# mount -t nfs -o rw,intr 192.168.1.106:/volume/share /share/backup 1>> /tmp/remoteNFS.log &2>> /tmp/remoteNFS.log
# done

What definitely did't work to start dnsmasq. If I start autostart.sh manually is works fine.

Any help appreciated !



forkless wrote:When you are running an autorun script it will be executed before the QPKG init script is started, in other words /opt is simply not symlinked at that point then.

I suggest reading http://wiki.qnap.com/wiki/Install_Optware_IPKG#Running_.2Fopt.2Fetc.2Finit.d.2F.2A_on_startup


Try this instead:

Code: Select all

#!/bin/sh
#
# /etc/config/autorun.sh - These commands run at every NAS Startup
#
/share/CACHEDEV1_DATA/.qpkg/Optware/etc/init.d/S56dnsmasq start
# /bin/mount -t nfs -o rw,intr 192.168.1.106:/volume/share /share/backup 1>> /tmp/remoteNFS.log &2>> /tmp/remoteNFS.log
# done


Or even better, implement Optware properly, and follow the steps in the Running /opt/etc/init.d/* on startup section of QNAPedia article: Install Optware IPKG, so that all the Optware init scripts placed in /share/CACHEDEV1_DATA/.qpkg/Optware/etc/init.d/ all run automatically at every boot up.

You will still want to use your "autorun.sh" file to do your NFS auto-mount (that is presently commented out), but you should implement the Optware init.d subsystem properly, rather than manually running one of them via the system-wide "autorun.sh" mechanism.

Patrick.

PS: Please update your Forum profile, to reflect a NAS model of "TS-x70" (like me). It currently lists a "TS-239 Pro" which requires completely different instructions for the location of the system "autorun.sh" file.

PPS: Your system wide "autorun.sh" code looks suspiciously like mine. I bet I wrote it. Thanks for the credit. :roll:

Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs

Please review: When you're asking a question, please include the following.

mw_orion
New here
Posts: 9
Joined: Tue Sep 11, 2012 8:18 pm

Re: nfs automount at system startup

Post by mw_orion » Sun May 03, 2015 1:09 am

Yes, indeed, I used your proposal. There is a package in the Qnap App store out there, named autorun v0.1. Does anybody know, if thats the simple install for a systemwide autostart without doing all the steps of the name thread / wiki ?

THanks,
Michael

User avatar
pwilson
Guru
Posts: 22568
Joined: Fri Mar 06, 2009 11:20 am
Location: Victoria, BC, Canada (UTC-08:00)

Re: nfs automount at system startup

Post by pwilson » Sun May 03, 2015 1:43 am

mw_orion wrote:Yes, indeed, I used your proposal. There is a package in the Qnap App store out there, named autorun v0.1. Does anybody know, if thats the simple install for a systemwide autostart without doing all the steps of the name thread / wiki ?

THanks,
Michael


I'm the wrong person to ask. I use the Wiki MTD-method, and I probably always will. I dislike the nasty QPKG kluge, and I will never recommend it to anyone.

I fail to see why the "autorun.sh" system is difficult. On your TS-470 Pro (like mine), it is as simply as:

Code: Select all

mount -t ext2 $(/sbin/hal_app --get_boot_pd port_id=0)6 /tmp/config
$EDITOR /tmp/config/autorun.sh
umount /tmp/config
#done


You have already accomplished this. You don't need anything else to create the system wide "autorun.sh".

This however still skirts the original question I asked you: Why aren't you using the Optware init.d subsystem to start DNSmasq?

You are already doing your "autorun.sh" properly. My only issue with your setup, is that you are attempting to run an Optware init.d script, but are attempting to do so via the "autorun.sh" script, rather than implementing the Optware init.d subsystem that would run it automatically without any "autorun.sh" file at all.

If you no longer need to do that NFS mount at startup, you really don't need an "autorun.sh" file at all. BTW, I use DNSmasq for my DNS+DHCP Server here too, the major difference is that I do so on my Router, rather than on my NAS. Unfortunately this entire message thread is now off topic. Your original topic was about doing a NFS Automount, yet this has really never been discussed in this thread, partially due to the fact that your own script has this "commented out" so that it doesn't occur at all.

For DNSMasq, simply setup Optware properly, as already explained multiple times within this thread.

Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs

Please review: When you're asking a question, please include the following.

mw_orion
New here
Posts: 9
Joined: Tue Sep 11, 2012 8:18 pm

Re: nfs automount at system startup

Post by mw_orion » Mon May 04, 2015 4:51 am

Many thanks for the reply and help. I will try to setup optware correctly. If there is any question left, i will put it to the appropriate thread in the forum.

Michael

User avatar
pwilson
Guru
Posts: 22568
Joined: Fri Mar 06, 2009 11:20 am
Location: Victoria, BC, Canada (UTC-08:00)

Re: nfs automount at system startup

Post by pwilson » Mon May 04, 2015 5:12 am

mw_orion wrote:Many thanks for the reply and help. I will try to setup optware correctly. If there is any question left, i will put it to the appropriate thread in the forum.

Michael


If you add the code:

Code: Select all

  # Patch per http://wiki.qnap.com/wiki/Install_Optware_IPKG
  /bin/echo "Run Optware/ipkg /opt/etc/init.d/*"
     source /etc/profile
        # Start all init scripts in /opt/etc/init.d
   # executing them in numerical order.
   #
   for i in /opt/etc/init.d/S??* do
       # Ignore dangling symlinks (if any).
           #[ ! -f "$i" ] && continue

            case "$i" in
                *.sh)
               # Source shell script for speed.
               (
              trap - INT QUIT TSTP
         set start
              . $i
              )
           ;;
           *)
              # No sh extension, so fork subprocess.
              $i start
                ;;         
            esac           
        done               
# End patch


to your /etc/init.d/Optware.sh init script, it will autorun all your Optware init.d scripts for you automatically, including your DNSmasq startup script. :DD

It it is related to any of the advice posted in this message thread, please put your further comments/questions back in this thread. (I'll be happy to continue helping with this issue for you).

Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs

Please review: When you're asking a question, please include the following.

mw_orion
New here
Posts: 9
Joined: Tue Sep 11, 2012 8:18 pm

Re: nfs automount at system startup

Post by mw_orion » Wed May 06, 2015 4:36 am

Hello,
I put the mount of an SSD at /dev/sda1 to your autorun.sh mounted in /tmp/config. Works fine. No Problem.
I added the optware ipkg as described, but still i have an error, because dnsmasq won't start.
Theis I have to analyse.

Thanks so far.

User avatar
pwilson
Guru
Posts: 22568
Joined: Fri Mar 06, 2009 11:20 am
Location: Victoria, BC, Canada (UTC-08:00)

Re: nfs automount at system startup

Post by pwilson » Wed May 06, 2015 4:47 am

mw_orion wrote:Hello,
I put the mount of an SSD at /dev/sda1 to your autorun.sh mounted in /tmp/config. Works fine. No Problem.
I added the optware ipkg as described, but still i have an error, because dnsmasq won't start.
Theis I have to analyse.

Thanks so far.


Please cut&paste a contents of your /etc/init.d/Optware.sh file to this message thread, so that I can see it. Simply put it inside "code" tags, so that it is scrollable, like my examples previously provided in this message thread.

Does "DNSmasq" work if you manually run /opt/etc/init.d/S56dnsmasq from the command line with:

Code: Select all

/opt/etc/init.d/S56dnsmasq start


At this point we don't know if this is a DNSmasq configuration issue, or a Optware init.d run issue. Lets see your modified Optware script.

Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs

Please review: When you're asking a question, please include the following.

mw_orion
New here
Posts: 9
Joined: Tue Sep 11, 2012 8:18 pm

Re: nfs automount at system startup

Post by mw_orion » Thu May 07, 2015 2:21 am

Hello,

the Script starts dnsmasq with any problem. That's the way i'm doing it after a restart of the NAS.
Attached the Optware.sh with marked the point, where I tried to integrate the additional code.
Compared to the Script of the wiki, there is additional code in, but my though was, that it could fit at that location still.

Code: Select all

#!/bin/sh

RETVAL=0
QPKG_NAME="Optware"

_exit()
{
    /bin/echo -e "Error: $*"
    /bin/echo
    exit 1
}

# Determine BASE installation location according to smb.conf
BASE=
publicdir=`/sbin/getcfg Public path -f /etc/config/smb.conf`
if [ ! -z $publicdir ] && [ -d $publicdir ];then
        publicdirp1=`/bin/echo $publicdir | /bin/cut -d "/" -f 2`
        publicdirp2=`/bin/echo $publicdir | /bin/cut -d "/" -f 3`
        publicdirp3=`/bin/echo $publicdir | /bin/cut -d "/" -f 4`
        if [ ! -z $publicdirp1 ] && [ ! -z $publicdirp2 ] && [ ! -z $publicdirp3 ]; then
                [ -d "/${publicdirp1}/${publicdirp2}/Public" ] && BASE="/${publicdirp1}/${publicdirp2}"
        fi
fi

# Determine BASE installation location by checking where the Public folder is.
if [ -z $BASE ]; then
        for datadirtest in /share/HDA_DATA /share/HDB_DATA /share/HDC_DATA /share/HDD_DATA /share/MD0_DATA; do
                [ -d $datadirtest/Public ] && BASE="$datadirtest"
        done
fi
if [ -z $BASE ] ; then
        echo "The Public share not found."
        _exit 1
fi
QPKG_DIR=${BASE}/.qpkg/Optware

case "$1" in
  start)
  if [ `/sbin/getcfg ${QPKG_NAME} Enable -u -d FALSE -f /etc/config/qpkg.conf` = UNKNOWN ]; then
        /sbin/setcfg ${QPKG_NAME} Enable TRUE -f /etc/config/qpkg.conf
  elif [ `/sbin/getcfg ${QPKG_NAME} Enable -u -d FALSE -f /etc/config/qpkg.conf` != TRUE ]; then
        _exit  "${QPKG_NAME} is disabled."
  fi

  /bin/echo "Enable Optware/ipkg"
        # sym-link $QPKG_DIR to /opt
        /bin/rm -rf /opt
        /bin/ln -sf $QPKG_DIR /opt
        # determine the architecture
        arch=$(/bin/uname -m)
        #if not x09 then
        if [ "$arch" != "armv5tejl" ]; then
          #sym-link the html dir
          /bin/ln -sf $QPKG_DIR/html /home/httpd/
          #sym-link the management website to /(Q)Web
          [ -d /share/Web ] && WebDir="/share/Web"
          [ -d /share/Qweb ] && WebDir="/share/Qweb"
          [ -d $WebDir/Optware ] || /bin/ln -sf /home/httpd/html/Management $WebDir/Optware
        fi
        # adding Ipkg apps into system path ...
        /bin/cat /etc/profile | /bin/grep "PATH" | /bin/grep "/opt/bin" 1>>/dev/null 2>>/dev/null
        [ $? -ne 0 ] && /bin/echo "export PATH=\$PATH":/opt/bin:/opt/sbin >> /etc/profile
#
# at this point I added the autostart part
#
  # Patch per http://wiki.qnap.com/wiki/Install_Optware_IPKG
  /bin/echo "Run Optware/ipkg /opt/etc/init.d/*"
     source /etc/profile
        # Start all init scripts in /opt/etc/init.d
   # executing them in numerical order.
   #
   for i in /opt/etc/init.d/S??* do
       # Ignore dangling symlinks (if any).
           #[ ! -f "$i" ] && continue

            case "$i" in
                *.sh)
               # Source shell script for speed.
               (
              trap - INT QUIT TSTP
         set start
              . $i
              )
           ;;
           *)
              # No sh extension, so fork subprocess.
              $i start
                ;;         
            esac           
        done               
# End patch


        # determine the right feed based on cpu type
        case "$(/bin/uname -m)" in
        armv5tejl)
          #X09 architecture
          kmod_feed="http://ipkg.nslu2-linux.org/feeds/optware/tsx09/cross/unstable"
          modelrange="tsx09"
        ;;
        armv5tel)
          #X19 architecture
          kmod_feed="http://ipkg.nslu2-linux.org/feeds/optware/tsx19/cross/unstable"
          modelrange="tsx19"
        ;;
        x86_64)
          #x86 architecture
          kmod_feed=""
          modelrange="ts509"
        ;;
        i686)
          #x86 architecture
          kmod_feed=""
          modelrange="ts509"
        ;;
        *)
         #everyting else
         _exit "Unknown CPU architecture, quitting Optware start"
       ;;
       esac

       [ -z $kmod_feed ] || /bin/echo "src $modelrange $kmod_feed" > /opt/etc/ipkg/$modelrange-kmod.conf
       [ -z $kmod_feed ] || /usr/bin/wget -q $kmod_feed/Packages --spider || /bin/rm -rf /opt/etc/ipkg/$modelrange-kmod.conf

       ;;
  stop)
        /bin/echo "Disable Optware/ipkg"
        export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

        [ -d /share/Web ] && WebDir="/share/Web"
        [ -d /share/Qweb ] && WebDir="/share/Qweb"
        /bin/rm -f $WebDir/Optware

        /bin/sync
        /bin/sleep 1
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac

exit $RETVAL


Thanks in advance, I'm not so familiar in programming scripts !

Edit: There is a nice thread : viewtopic.php?f=85&t=18977 explaining the boot sequence. When I reviewed it I didn't find the optware.qpkg in the conf file under /etc/config/qpkg.conf, but still had the ipkg apps installed and active. I had to deactivate and activate ipkg again to regain the entry in the config file. If this entry is missing as I understood, there will by no run script linked to /etc/rcS.d. And if so, no IPKG will be automatically launched. Let's see if that works better.

Edit2: Solved ! Works fine !

dgladstone
First post
Posts: 1
Joined: Tue Jul 04, 2017 1:21 pm

Re: nfs automount at system startup

Post by dgladstone » Sat Aug 12, 2017 11:44 am

Adding to a very old post, I know. I was struggling getting autorun.sh to work and found that from QNAP 4.3.3 build 20170727 you must enable the option in Control Panel > Hardware > Run user defined processes at startup. I think this was added as a result of some malware that was abusing the autorun.sh so it seems to be disabled by default now.

Hope this helps someone.

myg4ever
New here
Posts: 4
Joined: Sun Feb 08, 2015 11:36 pm

Re: nfs automount at system startup

Post by myg4ever » Wed Mar 28, 2018 6:00 pm

Can I use the same way for the external hard disk to be mounted to specific ID to let Plex Media Server always use this path every time I reboot my TS-453 Pro ?

jamesking
New here
Posts: 9
Joined: Sun Oct 09, 2016 3:50 pm

Re: nfs automount at system startup

Post by jamesking » Sun Apr 07, 2019 3:47 pm

dgladstone wrote:
Sat Aug 12, 2017 11:44 am
Adding to a very old post, I know. I was struggling getting autorun.sh to work and found that from QNAP 4.3.3 build 20170727 you must enable the option in Control Panel > Hardware > Run user defined processes at startup. I think this was added as a result of some malware that was abusing the autorun.sh so it seems to be disabled by default now.

Hope this helps someone.
Just did my first reboot and my edited autorun.sh didn't work - read to the end of the thread and saw your post. Very helpful, thank you. I am now rebooting again. Fingers crossed!

Post Reply

Return to “Linux & Unix (NFS)”