Difference between revisions of "HowTo/InstallDebianOnQNAP"
Line 150: | Line 150: | ||
== Restoring the original QNAP firmware == | == Restoring the original QNAP firmware == | ||
− | <p>If you want to restore the original QNAP firmware on your TS-41x or TS-42x device for some reason, you can follow the instructions below. Please note that this will only work if your Debian system is still working. If your Debian system is broken but the machine itself works, you can use the | + | <p>If you want to restore the original QNAP firmware on your TS-41x or TS-42x device for some reason, you can follow the instructions below. Please note that this will only work if your Debian system is still working. If your Debian system is broken but the machine itself works, you can use the recovery mode to restore the QNAP firmware.</p> |
− | <p>There are two steps to restore the original QNAP firmware. First, you have to put the backup of the flash partitions from the QNAP firmware you made | + | <p>There are two steps to restore the original QNAP firmware. First, you have to put the backup of the flash partitions from the QNAP firmware you made before the installation of Debian into flash.</p> |
<div class="code"> | <div class="code"> | ||
<pre> | <pre> | ||
Line 161: | Line 161: | ||
<p>Second, you have to restart your QNAP, and then go to the web interface to format your disk and install the full QNAP firmware.</p> | <p>Second, you have to restart your QNAP, and then go to the web interface to format your disk and install the full QNAP firmware.</p> | ||
<p>After you put the QNAP firmware back in flash and installed the complete the QNAP software, your device will run the original software from QNAP again.</p> | <p>After you put the QNAP firmware back in flash and installed the complete the QNAP software, your device will run the original software from QNAP again.</p> | ||
− | |||
== Recovery mode of QNAP TS-41x/TS-42x devices == | == Recovery mode of QNAP TS-41x/TS-42x devices == |
Revision as of 09:06, 31 May 2014
Contents
Installing Debian on the TS-420
Original source: http://www.cyrius.com/debian/kirkwood/qnap/ts-41x/install/
Overview
In a nutshell, the installation of Debian on your QNAP TS-41x/TS-42x works like this: you use the QNAP firmware to write a Debian installer image to flash. When you restart your device, Debian installer starts and allows you to login via SSH to perform the installation. Debian will be installed to disk and a Debian kernel will be put in flash that will start Debian from disk.
If you follow this procedure, Debian 7 (wheezy) will be installed to your SATA disk and the QNAP firmware on disk and in flash will be replaced with Debian. Debian does not install a web interface to configure your machine, although it's possible to install such software. If this is not what you want, please don't proceed with the installation.
Requirements and Preparation
In order to install Debian on a QNAP device, you need the following:
- A QNAP TS-410, TS-410U, TS-412, TS-419P, TS-419P+, TS-419P II, TS-419U, TS-419U+, TS-420 or TS-421.
- An internal SATA disk.
- A network connection.
- Another machine on which you have a telnet and an SSH client. Telnet is included in Linux and Windows. SSH is included in every Linux distribution as OpenSSH and there is <a href = "http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html">PuTTY</a> for Windows.
Making a Backup
You have to make a backup of all the data stored on your QNAP before starting with the installation of Debian since Debian will format the whole disk during the installation. Also, Debian will replace the QNAP firmware in flash, so it's also recommended to make a copy of the flash (mtd) partitions. Debian will only modify the first two flash partitions but it's a good idea to keep a copy of all partitions as you may need them to use the recovery mode. More detailed instructions for making a backup of your flash partitions will be given later.
Starting the Installer
Start your QNAP device and login via SSH. Some time after you start your machine, you will hear a beep and a bit later you'll hear a longer beep. Wait for a few more seconds and then connect to the machine via SSH. The username is admin
and the password is admin
too.
Once you are logged in, you can save the content of your flash partitions to a USB stick. Connect a USB stick to your QNAP and wait for the system to mount it. In my case, it was mounted at /share/external/sdi
but you can find the location with the following command:
mount | grep external /dev/sdi1 on /share/external/<span class="input">sdi</span> type vfat [...]
Now go to this directory and make a backup of your flash partitions:
cd /share/external/sdi cat /dev/mtdblock0 > mtd0 cat /dev/mtdblock1 > mtd1 cat /dev/mtdblock2 > mtd2 cat /dev/mtdblock3 > mtd3 cat /dev/mtdblock4 > mtd4 cat /dev/mtdblock5 > mtd5 cd umount /share/external/sdi
Disconnect your USB stick from your QNAP, connect it to your PC and to add the mtdX
files to your regular backup.
Now you can go ahead and download the installer.
Download and Flash the Installer
In order to download the Debian installer images, issue the following commands:
cd /tmp busybox wget http://ftp.debian.org/debian/dists/stable/main/installer-armel/current/images/kirkwood/network-console/qnap/ts-41x/initrd.gz busybox wget http://ftp.debian.org/debian/dists/stable/main/installer-armel/current/images/kirkwood/network-console/qnap/ts-41x/kernel busybox wget http://ftp.debian.org/debian/dists/stable/main/installer-armel/current/images/kirkwood/network-console/qnap/ts-41x/flash-debian busybox wget http://ftp.debian.org/debian/dists/stable/main/installer-armel/current/images/kirkwood/network-console/qnap/ts-41x/model
These commands will download the Debian kernel, the installer ramdisk, a file with information about the support QNAP model, and a script to write the kernel and ramdisk to flash. You can now run the script by executing the following command:
sh flash-debian
Please note that this command will take about three minutes to run. You will see the following on your screen:
Updating MAC address... Your MAC address is 00:08:9B:8C:xx:xx Writing debian-installer to flash... done. Please reboot your QNAP device.
Once the command has completed, you can reboot your QNAP device:
reboot exit
The Installation
After you have flashed the Debian installer image and restarted your QNAP device, the Debian installer will start. Since the TS-41x/TS-42x does not have any IO device, SSH will be used for the installation. The installer will bring up the network, start the OpenSSH server and you can then connect to the device using SSH. You have to wait a few minutes after starting the system before you can connect. When the installer is ready, the status LED will change to solid green and your device will beep briefly to indicate that you can now login via SSH.
Please note that Ethernet port numeration differs between the QNAP firmware and Debian. Under Debian, eth0
is the port marked with "LAN2". On the TS-419P, this is the lower (and not the upper) connector!
<a id = "net-config"></a>
Since most TS-41x/TS-42x devices do not have an LCD, the installer cannot tell you which IP address to connect to or which password to use. (On the TS-41x, the LCD is currently not supported but will be supported in the future.) With regards to the IP address, the following strategy is used:
- If your QNAP firmware is configured to use DHCP (the default configuration from QNAP), Debian installer will try to acquire an IP address with DHCP. If you have not initialized your QNAP firmware with QFinder, DHCP will be used. You can use the MAC address of your QNAP device to tell your DHCP server to give out a specific IP address to your machine.
- If you configured a static address in your QNAP firmware, this configuration will be used. However, if your network configuration was incomplete (e.g. IP address or DNS were missing), the installer will use DHCP instead.
-
If DHCP is used but your DHCP server does not respond, the device will use the fallback address
192.168.1.100
. If you are unsure what the address of your QNAP is, unplug the Ethernet cable, start the machine again, wait until Debian installer is ready for SSH and then plug the cable back in and connect to this fallback address.
Please make sure that the QNAP is on a local network to which only you have access since the installer uses a very generic password, namely install
. The user is installer
. Before you can connect to the installer via SSH, you have to remove the SSH key from the QNAP firmware from your known_hosts file. The QNAP firmware uses a different SSH key than the Debian installer, so when you try to connect to Debian you will get an error saying that the remote host identification has changed. Edit ~/.ssh/known_hosts and remove the entry for the IP address of your QNAP device. Now connect to the installer (again, replacing the address in the example with the actual IP address of your QNAP) and login as user installer
with the password install
:
ssh installer@<span class="input">192.168.1.100</span>
The installation itself should be pretty standard and you can follow the <a
href = "http://www.debian.org/releases/stable/armel/">installation guide</a>. The installer knows about the TS-41x/TS-42x and at the end of the installation it will flash a kernel and ramdisk that will automatically boot into Debian. It will also install the qcontrol
package that can be used to control the fan, LEDs and beeper on your QNAP device.
Since the TS-41x/TS-42x boots from flash you don't have many limitations as to how you partition your hard drive. You can use LVM and RAID and a number of filesystems.
At the end of the installation, the installer will write the new kernel to flash. Afterwards you will get a confirmation that the installation is complete. Confirm, wait for the installer to finish and once your SSH session terminates, wait a few minutes before you can connect to your newly installed system via SSH. Your QNAP device will beep when you can connect via SSH. You will be able to log in as root
or your newly created user.
Success
You should now have a complete Debian system running on your QNAP. You can use apt-get
and other tools to install additional software. The TS-41x/TS-42x is an ARM based device and the armel
architecture is fully supported by Debian.
Finally, make sure to read the <a href = "../tips/">tips and tricks</a> about running Debian on the QNAP TS-41x/TS-42x.
Restoring the original QNAP firmware
If you want to restore the original QNAP firmware on your TS-41x or TS-42x device for some reason, you can follow the instructions below. Please note that this will only work if your Debian system is still working. If your Debian system is broken but the machine itself works, you can use the recovery mode to restore the QNAP firmware.
There are two steps to restore the original QNAP firmware. First, you have to put the backup of the flash partitions from the QNAP firmware you made before the installation of Debian into flash.
cat mtd1 > /dev/mtdblock1 cat mtd2 > /dev/mtdblock2
Second, you have to restart your QNAP, and then go to the web interface to format your disk and install the full QNAP firmware.
After you put the QNAP firmware back in flash and installed the complete the QNAP software, your device will run the original software from QNAP again.
Recovery mode of QNAP TS-41x/TS-42x devices
QNAP TS-41x/TS-42x devices have a recovery mode that can be used when there is a problem with your installation of Debian that renders your device unbootable. The system recovery mode allows you write a recovery image to flash via the network using the TFTP protocol. This pages describes how how to create recovery images and how to use the recovery mode. As an alternative to the instructions on this page, you can use a <a href="http://wiki.qnap.com/wiki/Firmware_Recovery">Live CD provided by QNAP</a>.
Creating recovery images
In order to create a recovery image for your QNAP TS-41x/TS-42x, you have to take an exact copy of your flash memory. That is, the recovery image consists of the following parts of your flash in this order: mtd0
, mtd4
, mtd5
, mtd1
, mtd2
, mtd3
. You may wonder about this strange order but this is the way in which the data is physically stored in the flash memory. During recovery mode, mtd0
(the boot loader), mtd4
(the boot loader configuration) and on some devices mtd5
(device configuration) are ignored and the other parts of flash are overwritten with the data from your recovery image. In order to make a valid QNAP recovery image, you therefore have to put all mtd
partitions into one file in the order described above.
Making a recovery image of the QNAP backup
Before installing Debian, you should have made a backup of the QNAP firmware and have several mtdX
files. You can now make a recovery image out of the backup with this command:
cat mtd0 mtd4 mtd5 mtd1 mtd2 mtd3 > F_TS-419P_qnap
Making a recovery image from a running system
You can easily make a valid recovery image with the following command:
cat /dev/mtdblock0 /dev/mtdblock4 /dev/mtdblock5 /dev/mtdblock1 /dev/mtdblock2 /dev/mtdblock3 > F_TS-419P_debian
It is recommended to create periodic recovery images of your flash, so you have a recovery image in case something goes wrong.
Making a recovery image containing the Debian installer
If you want to make a QNAP recovery image containing the Debian installer, you can follow these steps. First of all, download the <a href = "http://ftp.uk.debian.org/debian/dists/stable/main/installer-armel/current/images/kirkwood/network-console/qnap/ts-41x/initrd.gz">initrd</a> and <a href = "http://ftp.uk.debian.org/debian/dists/stable/main/installer-armel/current/images/kirkwood/network-console/qnap/ts-41x/kernel">kernel</a> for the installer. You now have to pad the kernel so it is the right size and create an empty file 2 MB in size:
dd if=kernel of=kernel.pad ibs=2097152 conv=sync
Finally, you can create a recovery image:
cat mtd0 mtd4 mtd5 kernel.pad initrd.gz mtd3 > F_TS-419P_di
Note that the mtdX
files in this command refer to the backup you created earlier (before the installation).
Using the recovery mode
In case your Debian system no longer boots after a system upgrade, you can use the QNAP system recovery mode to restore a previous image, an image of the Debian installer, or the QNAP firmware.
The recovery mode will first request an IP address via DHCP and then request a recovery image by TFTP from a server on your network. You have to configure your DHCP server so it will request the right file from the right machine. In particular, you have to create an entry for your QNAP that specifies filename
and next-server
. The latter refers to the IP address of your TFTP server (likely the same as your DHCP server). The filename
of the recovery image has to start with a specific string depending on your machine (otherwise the machine won't load the image!).
You can check the following table to find out which string to use:
Device |
String |
---|---|
TS-410 |
|
TS-412 |
|
TS-410U |
|
TS-419P |
|
TS-419P+ |
|
TS-419P II |
|
TS-419U |
|
TS-419U+ |
|
TS-419U II |
|
TS-420 |
|
TS-421 |
|
One some devices (but not on the TS-419P+), you can check the backup you made of the flash to find out what the right string is for your machine:
strings mtd4 | grep bootp_vendor_class
Please note that by default the MAC address used by your QNAP device in the recovery mode is different to the one used while running the QNAP firmware. When you install Debian, a script is run to ensure that the same MAC address is used everywhere. Therefore, depending on whether you ran that script, the MAC address will either be that from the QNAP firmware (the one printed on your device; it probably starts with 00:08:9B
) or an address starting with 00:50:43
. You can run the recovery mode and then look for DHCPDISCOVER
messages in /var/log/syslog
to find out the correct MAC address.
Once you have the right MAC address, you can configure your DHCP server. I used the following entry in /etc/dhcp3/dhcpd.conf
:
host ts419p { hardware ethernet 00:50:43:3c:3b:5d; filename "F_TS-419P_debian"; fixed-address 192.168.1.71; next-server 192.168.1.2; }
Reload your DHCP server so the configuration change will take effect.
You can activate the recovery mode by pressing the reset button on the back of your QNAP for about 10 seconds. I suggest you press the reset button and keep it pressed, and then turn on your QNAP device. After about 10 seconds, you will hear two short beeps. Your QNAP will now request a recovery image via TFTP. When it has obtained the recovery image and written it to flash (which takes about 3.5 minutes), your QNAP will make two short beeps again and restart.