I recently purchased a Synology DS213j. This NAS comes with various applications and services; it can be extended by 3rd party packages. However the Synology distribution uses its own package system and I'm not ready to invest time to package and maintain software for Synology. Instead I choosed to chroot a Debian distro on this ARM-based Synology DiskStation NAS using debootstrap.

Creating base system

Debootstrap is a tool that help installing a Debian system in another system's subfolder. First step is to find which architecture you must use. The DS213j NAS has a MARVELL Armada 370 which is an ARMv7 CPU. For other models, please check What_kind_of_CPU_does_my_NAS_have. Debian officially supports 2 ARM architectures, armel and armhf. Armhf has hardware floating point support which can be used on CPUs like ARMv7.

From computer, let's create a base debian system on armhf architecture using stable version:

~$ apt-get install debootstrap
~$ mkdir synodebian
~$ sudo debootstrap --foreign --arch armhf wheezy synodebian

Once done, send the package to the Synology NAS

~$ sudo tar cvzpf synodebian.tar.gz synodebian
~$ scp synodebian.tar.gz root@mysynologyhostname:/volume1/

Deploying on NAS

Now connect to NAS and extract archive into the first volume:

~$ cd /volume1/
~$ tar xvzpf synodebian.tar.gz

Next step is to mount required partitions to have a working Debian system after being chrooted, plus setting up basic configuration. These actions will have to be performed after every reboot of the NAS, so let's put it into a startup script:

~$ cat > /usr/local/etc/rc.d/S99chrootDebian.sh << EOF
~$ CHROOT=/volume1/synodebian
~$ mount -o bind /dev \$CHROOT/dev
~$ mount -o bind /proc \$CHROOT/proc
~$ mount -o bind /dev/pts \$CHROOT/dev/pts
~$ mount -o bind /sys \$CHROOT/sys
~$ cp /etc/resolv.conf \$CHROOT/etc/resolv.conf
~$ cp /etc/hosts \$CHROOT/etc/hosts
~$ EOF

Set proper permissions, launch script and chroot a bash shell from where we'll be able to finalize our installation.

~$ chmod 755 /usr/local/etc/rc.d/S99chrootDebian.sh
~$ /usr/local/etc/rc.d/S99chrootDebian.sh
~$ chroot /volume1/synodebian /bin/bash

Finalize install with debootstrap, and upgrade packages

~$ /debootstrap/debootstrap --second-stage
~$ cat > /etc/apt/sources.list << EOF
~$ deb http://ftp.fr.debian.org/debian/ wheezy main contrib non-free
~$ deb-src http://ftp.fr.debian.org/debian/ wheezy main contrib non-free
~$
~$ deb http://security.debian.org/ wheezy/updates main contrib non-free
~$ deb-src http://security.debian.org/ wheezy/updates main contrib non-free
~$ EOF
~$
~$ aptitude update
~$ aptitude upgrade

The Debian system is now ready to use, now exit the chroot and add some services to automatically run at system startup. Please note since Debian is not responsible for boot sequence, scripts in /etc/init.d won't be executed automatically.

~$ cat >> /usr/local/etc/rc.d/S99chrootDebian.sh << EOF
~$ # Start some services
~$ chroot \$CHROOT /etc/init.d/rsyslog start
~$ chroot \$CHROOT /etc/init.d/mtab.sh start
~$ EOF
~$
~$ chmod 755 /usr/local/etc/rc.d/S99chrootDebian.sh

That's it! When installing new services on your Debian, just update the S99chrootDebian.sh script.

Source: http://pellelatarte.fr/2011/06/nas-synology-debian-en-chroot-apache-et-mysql/

Comments   

# Laurent 2014-06-13 05:04
Super ! Merci beaucoup pour ce tutoriel !
Reply
# Fantastic guide!!Allan Hansen 2014-07-16 21:12
Hello!

Thank you so much for this guide! As a unix noob this helped me ALOT! Minor thing, the command "tar xvzfp synodebian.tar.gz" failed, because the f parameter should be specified last, whenever present, eg xvzpf.

Kind Regards
Reply
# neo73 2014-08-24 17:38
Thank you, I just fixed this.
Reply
# Erik Johansson 2014-09-06 18:36
Hi and thanks for the guide. I have some truoble thou. On the part where you are suppose to chroot into debian: chroot /volume1/synodebian /bin/bash

When running this command, I get a segmentation fault error, and nothing more happens. Do you know how to fix this?

Thanks!

/E
Reply
# Gaetan Bouquet 2014-11-14 21:44
Hi,

Choosing the wrong architecture (armhf instead of armel) caused me the segmentation fault. Switching from armhf to armel fixed the problem. The link to the Synology processors doesn't give the information, so try both. For the record, I have a DS212j and needed to use the armel architecture, not armhf.
Reply
# matu 2014-12-29 22:55
thank you for the cat trick ^^
Reply
# Add servicepocket 2015-02-12 16:18
Quote:
The Debian system is now ready to use, now exit the crhroot and add some services to automatically run at system startup. Please note since Debian is not responsible for boot sequence, scripts in /etc/init.d won't be executed automatically.


any one can help me to put a service to boot wen i start my synology

the bin are in /volume1/synodebian/usr/local/bin and i have put the startup in /etc/rc.local but the service dont start

tanks
Reply
# neo73 2015-02-25 08:30
Hi,

Since Debian isn't responsible for boot sequence, you should place your scripts in the Synology /usr/syno/etc/rc.d/ folder.
Whenever you want to add some Debian services or custom scripts to your boot sequence, I recommend you add them to /usr/syno/etc/rc.d/S99chrootDebian.sh as suggested in the very last part of the post.

Should you have a script /volume1/synodebian/usr/local/bin/script.sh, you can run it at boot by adding:
~$ cat >> /usr/syno/etc/rc.d/S99chrootDebian.sh << EOF
~$ chroot \\$CHROOT /usr/local/bin/script.sh
~$ EOF
(there is no line break on the chroot line)
Reply