QNAP TS-41X

This guide contains all necessary information to install a fully running Gentoo Linux on a QNAP TurboStation TS-41X. It is assumed that you will want to have a RAID running on your QNAP.

= Hardware = Here are the hardware configurations of the TS-41X series. The respective U-version (like TS-410U) should not differ from these specifications. However, this has to be verified.

= Setting up an installation environment =

When the device is running, log in via the serial console or ssh. The default credentials are username=admin and password=admin, granting you root access. Now, follow the instructions on installing Debian until the point when you have logged in with the new user (installer).

The Debian installer will show up. Select the following now:
 * Start installer (expert mode)
 * Choose a mirror of the Debian archive (see list of Debian mirrors)
 * ftp
 * Enter the server name of a Debian mirror
 * Enter the directory containing the files. This usually defaults to /debian/
 * Specify a proxy or leave it blank
 * Choose your Debian flavor
 * Download installer components
 * ''Mark the tools you will need for installing gentoo. I only chose fdisk here.'
 * Detect disks
 * Partition disks
 * When you are prompted for the type of installation (manually or automatically), go back to the main menu.
 * Execute a shell

This will open an ash-shell and you will have access to the tools you downloaded previously, including the ones downloaded by default, such as mdadm. You should now have everything at your disposal needed to install Gentoo.

= Preparing the boot system =

Requirements
In order to create your own kernel and initramfs, you need to install and.

Initramfs
On startup, the NAS will only boot your kernel and the initramfs, so you will have to do start up your system from the initramfs. A minimal init script could look like this:

You can then build the initrd by executing

For more information on how to build an initrd, see Initramfs.

Since your flash memory for the initramfs can only store 9 MiB, you will want to have an initrd which is smaller or equal. However, since the boot loader loads exactly 9 MiB, you will need to adjust the size of the initrd:

This command writes exactly 9437184 bytes from to  filling up remaining space with zeros.

Flashing
Flash the kernel using

and the initrd with

After restarting the device, it will boot with the recently flashed kernel and initramfs.

= Recovering the original firmware = There are two possible ways of recovering the factory firmware, which basically work the same way. You have the TS-41X retrieve a recovery image via TFTP. It will flash it and restart. Both of the explained methods will assume that you have already shut down your QNAP device.

Using the Flash Reburn live cd
A thorough guide can be found on the official QNAP homepage.

Creating your own recovery image
= Access through a serial console = For debugging purposes, it is very useful to have serial access to the NAS. This section covers how to set up such a connection.

Preparation
The following Hardware and Software sections are based on [2].

Hardware
To access a QNAP TS-41X, you need a 3.3V TTL to RS-232 level shifter and a jumper. Put the jumper on JP1 to activate the serial console and connect the cable to CN1 which is of type JST PHR-4. The pin layout of the connector on the QNAP board is from top to bottom TX, VCC, RX, GND.

The TS-41X devices use 8 data bits, no parity, and 1 stop bit (8N1) at 115200 baud.

Software
In order to connect to the serial device, we will use.

Wiring the cable


You want the SIL connector the be replaced with the PHR-4 (the small white one), so do the following:
 * Write down the pin layout of the SIL connector of the 3.3V TTL to USB cable (e.g. pin 1 black, pin 2 green, ...). This way you can restore the factory setting.
 * Unplug RX, TX, and GND pins from the SIL.
 * RX from your connector cable must be linked with TX on the QNAP device and analogously the TX from the connectory cable must be linke with RX on the QNAP device. GND has to be linked with GND. So the layout of the PHR-4 plug looks the following from top to bottom (using names of the connector cable): RX, empty (we don't need VCC), TX, GND

Establishing the connection
Connecting is pretty straight forward. Since 8N1 is commonly used, we simply call

= Troubleshooting =

Genkernel fails when trying to compile mdadm into the initramfs
There is a workaround for this issue. By enabling USE="" for mdadm on your system, genkernel will copy the existing system files instead of trying to compile mdadm itself.

Serial console behaves strange
If you are only receiving strange characters of which none are readable, you are using a wrong connector cable. Keep mind that the QNAP device uses 3.3V and you need a converter to USB (5V) or RS-232 (12V).

= See also =
 * QNAP TS-210

= References =
 * 1) Official genkernel documentation
 * 2) Connecting a serial console to a QNAP TS-41X
 * 3) Firmware update through recovery mode

= External links =
 * Gentoo embedded handbook on installing a QNAP TS-109/209/409
 * Installing Debian on a QNAP TS-410X