How to configure, compile and install a new kernel

Questions that don't fit in any category below may go here
Forum rules
Please note the disclaimer before modifying your Synology Product.
Posts: 27
Joined: Sun Apr 25, 2010 10:16 am
Location: Sweden, Landskrona

How to configure, compile and install a new kernel

Postby nielsterp » Sat Dec 24, 2011 10:27 pm

There have been several attempts to compile and install a new kernel on a DS, but so far allmost everybody has run into trouble when they tried to install the new kernel.

Now, thanks to a lot of help from 'Atomic', I can show you how to do it. But before I do that, I have to give you this

:shock: WARNING :shock:

This procedure will certainly void your warrenty, and it potentialy has the ability to totally wreck your diskstation. Therefore, neither I nor Synology will assume any responsibility for consequences and / or losses following from this procedure.

That being said, I firmly believe that the procedure is safe, mainly because we are not going to tamper with the original instalation procedure. Instead, we are going to tweak a few files "inside" the firmware file from Synology. You will soon enough see how the installer protects the diskstation from any "dangerous" files. Just one very small mistake, and the installer will abort with a error message. In this context it means "Go back to square one and start over !".


Se the edit at the bottom of this post - you CAN get into serious trouble by doing a small mistake in this procedure !

No matter how safe the procedure might be, it is still absolutely mandatory to make a full backup of all your data and settings !!!

If you happen to have two or more unused SATA-disks, it is even better to substitute your normal disks with these, then, and only then, your data will be completely safe !

What you are going to need:

