【重要資安警示】發現冒充 Qfinder Pro 的非官方網站,了解詳情 >

此頁面為機器翻譯版本,請參閱機器翻譯免責聲明。
切換為English

Running Your Own Application at Startup
在啟動時執行您自己的應用程式


最後修訂日期: 2023-07-06
適用產品:
  • 所有 NAS 系列

某些進階的 NAS 使用可能需要您在開機時執行自訂應用程式。即使 QNAP NAS 是基於 Linux,您也無法使用一般的 Linux 方法在啟動時啟動應用程式:預設的配置檔案會在每次啟動時重置。

所需技能

  • 必須能夠透過 SSH 遠端登入(例如使用SSH PuTTY)
  • 必須知道如何使用 nano、vi 編輯檔案,或透過 SFTP 編輯(例如使用WinSCP)

基於 MTD 的方法

Autorun.sh 是一個在每次 TS-x09、TS-x19 和 TS-x39 啟動時執行的指令碼。編輯此檔案可以讓您啟動自己的程式或用自己的副本覆蓋配置檔案。

手動編輯 autorun.sh

  1. 使用 SSH 登入您的 QNAP 裝置,例如使用 Putty

  2. 選擇性:安裝 nano;使用ipkg install nano並用 nano 編輯而非 vi

  3. 透過在下方找到您的特定型號來掛載配置 ramblock:

    • 所有基於 HAL 的 Intel 和 AMD NAS:

      注意:從 QTS 4.3.3 開始,需要在控制台 -> 硬體 -> 一般中啟用 autorun.sh 處理:運行使用者定義的啟動過程 (autorun.sh)

      • QTS 5.x

        sudo -i
        mount $(/sbin/hal_app --get_boot_pd port_id=0)6 /tmp/config

      • QTS 4.x
        mount $(/sbin/hal_app --get_boot_pd port_id=0)6 /tmp/config

    • TS-212P3, TS-230:掛載配置 ramblock /dev/mmcblk0p5:
      mount -t ext2 /dev/mmcblk0p5 /tmp/config

    • TS-269L:掛載配置 ramblock /dev/sdc6:
      mount -t ext2 /dev/sdc6 /tmp/config

    • TS-439、TS-509、TS-639、TS-809、TS-809U (x86):掛載配置 ramblock /dev/sdx6:
      mount -t ext2 /dev/sdx6 /tmp/config

    • TS-109、TS-109P、TS-110、TS-119、TS-209、TS-209P、TS-212、TS-219、TS-409 (Marvell ARM)、TS-412、TS-419P:掛載配置 ramblock /dev/mtdblock5:

      注意:在 TS-219P II 上,您可能需要使用 ext4 而不是 ext2

      mount -t ext2 /dev/mtdblock5 /tmp/config

    • TS-201:掛載配置 ramblock /dev/mtdblock4:
      mount -t ext2 /dev/mtdblock4 /tmp/config

建立 / 編輯 /tmp/config/autorun.sh。

  1. 使用此命令 # vi /tmp/config/autorun.sh 編輯 autorun.sh,然後按 a進入編輯模式

    1. 編輯您需要的內容
    2. 退出編輯模式:按 ESC
    3. 儲存並退出:x
  2. 或者使用桌面 PC 和例如 SFTP 編輯 autorun.sh

  3. 使用此命令 # chmod +x /tmp/config/autorun.sh 確保 /tmp/config/autorun.sh 是可執行的

  4. 重要:使用此命令 # umount /tmp/config 卸載已掛載的快閃分區

editautorun.sh:簡化 autorun.sh 編輯的指令碼

如果您經常編輯此檔案,可以透過建立一個 shell 指令碼(例如 editautorun.sh)來節省一些時間以自動化過程。您可以將指令碼放在環境路徑中,或將其資料夾新增到路徑中,或透過別名呼叫它。

指令碼內容為:

所有基於 HAL 的 Intel 和 AMD NAS 使用...

mount $(/sbin/hal_app --get_boot_pd port_id=0)6 /tmp/config
touch /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
$EDITOR /tmp/config/autorun.sh
umount /tmp/config

所有 AL 架構的 NAS (TS-x31+ 和 TS-x31X) 和 TS-x31 使用...

ubiattach -m 6 -d 2
/bin/mount -t ubifs ubi2:config /tmp/config
vi /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
echo .
echo "unmounting /tmp/config..."
umount /tmp/config
ubidetach -m 6

TS-230 使用...

mount -t ext2 /dev/mmcblk0p5 /tmp/config
vi /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
echo .
echo "unmounting /tmp/config..."
umount /tmp/config

TAS-x68、TS-x28 使用...

/bin/mount -t ext4 /dev/mmcblk0p7 /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) 使用...

mount -t ext2 /dev/sdx6 /tmp/config
vi /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
echo .
echo "unmounting /tmp/config..."

對於 TS-109、TS-109P、TS-119、TS-209、TS-209P、TS-219、TS-412、TS-409 (Marvell ARM) 使用...

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-201 使用...

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

使用 "init" 指令碼來掛載快閃記憶體

QNAP GUI 能夠檢視 autorun.sh 的內容。在 TS-831XU-RP 上的 V4.5.1.1540 版本中,GUI 是這樣做的:

/etc/init.d/init_disk.sh mount_flash_config
(顯示 /tmp/nasconfig_tmp/autorun.sh)
/etc/init.d/init_disk.sh umount_flash_config

使用這些命令,您可以在指定位置創建 / 編輯 "autorun.sh"。

允許在啟動時執行 autorun.sh

完成 autorun.sh 後,請不要忘記啟用選項以允許在系統啟動時運行 autorun.sh。


這篇文章有幫助嗎?

59% 的人認為有幫助。
謝謝您,我們已經收到您的意見。

需要進一步協助,歡迎前往官方社群發文,與其他用戶及 QNAP 專家交流。 前往 QNAP 官方社群

請告訴我們如何改進這篇文章:

如果您想提供其他意見,請於下方輸入。

選擇規格

      顯示更多 隱藏更多
      選擇其他偏好的語言:
      歡迎隨時洽詢! 歡迎隨時洽詢!
      back to top