TS-x09 Stock Userspace
From Qnap-Wiki
Notes about the stock QNAP TS-209 and TS-409 firmware (version 2.0.1 Build 0416T) and userspace, with the intention of determining the best way to support these devices with Optware packages.
Contents |
Flash Layout
The "U-Boot", "U-Boot Config", and "Kernel" partitions have the obvious contents, and are used in the normal manner to boot the kernel.
The "NAS Config" partition is an ext2 filesystem which contains information specific to a particular board instance, and is described below.
The "RootFS1" and "RootFS2" partitions need more investigation ...
TS-109
[~] # cat /proc/mtd dev: size erasesize name mtd0: 00080000 00020000 "U-Boot" mtd1: 00200000 00020000 "Kernel" mtd2: 00400000 00020000 "RootFS1" mtd3: 00100000 00020000 "RootFS2" mtd4: 00020000 00020000 "U-Boot Config" mtd5: 00060000 00020000 "NAS Config" [~] #
TS-209 (II)
[~] # cat /proc/mtd dev: size erasesize name mtd0: 00080000 00020000 "U-Boot" mtd1: 00200000 00020000 "Kernel" mtd2: 00400000 00020000 "RootFS1" mtd3: 00100000 00020000 "RootFS2" mtd4: 00020000 00020000 "U-Boot Config" mtd5: 00060000 00020000 "NAS Config" [~] #
TS-409
[~] # cat /proc/mtd dev: size erasesize name mtd0: 00080000 00020000 "U-Boot" mtd1: 00200000 00020000 "Kernel" mtd2: 00400000 00020000 "RootFS1" mtd3: 00100000 00020000 "RootFS2" mtd4: 00020000 00020000 "U-Boot Config" mtd5: 00060000 00020000 "NAS Config" mtd6: 00400000 00020000 "mtdram test device" [~] #
NAS Config Partition
"BOOT_COUNT" contains a single integer which is incremented each time the device is rebooted.
"ETH0.MAC_ADDR" contains the ethernet MAC address of the single Gigabit network interface.
"board_level_test.cfg" seems to be the output of the manufacturing board test and configuration process.
"hw_type" contains "0099" for both the TS-209 Pro II and TS-409 Pro.
"mv_eth_tool.txt" contains "1000 " refering to Gigabit ethernet.
"storage.conf" contains the RAID disk configuration details.
"uLinux.conf" contains the user configuration settings.
If you add an autorun.sh script to this partition, it is executed on each boot. This is important because the root filesystem is a ramdisk, so many changes that you might otherwise make to it directly are lost on each reboot.
[~] # mount -t ext2 /dev/mtdblock5 /mnt/config [~] # ls -lR /mnt/config/ /mnt/config/: -rw-r--r-- 1 admin administ 1 May 19 16:45 BOOT_COUNT -rw-r--r-- 1 admin administ 18 May 20 01:14 ETH0.MAC_ADDR -rw-r--r-- 1 admin administ 316 May 19 20:34 board_level_test.cfg -rw-r--r-- 1 admin administ 5 May 19 20:34 hw_type -rw-r--r-- 1 admin administ 5 May 19 20:34 mv_eth_tool.txt -rw-r--r-- 1 admin administ 472 May 19 20:34 storage.conf -rw-r--r-- 1 admin administ 3469 May 19 12:54 uLinux.conf [~] #
Filesystem Mounts
/dev/md0 is the main data partition.
/dev/md4 is the swap partition.
/dev/md9 seems to be the applications partition.
/dev/sda4 contains /home and /usr persistent directories. It's unclear why this is not RAID space.
TS-209 (II)
[~] # cat /proc/partitions major minor #blocks name 8 0 732574584 sda 8 1 530113 sda1 8 2 530145 sda2 8 3 731423385 sda3 8 4 80325 sda4 8 16 732574584 sdb 8 17 530113 sdb1 8 18 530145 sdb2 8 19 731423385 sdb3 8 20 80325 sdb4 31 0 512 mtdblock0 31 1 2048 mtdblock1 31 2 4096 mtdblock2 31 3 1024 mtdblock3 31 4 128 mtdblock4 31 5 384 mtdblock5 9 0 731423296 md0 9 9 530048 md9 9 13 71808 md13 9 5 530048 md5 [~] # cat /proc/mounts rootfs / rootfs rw 0 0 /dev/root / ext2 rw 0 0 /proc /proc proc rw,nodiratime 0 0 none /dev/pts devpts rw 0 0 sysfs /sys sysfs rw 0 0 tmpfs /tmp tmpfs rw 0 0 usbfs /proc/bus/usb usbfs rw 0 0 /dev/sda4 /mnt/ext ext2 rw 0 0 /dev/md9 /mnt/HDA_ROOT ext3 rw 0 0 /dev/md0 /share/MD0_DATA ext3 rw 0 0 [~] #
TS-409
[~] # cat /proc/partitions major minor #blocks name 8 0 156250000 sda 8 1 530113 sda1 8 2 530145 sda2 8 3 155099542 sda3 8 4 80325 sda4 8 16 117220824 sdb 8 17 530113 sdb1 8 18 530145 sdb2 8 19 116069625 sdb3 8 20 80325 sdb4 31 0 512 mtdblock0 31 1 2048 mtdblock1 31 2 4096 mtdblock2 31 3 1024 mtdblock3 31 4 128 mtdblock4 31 5 384 mtdblock5 31 6 4096 mtdblock6 9 0 116069504 md0 9 9 530048 md9 9 13 71808 md13 9 4 530048 md4 [~] # cat /proc/mounts rootfs / rootfs rw 0 0 /dev/root / ext2 rw 0 0 /proc /proc proc rw 0 0 none /dev/pts devpts rw 0 0 sysfs /sys sysfs rw 0 0 tmpfs /tmp tmpfs rw 0 0 usbfs /proc/bus/usb usbfs rw 0 0 /dev/sda4 /mnt/ext ext3 rw,data=ordered 0 0 /dev/md9 /mnt/HDA_ROOT ext3 rw,data=ordered 0 0 /dev/md0 /share/MD0_DATA ext3 rw,data=writeback,jqfmt=vfsv0,usrjquota=aquota.user 0 0 [~] #
Boot Process
The kernel executes /linuxrc, which is a symlink to /bin/busybox. Busybox reads /etc/inittab and executes the sysinit actions. One of the sysinit actions executes /etc/init.d/rcS. /etc/init.d/rcS executes the startup scripts in /etc/rcS_init.d. There is only one startup script: /etc/rcS_init.d/S20init_check (which is a symlink to /etc/init.d/init_check.sh). The aspects from that script (and the sub-scripts that it executes) that are related to filesystem layout are:
mount -t proc /proc /proc
mount -o remount,rw /
mount -a
mount -t sysfs sysfs /sys
mount -t tmpfs tmpfs /tmp -o size=16M
mount -t usbfs usbfs /proc/bus/usb
/bin/mount /dev/sda4 /mnt/ext
/bin/ln -s /mnt/ext/home /home
/bin/ln -s /mnt/ext/usr /usr
/bin/mv /etc/rcK.d/K24thttpd /etc/rcK_init.d/
/bin/mv /etc/rcK.d/K40network /etc/rcK_init.d/
/bin/mv /etc/rcK.d/K66shutdown_check /etc/rcK_init.d/
/bin/mv /etc/rcK.d/K80init_disk /etc/rcK_init.d/
mount /dev/mtdblock5 -t ext2 /tmp/config
[ -f /tmp/config/autorun.sh ] && /tmp/config/autorun.sh
for i in /tmp/config/* ;do
case "$i" in
/tmp/config/K01*.sh)
echo $i start
. $i start &
cp $i /etc/rcK_init.d
;;
*)
;;
esac
done
umount /dev/mtdblock5
/etc/init.d/runone.sh
/bin/umount /dev/mtdblock3 1>>/dev/null 2>>/dev/null
What this tells us is that we can install Optware startup scripts in /dev/mtdblock5 as autorun.sh and K01*.sh and they will be executed on each boot and shutdown.

