# The NAS at the shell

What QTS and QuTS hero are when a script runs on them. Measured by QNAP Club Poland on QTS 6.1 and QuTS hero 6.0
units; the source files are linked at the end.

## Storage, paths and USB disks

What survives a reboot, how to resolve the data volume and a package's folder, the system partitions, and the
mount check before a script writes to a USB disk are in [storage-and-paths.md](storage-and-paths.md). In short:
the root file system is a RAM disk, `/tmp` is a small tmpfs, and only `/etc/config` and the data volumes last.

## QTS or QuTS hero

- A firmware version with an `h` prefix (`h6.0.0`) is QuTS hero: ZFS, pools and datasets, `zpool` and `zfs` on
  `PATH`. Without the prefix it is QTS: ext4 on LVM, `/share/CACHEDEV<N>_DATA`.
- `Version` in `/etc/config/uLinux.conf` is not the firmware you are on. QuTS hero 6.x and QTS 6.0 report `5.2.10`
  there so older apps keep installing. Do not branch on it; read the kernel (`uname -r`) or test for `zpool`.
- Both have the same BusyBox, the same `/etc/config` and the same `getcfg`.

## Commands: BusyBox, not GNU

Most classic commands are BusyBox 1.24.1 applets (2015) with fewer flags, and some names resolve to a fuller program
instead. A flag you know from Ubuntu may be missing. Check a name against
[absent-commands.json](https://forum.qnap.net.pl/llms/absent-commands.json) before you script with it.

The commands that do not exist, or lack a flag, and what to write instead are in
[never-recommend.md](never-recommend.md): `timeout`, `nohup`, `flock`, `pgrep`, `pkill`, a bare `printf`,
`realpath`, `getopt`, `ss`, `nproc`, `lsblk`, `grep -P`, `find -printf`, `systemctl`, `apt`, `useradd`,
`crontab -e`, `sudo` and more.

Present on QTS 6.1 and safe to use: `jq`, `curl` (`/sbin/curl`), `rsync` (`/usr/bin/rsync`), `setsid`
(`/bin/setsid`), `watch -n`, `readlink -f`, `stat -c`, `date -d @<epoch>`, `find -maxdepth`, `sed -E`,
`du --max-depth`, `head -c`. `jq` is QNAP's own copy on QTS; treat it as conditional on QuTS hero. The forum's QuTS
hero 6.0 capture has `curl` and `/bin/setsid` (call it by that path: `/usr/bin/setsid` does not exist) but records
no path for `rsync`: check for it there before you rely on it.

For a time limit, use the program's own option first. QNAP's `/sbin/curl` lists `--max-time` (`-m`) and
`--connect-timeout` among its options on QTS 6.1 and QuTS hero 6.0:

```sh
/sbin/curl -fs -m 30 --connect-timeout 10 -o "$OUT" "$URL" || /sbin/log_tool -t 1 -a "mysvc: download failed"
```

Keep the background job and `kill` for a program with no such option.

**Never run an unknown QNAP binary to see what it does.** `--help` is data to some of them: `gen_hostname --help`
renamed a NAS and took it off the network, and BusyBox `reboot -h` halts. BusyBox here has no help text at all. Read
the recovered usage in [help-qts61.txt](https://forum.qnap.net.pl/llms/help-qts61.txt) or
[help-hero60.txt](https://forum.qnap.net.pl/llms/help-hero60.txt).

## Services

- A service is `/etc/init.d/<name>.sh`, not a systemd unit. On QuTS hero 6.0, 111 of its 284 init scripts accept
  `start`, fewer accept `stop` or `restart`, and 4 accept `status`. In many the first argument is data, not a
  verb. Read the script's `case` before you call it.
- To learn whether something runs, look for its process (`pidof`) or its PID file, not `status`.
- A QPKG's own service script is yours to write, and QTS calls it with `start`, `stop` and `restart`
  ([qpkg.md](qpkg.md)).

## Settings, cron and logs

- `getcfg <section> <key> [-d <default>] -f /etc/config/<file>.conf` and `setcfg <section> <key> <value> -f …` read
  and write the ini files under `/etc/config`. Avoid `rmcfg`: on a QuTS hero unit it deleted the whole section, so
  Bucket & Code Server IDE never calls it; clear a key with `setcfg` and an empty value instead. Edit a file by hand
  only when no QNAP service rewrites it.
- Cron: a `crontab -e` edit is lost at reboot, while `/etc/config/crontab` persists. Add the line there, then run
  `crontab /etc/config/crontab`. Cron runs the line with the NAS's own `PATH`: call programs by full path.
- System Logs (the event log QTS shows): `/sbin/log_tool -t <type> -a "message"`, where the type is 0 for
  information, 1 for a warning and 2 for an error; `log_tool -q` lists it. Kernel messages: `dmesg`.
- `/var/log` is a tmpfs; a program that must keep its log writes it to a data volume.

## Accounts and root

The admin account's SSH login is uid 0. `su` does not exist, and `sudo` has nothing to raise. Every program a QPKG
starts runs as root unless it drops privileges itself.

## Sources

QNAP Club Poland (forum.qnap.net.pl), cited as the source of every fact on this page:
[guidelines.md](https://forum.qnap.net.pl/llms/guidelines.md),
[ai-guidelines-hero60.md](https://forum.qnap.net.pl/llms/ai-guidelines-hero60.md),
[ai-exclusions-qts61.md](https://forum.qnap.net.pl/llms/ai-exclusions-qts61.md),
[linux-gap.md](https://forum.qnap.net.pl/llms/linux-gap.md),
[absent-commands.json](https://forum.qnap.net.pl/llms/absent-commands.json),
[storage-layout.md](https://forum.qnap.net.pl/llms/storage-layout.md),
[services-qts61.md](https://forum.qnap.net.pl/llms/services-qts61.md). The full index is
[llms/llms.txt](https://forum.qnap.net.pl/llms/llms.txt).
