RedSleeve Wikia

Install on QNAP TS-421

19pages on
this wiki
Add New Page
Comments0 Share

Initialization Edit

Insert a 3.5" SATA disk complete the standard factory setup as per the instructions that came with your QNAP TS-421. This is done using it's web interface and will take a few minutes. Once this step is completed you should be able to ssh into it.

The stock firmware's kernel version is

# uname -r

The SHA1 checksum of the kernel flash partition should be as follows:

# cat /dev/mtdblock1 | sha1sum
 6ff96114a82dd4864751329e2f2480a8085be6c7  -

If these two don't match on your TS-421, it would probably be a good idea to seek help on the mailing list before you proceed.

Retrieve Files From Standard Firmware Edit

You will need to acquire the following files from the standard firmware:

Kernel modules:Edit


Note: Make sure you get the actual files, not the symlinks pointing to those files, such as /lib/modules/other which points to /usr/local/modules.

You will need to put these in /lib/modules/{misc,local} on your RedSleeve rootfs.

Libraries: Edit


You will need to copy these files into /usr/local/lib on your RedSleeve and place symlinks into /lib/ and /usr/lib/ folders as per the original locations listed above.

Executables Edit

You will need at least the following:


Put these in /usr/local/sbin, and symlink get_time and lcd_tool to /sbin/

Extras for Further Investigation Edit

For completeness and further investigation later on, you may also want to copy across the following executables with all the symlinks pointig to them:


You can also put these in /usr/local/sbin/

Custom initramfs Edit

Unfortunately, the uboot parameters on the QNAP TS-421 are not fully adjustable - there are things that are hard-coded in uboot that override the settings stored in the uboot configuration flash segment. This, unfortunately, means we cannot change the uboot parameter that tells the kernel where to look for the rootfs. This isn't a show stopper - we just need a custom initrd that handles initial rootfs mounting.

Here is the QNAP TS-421 custom initramfs I use. For the gory details you are encouraged to extract the initramfs and look at /init script.

Investigating the Gory initramfs Details Edit

You can extract it as follows:

gzip -cd QNAP_TS-421_initramfs- | cpio -i

In brief it does the following: 1) Assembles any MD arrays it finds (RAID 0/1/10 support is built into the stock kernel which is what we are using) 2) Looks for /sbin/init on present disks in the following order: md127, sda2, sdb2, sdc2, sdd2. The reason it looks for rootfs on the 2nd partition is purely a convention I use (partition 1 is either /boot or the zfs partition). Feel free to edit it if you prefer the initramfs to look on different partitions. 3) Once it finds /sbin/init, it disables the TS-421's build in watchdog (using pic_raw) and executes switch_root to hand over execution to init on the rootfs.

If you are planning to edit the initrd, make sure you have wired up the serial console to your TS-421 so that you can get it booting again if you make a mistake.

If you have edited the initrd, you can repack it using:

find . | cpio -H newc -o | gzip -9 > mynewinitramfs.img

You can burn this to the on-board flash using:

dd if=mynewinitramfs.img of=/dev/mtdblock2.img ibs=9437184 obs=9437184

Note: The on-board watchdog gets enabled by uboot at boot time. This is one of those hard-coded options in uboot, and while you can change any options manually at boot time using the serial console for a single boot, they will not survive a reboot. The watchdog will automatically reboot the machine 5 minutes after booting up if it is not disabled, so it is vital we disable it during boot.

Integrate rootfs Edit

Disk Preparation Edit

Put the disk you intend to use in a different machine. Make sure it has a suitably sized partition 2. If you are reading this wiki entry, it is assumed you are extremely comfortable with operations like this. Format partition 2 as ext4. Grab the current rootfs tarball and extract it to partition 2 you just formatted.

Extra Files from Original Firmwre Edit

Take the files you copied from the stock firmware rootfs earlier and put it in the rootfs you just created:

  • Modules in /lib/modules/{misc,other}.
  • Libraries in /usr/local/lib/ with symlinks to /lib or /usr/lib as listed above.
  • Binaries in /usr/local/sbin/ with symlinks in /sbin for the two files mentioned above.

Disable Virtual Terminal Consoles Edit

Disable virtual terminals since we have no frame buffer. In /etc/sysconfig/init (pseudo-diff):


If you don't do this there will be unnecessary noise in syslog.

Serial Console for Debugging Only Edit

If you are using the serial console, add this a file ttyS0.conf file to /etc/init/:

# cat ttyS0.conf.bak 
 start on stopped rc RUNLEVEL=[2345]
 stop on starting runlevel [016]
 pre-start exec /sbin/securetty ttyS0
 exec /sbin/agetty -L /dev/ttyS0 115200 vt102

