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
Manual edit of autorun.sh
- Log into your QNAP device using SSH or Telnet, for instance by using Putty
- Optional: install nano; use ipkg install nano & edit with nano instead of vi
- 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 - Create/Edit /tmp/config/autorun.sh .
- either using vi:
# vi /tmp/config/autorun.sh
- either using vi:
- Get vi editor into edit mode: press a
- Edit whatever you need to
- Exit edit mode: press ESC
- Save and exit: press ZZ
- or editing it using a desktop PC and e.g. SFTP
- Ensure that /tmp/config/autorun.sh is executable:
# chmod +x /tmp/config/autorun.sh
- IMPORTANT: Unmount the mounted flash partition:
# umount /tmp/config
editautorun.sh: script to ease autorun.sh edit
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
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
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
mkdir /share/HDA_DATA/.qpkg/autorun cd /share/HDA_DATA/.qpkg/autorun/ touch autorun.sh chmod +x autorun.sh
#!/bin/sh /share/HDA_DATA/.qpkg/autorun/autorun.sh &
IMPORTANT Notes!
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:
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
/opt/bin/rsyncd-acl.sh start
#!/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
mkdir -p /opt/var/log
#!/bin/sh /opt/bin/rsyncd-acl.sh start
QPKG-based method
- 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
- 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
- Set the execute bit:
# chmod +x /share/MD0_DATA/.qpkg/autorun/autorun.sh
- Reboot and enjoy!
MTD-based method (old)
QPKG-based method (new)
Trick & tips
Waiting for encrypted partitions
#! /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
(./waitforenc.sh; /etc/init.d/ldap_server.sh restart ) &
Calling all scripts in a certain directory
#! /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
- You can also try different values from http://www.speedguide.net/read_articles.php?id=121" alt="http://www.speedguide.net/read_articles.php?id=121" title="http://www.speedguide.net/read_articles.php?id=121">http://www.speedguide.net/read_articles.php?id=121
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