A working linux installation, including gcc and ncurses-devel. When I wrote this guide, I used a SuSE, which you can download here: You can install this on top of your Windows (with Virtualbox,, you can make a dual-boot installation, or install it on a seperate machine.

When your Linux is running, install the toolchain as described in "3rd Party Apps Developer Guide, ... ntegration. Be sure to install it in the right directory, /usr/local.

You need to set a number of environment variables, I find it most easy simply to make a user solely for cross-compiling, and set the variables in the users .config file. When logged in as that user, even if you su to "become" root, your environment variables will be there for you. And you can still log in as another user to do e.g. normal C-compiling, where these variables would just be in the way.

Here is what my .config file look like:

Code: Select all

# To make use of this feature, simply uncomment one of the lines below or
# add your own one (see /usr/share/locale/locale.alias for more codes)

# Most applications support several languages for their output.
# This overwrites the system default set in /etc/sysconfig/language
# in the variable RC_LANG.
#export LANG=de_DE.UTF-8        # uncomment this line for German output
#export LANG=fr_FR.UTF-8        # uncomment this line for French output
#export LANG=es_ES.UTF-8        # uncomment this line for Spanish output

# Some people don't like fortune. If you uncomment the following lines,
# you will have a fortune each time you log in ;-)

#if [ -x /usr/bin/fortune ] ; then
#    echo
#    /usr/bin/fortune
#    echo

# Set up environment for cross-compiling

export CC
export LD
export RANLIB
export CFLAGS
export LDFLAGS

".profile" 42L, 1440C                                         42,0-1        Bot

Type in the small test applikation sysinfo.c and the Makefile, these should work flawless before you continue. They are in the "3rd Party Apps Developer Guide".

Now you can download and decompress the Synology NAS GPL source from ... %20Source/. I have a DS207+ with a ARM 88f5281 processor, so I downloaded the file synogpl-1628-5281.tbz from the 1594branch.

Now your Linux-installation is ready, and we can turn our attention to Windows for a minute.

You will need a utility to find the CRC32-checksum for a file. I found a very compact (and free) application at

You will also need a binary editor, a so-called "Hex Editor". At you can download a free version of "Hex Editor NEO", it even has an option for a free period with all options enabled. Highly recommended !

Finaly you will need an editor for Windows, that actualy only writes what you are typing in. Wordpad is saving some control codes, that will mess up everything, and even Notepad can sometimes shred a file (and it places everything on one single line, making it very difficult to use). I found "VI for Windows" which can be freely downloaded from

Finaly you need some means of calculating or converting from decimal to hexadecimal and back. I have an old TI-68, which was a "special edition" for programmers, but even Windows itself have a calculator which can do the trick.

Now our toolbox is complete, and we can move on.

Compiling your first kernel

Log into Linux as your cross-compile user, goto the linux directory that fits your DS. Here you will find a file with configuration for your processor. Mine is 88f5281-config, and you simply copy it to .config. If you don't find the file, you are probably in the wrong directory, or you have downloaded the wrong sources.

At least in my version, you have to make a small modifikation to the Makefile: Line 454 reads:

Code: Select all

config %config: scripts_basic outputmakefile FORCE

For some reason, the compiler doesn't like this construction. Remove the first 'config', so that line 454 reads:

Code: Select all

%config: scripts_basic outputmakefile FORCE

Then type (NOTE: The following can look a little strange, because of the spacing. Just copy the full text)

Code: Select all

make ARCH=arm CROSS_COMPILE=/usr/local/arm-marvell-linux-gnu/bin/arm-marvell-linux-gnu- oldconfig

and then

Code: Select all

make ARCH=arm CROSS_COMPILE=/usr/local/arm-marvell-linux-gnu/bin/arm-marvell-linux-gnu- menuconfig

You will get a menu where you can configure your kernel. If you have no idea how to do this, search for a tutorial on the net, it is outside the scope of this guide.

When you are happy with your configuration, go back with <ESC>, and save your configuration when prompted. Then

Code: Select all

make ARCH=arm CROSS_COMPILE=/usr/local/arm-marvell-linux-gnu/bin/arm-marvell-linux-gnu- modules


Code: Select all

make ARCH=arm CROSS_COMPILE=/usr/local/arm-marvell-linux-gnu/bin/arm-marvell-linux-gnu- zImage

If you just want the kernel, you can skip the modules build. However, due to the limited size of a zImage, it may be better to generate the modules, rather than including everything in the kernel.

Now your new kernel is compiled, and it is time to sneak it into your DS. The kernel modules can simply be copied to /lib/modules, but zImage requires "special treatment" because it is not saved on the disk, but rather in flash memory.

And now to the Holy Grail

While you are still in Linux, download the latest firmware from Synology to an empty folder, open a terminal window, and unpack it:

Code: Select all

tar xvf <DSM(whatever your version is named)> .

You wil see, that one of the files are named zImage. Delete that file, and replace it with the one you created when compiling the kernel (it is located in <linuxdirectory>/arch/arm/boot).

Go into Windows, and use VI for Windows to open the "checksum" file.

The Anatomy of a Synology .pat-file

Here is what my .pat file is made up of:

Code: Select all


zImage is the kernel (uncompressed format)
VERSION describes the version - don't change this for now.
updater is a binary file - it can not (succesfully) be changed without a disassembler.
rd same as above (probably holds the initial RAMdisk content).
hda1 is a tar-compressed file which contains the complete initial filesystem. It can, in theory, be uncompressed, modified, and recompressed. I have not tried this yet.

And then there is the checksum file, where all the fun takes place.

This is the contents of my original checksum-file (all values in this file is in decimal format):

Code: Select all

3003329323 141 VERSION 226 196
2695277617 154613558 hda1.tgz 258153803 754
3646717353 1450688 zImage 2534887 710
548234567 2187168 updater 4250119 331
78028648 827603 rd.bin 942446 688
#Synocksum 159079158 265881481 2679

The first group of digits is the decimal value of that files CRC32 checksum.
The second group of digits is the filesize in bytes.
The third column is the filename.
Next column is a random number between <filesize> and <(filesize*2) - 4> called "offset". The difference between this number and the <filesize> in bytes is a pointer to a adress inside the file. Find the value of the byte at that address, add it together with the value of the next three bytes, the sum of these four bytes - converted back to decimal - is the last number on the line.

The last line #Synochksum is the three last columns of digits added together.

Are you confused ? Well, it certainly took me a few minutes to figure out, even after being shown how to do it by 'Atomic'. But an example might help:

The latest firmware for DS207+ is DSM_DS207+_1636, and the checksum file looks as I showed above.

Then I recompile the kernel, ending up with a new zImage file. This files CRC32-checksum is 81827A4D hexadecimal, which we convert to decimal 2172811853. The filesize is 1495524 bytes, the file name is the same, the next number is still within the bounds, so we dont have to change this.

Now we calculate the offset as 2534887 - 1495524 = 1039363 decimal, which converts into FDC03 hexadecimal. Now right-click on the zImage file, and select "Edit with HHD Hex Editor Neo". Go to the address FDC03, and you wil find the four bytes as 48 - EE - 74 - EE. These four bytes add up to 298 hexadecimal, which converts into 664 decimal. And that is the last number on the line.

Now we just have to count together the second, third and fourth column of digits, and our checksum file looks like this:

Code: Select all

3003329323 141 VERSION 226 196
2695277617 154613558 hda1.tgz 258153803 754
2172811853 1495524 zImage 2534887 664
548234567 2187168 updater 4250119 331
78028648 827603 rd.bin 942446 688
#Synocksum 159123994 265881481 2633

Save the file, and go back to linux. Open a terminal window in the folder with your files, and type

Code: Select all

tar -cf <name-of-your-pat-file> *

After a few seconds your file is ready for installation. There is one little snag: Because the version can not be updated (it is hidden inside one of the binary files), and because you can only install a newer version than the one you have installed, you have to do a "hard reset" by pressing the reset-button at the backside of your DS, until it emits a beep. Then release and immediately pres the button again, until it emits three beeps.

Then you can install your file from the DSM Manager.


You should read this post: viewtopic.php?f=128&t=14130&start=15 . It explains how to mount and modify the rd.bin file. It also have a very helpful link to a small program that takes care of all the checksum calculation.

This post also describe in some detail how to change the version number. However ...


I have not been able to confirm that this is working - right now my DS does not want to talk to me at all, after I tried to install my latest patch. I will return with more information IF my DS becomes well again ...

Return to “General Mods”

Who is online

Users browsing this forum: No registered users and 2 guests