Note: DO NOT do this if you aren't using the serial console - this is only for debugging purposes and initial configuration as it requires the case to be removed. With the case removed there will be no airflow through the case and the disks and CPU are going to run much hotter than intended, so don't run the TS-421 without the case in normal operation.

Ensure SSHD is Enabled Edit

Make sure ssh is enabled in the rootfs or you will not be able to log in:

# ls -la /etc/rc3.d/*ssh*
 lrwxrwxrwx 1 root root 14 Feb 22 17:26 /etc/rc3.d/S55sshd -> ../init.d/sshd

Network Configuration Edit

Make sure your network interface is configured appropriately or you will not be able to log in:

# cat /etc/sysconfig/network-scripts/ifcfg-eth0 

LEDs, LCD Display, Fan Control Edit

Adjust rc.local with some useful things such as telling you what the IP address of eth0 is without having to look it up on your DHCP server:

# cat /etc/rc.local
 touch /var/lock/subsys/local
 export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin
 # Status LED ON - Green
 pic_raw 86
 # Configure LCD Display and Messages
 lcd_tool -s 2
 stty -F /dev/ttyS0 1200
 sleep 1
 echo -e "M^\x1" > /dev/ttyS0
 sleep 1
 echo -e "M\f\x0 Red Sleeve Linux" > /dev/ttyS0
 sleep 1
 ipaddr=`ifconfig eth0 | grep "inet addr:" | sed -e 's/.*inet addr://' -e 's/ .*//'`
 echo -e "M\f\x1 $ipaddr         " > /dev/ttyS0
 # Set fan to 4/5 speed (48:OFF 53:FULL)
 pic_raw 52

Enable Alignment Warnings and Configure MAC Addresses Edit

Set this to get warnings in the logs when alignment errors occur. Consider reporting a bug for these especially if they occur thousands of times in a frequently running program.

 # cat /etc/sysconfig/modules/alignment.modules 
 echo 3 > /proc/cpu/alignment

Note: The MACs here are made up, change them to what the label on the back of your NAS says. You can also get the MAC address of the primary interface using the "pic_get_mac" program copied from the stock firmware. The secondary interface's MAC is always adjecent and above the primary interface's MAC.

# cat /etc/sysconfig/modules/eth.modules 
 /sbin/ip link set dev eth0 address 00:11:22:33:44:55
 /sbin/ip link set dev eth1 address 00:11:22:33:44:56

The Moment of Truth Edit

Finally, dd the initramfs you downloaded (and possibly modified as mentioned above) to /dev/mtdblock2.img:

dd if=QNAP_TS-421_initramfs- of=/dev/mtdblock2.img ibs=9437184 obs=9437184

Shut down the NAS and insert the disk you just prepared into the first slot. Power it up, and after a little while you should hear:

  • 1) A beep
  • 2) After a little while longer the status LED should go from flashing from red-green to solid green

Once this happens, you should be able to ssh into the machine, and the IP address should show up on the LCD display. If this doesn't happen, hook up the serial console and investigate.

Hooking up the Serial Console Edit

The instructions are available on Martin Michlmayr's site covering Debian on QNAP NAS systems. You will need a TTL to RS232 level shifter cable. The Raspberry Pi Console cable is suitable.

Note: Make sure you connect the RX pin on the cable to the TX pin on the QNAP and vice versa. There is no need to connect the VCC pin so leave it off.

If you are interested in more details on various intricacies of QNAP NAS-es and running non-standard Linux distributions on it, you may want to read through all the information on Martin's site.

Other Useful Information Edit

Reference list of the known pic_raw op codes (some may not be applicable to TS-421):

 48 Fan OFF
  49 Fan Speed 1
  50 Fan Speed 2
  51 Fan Speed 3
  52 Fan Speed 4
  53 Fan Speed FULL
  68 After Power Loss Go To Last State
  76 (INT) Power LED Blink
  77 (INT) Power LED ON
  80 Silence Buzzer
  81 Unsilence Buzzer
  84 Status LED Blink RED Fast
  85 Status LED Blink GREEN Fast
  86 Status LED ON GREEN
  87 Status LED ON RED
  88 Status LED Blink GREEN/RED Fast
  89 Status LED OFF
  90 Status LED Blink GREEN Slow
  91 Status LED Blink RED Slow
  92 Status LED Blink GREEN/RED Fast
  93 Status LED ON RED
  99 10G Ethernet Extra
 100 1G Ethernet Extra
 105 WATCHDOG ON, 5min OFF
 244 EUP OFF
 245 EUP ON

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.