network:ax4200:install_additional_software

This is an old revision of the document!


Install additional software

You can get a system for installing additional software by:

  1. plugging in a partitioned, ext4 formatted USB device
  2. enabling Download Master on that USB device

The Download Master installation mounts a subdirectory on the USB device to opt/bin and it fetches a bunch of packages including ipkg, the same tool that manages packages on OpenWRT.

Entware

Entware is a repository of prebuilt packages that can be installed on the USB device.

wget -O - http://bin.entware.net/aarch64-k3.10/installer/generic.sh | sh

Using a standard init.d startup script system services can be launched on boot.

How a script is started at boot (asusware.arm mechanism)

On recent stock firmware the script_usbmount/script_usbumount NVRAM variables no longer work (their values are discarded shortly after nvram commit), so they cannot be used to run something at boot. Instead you can abuse the app mechanism that Download Master/Optware uses, as described in the Entware wiki:

  1. Discovery: The firmware scans mounted USB partitions for a directory named asusware.arm at the partition root (suffix depends on architecture; asusware.arm on this aarch64 router). It exposes that directory as /opt — this is why /opt exists even without Entware. During detection the partition is unmounted and re-mounted, so anything mounted earlier from it is gone; do your own mounting inside the init script.
  2. Init scripts: At boot/mount the firmware runs /usr/sbin/app_init_run.sh allpkg start, which iterates over /opt/etc/init.d/S* and runs each script with the argument start (on unmount with stop). The S<nn> prefix controls ordering (S99... runs last).
  3. Enable gate: A script is skipped unless /opt/lib/ipkg/info/<name>.control contains a line Enabled: yes, where <name> is the script name without the S<nn> prefix. The field is read by /usr/sbin/app_get_field.sh from the .control file.
  4. Copy before run: Each script is first copied to /opt/<Sname>.1 and that copy is what actually gets executed (sh /opt/S99patch-and-restart-dnsmasq.1 start). So edits to the original only take effect after a remount/reboot. (On NTFS/fuseblk the copy is instead sed-filtered to neuter chmod/chown lines.)

On this router the layout on the USB stick (/tmp/mnt/sda1) is:

/tmp/mnt/sda1/
├── asusware.arm/                          # exposed as /opt
│   ├── .asusrouter                        # marker file, must exist (empty)
│   ├── etc/init.d/
│   │   └── S99patch-and-restart-dnsmasq   # symlink -> ../../../data/patch-and-restart-dnsmasq.sh
│   └── lib/ipkg/info/
│       └── patch-and-restart-dnsmasq.control   # "Enabled: yes" gates the start
└── data/
    └── patch-and-restart-dnsmasq.sh       # the real script (kept outside /opt)

The real script lives in data/ and is only symlinked into etc/init.d/, so it can be edited without touching the app directory. It expects start/stop as $1, logs with logger -t <TAG> (check System Log for the tag after reboot), and in the start branch patches /etc/dnsmasq.conf to read conf-dir=/tmp/mnt/sda1/data/dnsmasq.d, opens the TFTP firewall ports and restarts dnsmasq.

The relevant files from the router (app_init_run.sh, app_get_field.sh, the init script, control file and the patch script) are kept as a mirror of the router filesystem under network/ax4200/router-files/.

Tips:

  • Reboot and check the system log: look for the asusware: ... detection lines, then your script's own log tag.
  • If the script doesn't run, make sure the .control file has Enabled: yes, the script name matches the control file name (minus S<nn>), and remember the .1 copy semantics above.
  • Sometimes detection only works after installing Download Master once (on another stick), then swapping back. nvram set stop_fsck=1 skips the fsck delay at mount.
network/ax4200/install_additional_software.1792945376.txt.gz · Last modified: by admin