• Increase font size
  • Default font size
  • Decrease font size
No one can make you feel inferior without your consent.
Home Geek stuff Synology Chroot Debian on Synology with debootstrap

Chroot Debian on Synology with debootstrap

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/ << 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/
~$ /usr/local/etc/rc.d/
~$ chroot /volume1/synodebian /bin/bash

Finalize install with debootstrap, and upgrade packages

~$ /debootstrap/debootstrap --second-stage
~$ cat > /etc/apt/sources.list << EOF
~$ deb wheezy main contrib non-free
~$ deb-src wheezy main contrib non-free
~$ deb wheezy/updates main contrib non-free
~$ deb-src 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/ << EOF
~$ # Start some services
~$ chroot \$CHROOT /etc/init.d/rsyslog start
~$ chroot \$CHROOT /etc/init.d/ start
~$ EOF
~$ chmod 755 /usr/local/etc/rc.d/

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


Add New Search
Laurent   | |2014-06-13 05:04:30
Super ! Merci beaucoup pour ce tutoriel !
Allan Hansen  - Fantastic guide!!   | |2014-07-16 21:12:16

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.

neo73   | |2014-08-24 17:38:20
Thank you, I just fixed this.
Erik Johansson   | |2014-09-06 18:36:05
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?


Gaetan Bouquet   | |2014-11-14 21:44:48

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.
matu   | |2014-12-29 22:55:14
thank you for the cat trick ^^
pocket  - Add service   | |2015-02-12 16:18:10
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

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

neo73   | |2015-02-25 08:30:34

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/ as suggested in the very last
part of the post.

Should you have a script
/volume1/synodebian/usr/local/bin/, you can run it at boot by
~$ cat >> /usr/syno/etc/rc.d/ << EOF
~$ chroot
\$CHROOT /usr/local/bin/
~$ EOF
(there is no line break on the
chroot line)
Write comment
[b] [i] [u] [url] [quote] [code] [img] 
Please input the anti-spam code that you can read in the image.

3.26 Copyright (C) 2008 / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."