顯示具有 QNAP 標籤的文章。 顯示所有文章
顯示具有 QNAP 標籤的文章。 顯示所有文章

2016年2月23日 星期二

QNAP開機自動執行的方法

Skills required

  • must be able to remote login via ssh or telnet (e.g. use SSH PuTTY)
  • must know how to edit files using nano, vi, or edit via SFTP (e.g. use WinSCP)

MTD-based method

autorun.sh is a script which will be executed on every startup of the TS-x09, TS-x19 and TS-x39. Editing this file allows you to start your own programs or overwrite config files with your own copies.

Manual edit of autorun.sh

  1. Log into your QNAP device using SSH or Telnet, for instance by using Putty
  2. Optional: install nano; use ipkg install nano & edit with nano instead of vi
  3. Mount config ramblock by finding your specific model below:

    TS-201: 
    Mount the config ramblock /dev/mtdblock4:
    # mount -t ext2 /dev/mtdblock4 /tmp/config

    1 bay: TS-109, TS-109P, TS-110, TS-119,
    2 bay: TS-209, TS-209P, TS-212, TS-219 (TS-219P II: since the new firmware update you maybe have to use ext4 instead of ext2), 
    4 bay: TS-409 (Marvell ARM), TS-412, TS-419P:
    Mount the config ramblock /dev/mtdblock5:
    # mount -t ext2 /dev/mtdblock5 /tmp/config

    TS-439, TS-509, TS-639, TS-809, TS-809U (x86): 
    Mount the config ramblock /dev/sdx6:
    # mount -t ext2 /dev/sdx6 /tmp/config

    TS-269L: 
    Mount the config ramblock /dev/sdc6:
    # mount -t ext2 /dev/sdc6 /tmp/config
  4. Create/Edit /tmp/config/autorun.sh .
    1. either using vi:
      # vi /tmp/config/autorun.sh
  1. Get vi editor into edit mode: press a
  2. Edit whatever you need to
  3. Exit edit mode: press ESC
      1. Save and exit: press ZZ
    1. or editing it using a desktop PC and e.g. SFTP
  4. Ensure that /tmp/config/autorun.sh is executable:
    # chmod +x /tmp/config/autorun.sh
  1. IMPORTANT: Unmount the mounted flash partition:
    # umount /tmp/config

editautorun.sh: script to ease autorun.sh edit

If you edit this file regularly you can save some time by creating a shell script (e.g. editautorun.sh) to automate the process. You can call the script by either putting it in the environment path, or add its folder to the path or call it by an alias.
The script contents are:
For TS-201 use ...
mount -t ext2 /dev/mtdblock4 /tmp/config
vi /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
echo .
echo "unmounting /tmp/config..."
umount /tmp/config
For TS-109, TS-109P, TS-119, TS-209, TS-209P, TS-219, TS-412, TS-409 (Marvell ARM) use ...
mount -t ext2 /dev/mtdblock5 /tmp/config
vi /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
echo .
echo "unmounting /tmp/config..."
umount /tmp/config
TS-439, TS-509, TS-639, TS-809, TS-809U (x86) use ...
mount -t ext2 /dev/sdx6 /tmp/config
vi /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
echo .
echo "unmounting /tmp/config..."
umount /tmp/config

autorun.sh: one script to rule them all

