Archive

Archive for the ‘QNAP’ Category

QNAP: How to add a static route or add commands that should be executed during startup/reboot

Problem description:

You need to add an additional static route to your QNAP storage system. “route add” works fine through ssh, but does not persist a reboot.

 
Problem resolution:

Unfortunately the configuration of routes is not possible via the web interface. You will have to connect via ssh and edit a script that will be executed on every startup.

Just follow the next steps:

  1. Connect via ssh

    mbp:~ matt $ ssh admin@qnap15
    admin@qnap15's password: 
    [~] #

     

  2. Mount of the QNAP-Configuration device

    The name of the actual device to mount depends on your model number. In general for x86-based systems this should be /dev/sdx6. For Marvell ARM based models it should be /dev/mtdblock5 or /dev/mtdblock4. In this case we are working on higher model based on x86 and will mount /dev/sdx6:

    [~] # mount -t ext2 /dev/sdx6 /tmp/config
    [~] # df -h
    Filesystem                Size      Used Available Use% Mounted on
    /dev/ramdisk            139.5M    111.9M     27.5M  80% /
    tmpfs                    64.0M    164.0k     63.8M   0% /tmp
    /dev/sda4               310.0M    220.0M     90.0M  71% /mnt/ext
    /dev/md9                509.5M     88.8M    420.6M  17% /mnt/HDA_ROOT
    /dev/md0                  7.2T    402.7G      6.8T   5% /share/MD0_DATA
    tmpfs                    32.0M         0     32.0M   0% /.eaccelerator.tmp
    /dev/sdx6                 3.9M     44.0k      3.8M   1% /tmp/config
    [~] # 
    [~] # ls -al /tmp/config/
    drwxr-xr-x    3 admin    administ     1024 May 11 17:43 ./
    drwxrwxrwx    8 admin    administ     1160 May 11 17:43 ../
    -rw-r--r--    1 admin    administ        1 May  3 17:30 BOOT_COUNT
    -rw-r--r--    1 admin    administ       27 Mar  6 12:21 customise.conf
    drwx------    2 admin    administ    12288 Jan 11  2010 lost+found/
    -rw-r--r--    1 admin    administ     3036 May  3 17:28 smb.conf
    -rw-r--r--    1 admin    administ       11 May  3 17:28 smb.conf.cksum
    -rw-r--r--    1 admin    administ       37 May  3 17:28 system.map.key
    -rw-r--r--    1 admin    administ     4552 Mar  8 11:48 uLinux.conf
    [~] #

     

  3. Create or adapt autorun.sh

    A shell script called “autorun.sh” will be executed by your QNAP storage system on every startup. If you have a freshly installed QNAP and never created/adapted “autorun.sh”, it might be possible that file currently does not exist.
    In this example we created the “autorun.sh” and implemented the following commands:

    [~] # vi /tmp/config/autorun.sh
    [~] # 
    [~] # cat /tmp/config/autorun.sh
    #!/bin/sh
     
    route add -net 192.168.35.0 netmask 255.255.255.0 gw 192.168.91.254
     
    [~] #

     

  4. Make sure that autorun.sh is executable

    In order to be executable during startup, we will have to set the executable flag for “autorun.sh”:

    [~] # ls -al /tmp/config/autorun.sh   
    -rw-r--r--    1 admin    administ       60 May 11 17:43 /tmp/config/autorun.sh*
    [~] # 
    [~] # chmod +x /tmp/config/autorun.sh 
    [~] # 
    [~] # ls -al /tmp/config/autorun.sh   
    -rwxr-xr-x    1 admin    administ       60 May 11 17:43 /tmp/config/autorun.sh*
    [~] #
  5. Test the command or autorun.sh

    Test the actual added content of your autorun.sh or if it is newly created test the execution of the whole script. In this case we have created a completely new autorun.sh and therefore can test the whole execution:

    [~] # /tmp/config/autorun.sh
    [~] # netstat -rn
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    ...
    192.168.35.0    192.168.91.254  255.255.255.0   UG    0      0        0 eth0
    ...
    [~] #
  6. Unmount /tmp/config

    If everything went well, unmount /tmp/config:

    [~] # umount /tmp/config/
    [~] # df -h
    Filesystem                Size      Used Available Use% Mounted on
    /dev/ramdisk            139.5M    111.9M     27.5M  80% /
    tmpfs                    64.0M    156.0k     63.8M   0% /tmp
    /dev/sda4               310.0M    219.9M     90.1M  71% /mnt/ext
    /dev/md9                509.5M     88.8M    420.6M  17% /mnt/HDA_ROOT
    /dev/md0                  7.2T    400.2G      6.8T   5% /share/MD0_DATA
    tmpfs                    32.0M         0     32.0M   0% /.eaccelerator.tmp
    [~] #
Categories: QNAP Tags: