# 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](https://bin.entware.net/aarch64-k3.10/Packages.html) that can be [installed on the USB device](https://github.com/Entware/Entware/wiki/Install-on-Asus-stock-firmware#deploying-entware). ```bash wget -O - http://bin.entware.net/aarch64-k3.10/installer/generic.sh | sh ``` ## How a script is started at boot (asusware.arm mechanism) Using a non-standard `/opt/etc/init.d` startup script system, services can be launched on boot. We use the app mechanism that Download Master/Optware uses, as described in the [Entware wiki](https://github.com/Entware/Entware/wiki/Install-on-Asus-stock-firmware#alternative-asuswarearm-init-script-recent-firmware): 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` prefix controls ordering (`S99...` runs last). 3. **Enable gate:** A script is skipped unless `/opt/lib/ipkg/info/.control` contains a line `Enabled: yes`, where `` is the script name without the `S` 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/.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 ` (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. What this is used for is described in [Enable TFTP booting](Network:AX4200:Enable_TFTP_booting). 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`), 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.