Frequently mounting and editing autorun.sh on the flash could be an annoying task. More important, it may reduce the lifetime of some flash blocks. Flash blocks have limited write/erase cycles, and the mtdblock device driver does little to prevent their wear. Read more on this on the http://www.linux-mtd.infradead.org/faq/general.html#L_ext2_mtd" alt="http://www.linux-mtd.infradead.org/faq/general.html#L_ext2_mtd" title="http://www.linux-mtd.infradead.org/faq/general.html#L_ext2_mtd">Linux mtd
web site.
To avoid this, you could configure autorun.sh to launch another script located in the inner drive: in this way there no need to always mount and modify the file inside the flash. but only edit the script file located on your drive.
Create the directory /share/HDA_DATA/.qpkg/autorun and file autorun.sh with:
mkdir /share/HDA_DATA/.qpkg/autorun
cd /share/HDA_DATA/.qpkg/autorun/
touch autorun.sh
chmod +x autorun.sh
The autorun.sh located on the flash could be something like this (just two lines that won't need many changes!):
#!/bin/sh
/share/HDA_DATA/.qpkg/autorun/autorun.sh &
and then edit the file /share/HDA_DATA/.qpkg/autorun/autorun.sh to be used to launch all your startup scripts.

IMPORTANT Notes!

1. Never put any larger files on your flashboot devices and ramdisk; instead, create symbolic links to whatever you want to put there, e.g.:
Create a link from /usr (which is in ramdisk) to /share/MD0_DATA/jre1.6.0_10 (which is on a hard disk) at the mountpoint /usr/java
# ln -sf /share/MD0_DATA/jre1.6.0_10 /usr/java

2. Always use the full system path because locations like /opt/bin or /opt/sbin might not have been exported yet when Autorun.sh is executed, e.g:
No good.
svnserve -d --listen-port=4000 -r /share/subversion

This is better.
/opt/bin/svnserve -d --listen-port=4000 -r /share/subversion


If it still fails to start svnserve, you might try adding this line to your autoexec script:
/bin/ln -sf /opt/bin/ /share/HDA_DATA/opt/bin/

3. Many startup scripts in /etc/init.d overwrite their corresponding configuration files in /etc. In this case overwriting the config file using autorun.sh is not enough; we also have to overwrite the startup script itself. Moreover, many startup scripts get excecuted before autorun, such that we also have to restart the service. In this case an autorun.sh may look like this:
#!/bin/sh

cp /share/MD0_DATA/admin/nfs /etc/init.d/nfs
cp /share/MD0_DATA/admin/exports /etc

/etc/init.d/nfs restart
Very ugly, indeed! However, it seems this is the only way to make it work (unless you want to throw out the QNAP OS and install a 'better' OS on your NAS).
4. On our QNAP TS-879 Pro we were not able to run
/opt/bin/rsyncd-acl.sh start
from the autorun.sh as /opt is not the one from Optware but a directory containing one file, i.e. nasconfig_fs.img.tgz.
Thus we modified /tmp/config/autorun.sh to
#!/bin/sh
log=/share/MD0_DATA/.qpkg/Optware/var/log/autorun
date > $log
# removing bogus /opt
/bin/rm /opt/nasconfig_fs.img.tgz /opt 2>> $log >> $log
/bin/rmdir /opt 2>> $log >> $log
# link correct /opt
/bin/ln -s /share/MD0_DATA/.qpkg/Optware /opt 2>> $log >> $log
# run autorun.sh
/opt/etc/autorun.sh 2>> $log >> $log
created a log file directory
mkdir -p /opt/var/log
and created /opt/etc/autorun.sh on the disk
#!/bin/sh
/opt/bin/rsyncd-acl.sh start
thus no mounting of the flash partition is necessary anymore.

QPKG-based method

With firmware 3.8.2, the #MTD-based_method was broken. With the next firmware update, this bug was corrected, but in the meanwhile, the below workaround has been devised.
This method consists of declaring a dummy QPKG which launches your script at startup.
  • Log into your QNAP device using SSH or Telnet, for instance by using Putty
  • Edit QPKG config file:
# vi /etc/config/qpkg.conf
  • Declare a new dummy package by adding something like that in this file, but take care about the order. e.g. if you would like to start a service from a optware package, be sure optware is initialized before:
[autorun]
Name = autorun
Version = 0.1
Author = neomilium
Date = 2013-05-06
Shell = /share/MD0_DATA/.qpkg/autorun/autorun.sh
Install_Path = /share/MD0_DATA/.qpkg/autorun
Enable = TRUE
As you can see, Shell is the interesting variable: at boot-time, QNAP OS will launch each QPKG's Shell variable content.
Note: if your NAS doesn't have /share/MD0_DATA (i.e. is a one-drive NAS then substitute /share/MD0_DATA by /share/HDA_DATA , on a NAS with the new Storage Manager substitute /share/MD0_DATA by /share/CACHEDEV1_DATA/), put the right directory into the Shell and Install_Pathvariables and adapt the following commands to your needs.
  • Create the dummy package directory:
# mkdir /share/MD0_DATA/.qpkg/autorun
  • Create the autorun script with the contents of your choice:
# vi /share/MD0_DATA/.qpkg/autorun/autorun.sh
Note: don't forget "#!/bin/sh" at the beginning of script.
  • Set the execute bit:
# chmod +x /share/MD0_DATA/.qpkg/autorun/autorun.sh
  • Reboot and enjoy!

MTD-based method (old)

This section is here only to make sure existing anchor links continue to work. The meat is in the section MTD-based method.

QPKG-based method (new)

This section is here only to make sure existing anchor links continue to work. The meat is in the section QPKG-based method

Trick & tips

Waiting for encrypted partitions

If your data partition is encrypted, you might have some script that has to wait until the encrypted partition is available. I added a script called waitforenc.sh in my autorun-directory:
#! /bin/sh

# This script ends after the encrypted filesystem has been mounted.

# The following exits successfully (0) if MD0 is mounted
cat /etc/mtab | grep -q MD0
while [[ $? -ne 0 ]] ; do
        sleep 5
        cat /etc/mtab | grep -q MD0
done
And now I'm able to call scripts *after* the encrypted partition is available, without blocking other scripts:
(./waitforenc.sh; /etc/init.d/ldap_server.sh restart ) &

Calling all scripts in a certain directory

Place a file called listoffiles.sh in a directory, create a subdirectory called scripts, add listoffiles.sh to your autorun:
#! /bin/sh
# listoffiles.sh

BASEDIR=$(dirname $0)

echo "" > log/userfiles.log

for i in scripts/*.sh ; do
        if [[ -x $i ]] ; then
                echo -n "$i " >> log/userfiles.log
                echo `date` >> log/userfiles.log
                $i 2>&1 >> log/userfiles.log
                cd $BASEDIR
        fi
done

Optimized networking

">SpeedGuide.net
ifconfig eth0 txqueuelen 50000
ifconfig eth1 txqueuelen 50000
echo 1 > /proc/sys/net/ipv4/tcp_rfc1337
echo 2 > /proc/sys/net/ipv4/tcp_frto
echo 2 > /proc/sys/net/ipv4/tcp_frto_response
echo 1 > /proc/sys/net/ipv4/tcp_mtu_probing
echo 1 > /proc/sys/net/ipv4/tcp_window_scaling
echo 1 > /proc/sys/net/ipv4/tcp_workaround_signed_windows
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
echo 0 > /proc/sys/net/ipv4/tcp_tw_recycle
echo 1 > /proc/sys/net/ipv4/tcp_low_latency
echo 1 > /proc/sys/net/ipv4/tcp_ecn

QNAP mount samb分享的目錄

mount.cifs //192.168.12.34/sharename /share/Public/WindowsShare -o username=user,password=pass

2016年2月20日 星期六

兩個NAS掛載其中一台分享出來的資料夾成為本地硬碟!

Steps to do:
On the ARM based QNAP, create the share in common, and grant rights to the NFS Intel based QNAP
On the Intel baed QNAP, create a directory like: / share / MD0_DATA / remotenas
Then type the Following:
mount -t nfs : /   / share / MD0_DATA / remotenas

2012年2月1日 星期三

qnap與一般linux主機間要ssh金鑰登入,不用密碼的方法!

早在qnap韌體不知在第幾版前,依照一般的操作方式(如這篇文章所提的方法:兩台linux主機以ssh自動登入,不無打入密碼的方法!),要登入都是可以的,但不知在那個版本之後,突然問就會出問題,原因在路徑出了問題。

ssh-keygen -t rsa

上述指令打完後,其內定的路徑是/share/homes/admin/.ssh,然而系統會告知你無法建立此資料夾,原因是系統除了/share這個資料夾外,其間的homes與admin兩個子資料夾均沒有,所以當然無法建立.ssh這個資料夾了,而當然我們只好自己建立。

建立好後總算可以:利執行完ssh-keygen -t rsa指令!

在/share/homes/admin/.ssh產生的id_rsa,和id_rsa.pub這兩個檔案,其中依據兩台linux主機以ssh自動登入,不無打入密碼的方法!的說法是把qnap生成的id_rsa.pub拷貝到B機上,假設拷貝到B機的臨時目錄下,如:

scp /share/homes/admin/.ssh/id_rsa.pub root@B機ip:/tmp

然後再用root帳號登陸B機,進入其主目錄,創建authorized_keys檔,並設置好許可權。

cd ~/.ssh
cat /tmp/id_rsa.pub >>authorized_keys
chmod 400 authorized_keys
rm -f /tmp/id_rsa.pub

當你設定好之後回到qnap,重新以root身份試著登入B機,會發現無法登入!

其原因是Qnap主機透過ssh-keygen -t rsa指令產生的id_rsa,和id_rsa.pub,這兩個鑰匙並沒有在正確的位置,一般系統在核對金鑰時其內定的路徑是/root/.ssh裡,所以你必須再將你原先放在/share/homes/admin/.ssh裡的兩個檔案拷備過來,這樣才能完成金鑰登入B機的方法!

2011年3月12日 星期六

Qnap NAS ssh登入,僅能以金鑰登入而不能以密碼登入的設定法

找到 /etc/ssh/sshd_config

vim /etc/ssh/sshd_config

找到  #PasswordAuthentication yes

#刪掉,並將yes改為no,重新啟動ssh服務。當然前提是要對你用以登入該NAS的client端之電腦產生連線登入金鑰,並上傳到NAS主機裡。

其做法有兩種,請分別看以下之文章:

若你的client端為linux系統請看這篇:兩台linux主機以ssh自動登入,不無打入密碼的方法!

若你的client端為windows系統請看這篇:使用public/private key讓putty(ssh)自動登錄(以及linux上使用金鑰做ssh自動登陸)

2010年12月23日 星期四

qnap httpd的設定檔及透過ssh重啟httpd的指令及其路徑

/usr/local/apache/conf/apache.conf
/etc/init.d/Qthttpd.sh restart
曾加一個ssh重啟指令
/etc/init.d/login.sh restart

2010年3月5日 星期五

QNAP設定為強制ssl登入後,無法登入的解決方法!

QNAP,何改為強制ssl登入後,就無法登入成功?就我的認知,我已將所有的防火牆都打開了,卻仍然無法登入,打入帳號密碼之後,一直跳在登入畫面前。問題出在什麼地方?會是系統的bug嗎?還是要開啟這個功能時,必須有什麼搭配條件?底下是一段有無改為強制ssl登入畫面的差異!
解決的方法:用其它的BROWSER 如firefox

2010年2月23日 星期二

在網頁管理介面下,選了強制ssl登入之後,就無法登入了。 想從ssh進去更改設定檔,但不知哪一個設定檔是在更改該設值的,以及如何更改?能否說明一下,

ssh admin帳號登入後,找到/etc/config/uLinux.conf這個設定檔裏的Force SSL =1,將1 改成0 就會變成非強制SSL 登入

Remote tool/Teamviewer , http://wiki.qnap.com/wiki/TeamViewer_setup_for_remote_desktop_connection

Download Teamviewer QS version HERE

Disclaimer:
Our advice is strictly limited to the question(s) asked and is based on the information provided to us. QNAP Systems Inc. does not assume any responsibility or liability for the advice given and shall not be liable for any direct, indirect, special, incidental or consequential damages in connection with the use of this information. Always back up your data. For more information, including technical information updates, please visit our website at http://www.qnap.com/

2009年7月30日 星期四

QNAP 的 cron 排程檔位置與重新啟動指令語法

排程檔位置
/mnt/HDA_ROOT/.config/crontab
/etc/config/crontab
編輯它,然後執行
crontab /etc/config/crontab
重新啟動指令語法
/etc/init.d/crond.sh restart
目前試了上面的做法可以!
下面的做法重啟後,還是會回復到原來的設定!看來關鍵在/etc/config/crontab
總算找到好的改更crontab檔的方法了,那就是先將內容以vim這支程式寫完後,存成任意檔名,例如:newcrontab,然後輸入如下指令:
#crontab newcrontab
這樣就會直接更改系統內定的crontab內容,而不用再以crontab -e指令進入後一個一個改!