Synology DS107

From Gentoo-en
Jump to: navigation, search
Fix me:
  • This article appears to be out of date - it refers to profiles and package versions no longer available in the main tree.

This tutorial was written in September 2007. It describes how to install a chrooted Gentoo on the Synology DS-107 NAS so that we will not break anything.

Firmware version : 0514.

In this procedure, we use the following settings :

  • mount point on linux host : public
  • nas hostname : nas
  • chrooted gentoo root directory on nas : /volume1/public/gentoo

Warning : with this procedure, nas startup time becomes longer because of quota checks. Do not turn off the nas during startup or you might need to reformat the hdd.

This method uses 2006.1 stage (2005.0 stage does not work).

Steps to chroot

Connect to the nas with root credentials. Use Enable ssh patch from synology. Get stage3 archive on your favourite mirror (current ppc32 stages on Turn of any p2p to fill bandwith.

Also get last portage version :

Uncompress archive :

mkdir gentoo cd gentoo tar xjpf ../stage*bz2

We also install portage :

tar xjf ../portage-latest.tar.bz2 -C /volume1/public/gentoo/usr/

Get some info from base system :

cp -L /etc/hosts /volume1/public/gentoo/etc/hosts cp -L /etc/resolv.conf /volume1/public/gentoo/etc/resolv.conf mount -t proc none /volume1/public/gentoo/proc mount -o bind /dev /volume1/public/gentoo/dev

Chroot in the new gentoo environment :

chroot /volume1/public/gentoo /bin/bash env-update source /etc/profile

Bonus : you can configure bashrc file.

cd cp /etc/skel/.bashrc . source .bashrc

Fix and Sync

Now we'd like to sync portage...

You can set your own local rsync server so that you will not abuse mirror and benefit from your local network bandwith. In this case, set your own local rsync mirror :

echo SYNC=\"rsync://\" >> /etc/make.conf
emerge --sync

... but sync fails because python is actually broken. We need to manually install python to fix it :

wget tar xjf Python-2.5.1.tar.bz2 cd Python-2.5.1 ./configure --prefix=/usr make make install

When python is fine, we can use portage. The following commands will emerge portage and almost fix python :

echo "~dev-lang/python-2.5.1-r3 ~x86" >> /etc/portage/package.keywords emerge -va python

pycrypto is broken :

  File "/usr/lib/portage/pym/", line 59, in <module>
    md5hash = _generate_hash_function("MD5",, origin="pycrypto")
AttributeError: 'module' object has no attribute 'new'

... and portage relies on it. So we remove it, the hard way :

cd /usr/lib/python2.5/site-packages rm -rf Crypto pycrypto-2.0.1-py2.5.egg-info emerge --unmerge pycrypto

Sync should now work.

Enjoy !

You can now add new services to your NAS.


Basic configuration

Emerge and generate keys (this is usually done in the init.d script, but I am not able to launch it because of the chrooted environment) :

emerge -av openssh /usr/bin/ssh-keygen -t rsa1 -b 1024 -f /etc/ssh/ssh_host_key -N '' /usr/bin/ssh-keygen -d -f /etc/ssh/ssh_host_dsa_key -N '' /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''

Fix ssh user updating /etc/passwd :

File: /etc/passwd
File: /etc/ssh/sshd_config
Port 5022
Protocol 2
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no
Subsystem  sftp /usr/lib/misc/sftp-server

You might need to fix /var/empty owner :

chown root:root /var/empty

Mount /dev/pts :

mount -t devpts devpts /dev/pts

The -4 (ipv4) option is compulsory to avoid the "all ports in use effect".

/usr/sbin/sshd -o PidFile=/var/run/ -f /etc/ssh/sshd_config -4

You can analyze problems adding the -Ded :) options.

On client :

ssh-keygen -t rsa

On the nas in /root/.ssh/authorized_keys (copy the line from .ssh/ :

File: .ssh/
ssh-rsa key_with_many_alpha_numeric_characters root@client

And finally :

ssh nas -p 5022

Improving ssh service

We need to fix sshd service dependencies : logger and dns. app-admin/syslog-ng will provide logger. We fake app-admin/syslog-ng dependencies creating symlinks in /var/lib/init.d/started/.

emerge -va syslog-ng ln -s /etc/init.d/clock /var/lib/init.d/started/clock ln -s /etc/init.d/hostname /var/lib/init.d/started/hostname ln -s /etc/init.d/localmount /var/lib/init.d/started/localmount mount -t proc proc /proc /etc/init.d/syslog-ng start

We fake net service status :

ln -s /etc/init.d/net.lo /var/lib/init.d/started/net.lo ln -s /etc/init.d/net.eth0 /var/lib/init.d/started/net.eth0

It is now seen as running :

nas ~ # /etc/init.d/net.eth0 status
 * status:  started

Start sshd service as usual :

nas ~ # /etc/init.d/sshd start
 * Starting sshd ...                                                      [ ok ]


You can configure your nas to update French network weather data with grenouille.

wget tar xzf camlgrenouille-1.28.tar.gz cd camlgrenouille-1.28 emerge -va dev-lang/ocaml touch build_linux make depend make cd .. wget tar xzf camlgrenouille-bin-linux-1.28.tar.gz cp camlgrenouille-bin-linux-1.28/user.config camlgrenouille-1.28

And just update user.config with username and password.

Install ping :

emerge -va iputils

Mount proc if needed :

mount -t proc proc /proc


Other usefull Gentoo packages :

emerge -va gentoolkit emerge -va vim emerge -va screen

linux backup with rsync

We mount volume1 in the root of the chroot system. Run under base system :

mkdir /volume1/public/gentoo/volume1 echo "mount --bind /volume1 /volume1/public/gentoo/volume1" >> /etc/rc.local chmod 777 /etc/rc.local
File: /etc/rsyncd.conf
# /etc/rsyncd.conf

# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help

# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/
use chroot = yes
read only = yes

# Simple example for enabling your own local rsync server
#       path = /usr/portage
#       comment = Gentoo Portage tree
#       exclude = /distfiles /packages

uid = nobody
gid = nobody
hosts allow=
hosts deny=*
pid file = /var/run/
motd file = /etc/rsyncd.motd
log file = /var/log/rsync.log
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300

   path = /volume1/public/DED/linux
   comment = root backup
   read only = false
   uid = root
   gid = root
/etc/init.d/rsyncd start

If you want to backup /etc to the nas :

rsync -az --delete /root /etc nas::root-backup

You can configure backuping for other users :

  • Create accounts on the NAS
  • Update rsyncd.conf
  • Allow ssh connection
  • Configure rsync client (exclusions, etc.)

Important note : it seems that the kernel has been patched so that the file system is not aware of case : it is not possible to have two different files with their names only different in case. This may be a problem because afterwards it becomes really hard to remove the files (see Tips)

automatic startup

Add the following lines to /etc/fstab

File: /etc/fstab
none  /proc     proc    defaults  0 0
none  /dev/pts  devpts  defaults  0 0

Fake runlevel :

echo default > /var/lib/init.d/softlevel

Fake rc-update data :

ln -s /etc/init.d/net.eth0 /etc/runlevels/default/

Add some services to current runlevel :

rc-update add sshd default rc-update add rsyncd default rc-update add syslog-ng default

List status of all services :

root@nas ~ # rc-status -a  
Runlevel: boot
 keymaps                                                            [ started  ]
 clock                                                              [ started  ]
 urandom                                                            [ stopped  ]
 hostname                                                           [ started  ]
 net.lo                                                             [ started  ]
 localmount                                                         [ started  ]
 modules                                                            [ started  ]
 checkfs                                                            [ stopped  ]
 consolefont                                                        [ stopped  ]
 rmnologin                                                          [ stopped  ]
 bootmisc                                                           [ started  ]
 checkroot                                                          [ started  ]
Runlevel: default
 local                                                              [ started  ]
 net.eth0                                                           [ started  ]
 sshd                                                               [ stopped  ]
 netmount                                                           [ started  ]
Runlevel: nonetwork
 local                                                              [ started  ]
Runlevel: single
 crypto-loop                                                        [ stopped  ]
 dropbear                                                           [ stopped  ]
 numlock                                                            [ stopped  ]
 rsyncd                                                             [ stopped  ]
 syslog-ng                                                          [ stopped  ]

There may be some differences with your rc-status report as I have manually started some services...

We need to fix status of all services from boot level. Only these two ones are really needed :

ln -s /etc/init.d/checkfs /var/lib/init.d/started/checkfs ln -s /etc/init.d/consolefont /var/lib/init.d/started/consolefont

It is now possible to start all services :


We will use the rc script to start everything. proc will not be automatically mounted. So we will use the following scripts :

File: /root/start
rm /var/lib/init.d/started/sshd                                                 
rm /var/lib/init.d/started/rsyncd                                               
rm /var/lib/init.d/started/local                                                
umount /proc                                                                    
umount /dev/pts                                                                 
mount|grep proc>>/dev/null || mount /proc                                       
mount|grep pts>/dev/null || mount /dev/pts                                      
/sbin/runscript /sbin/rc>/var/log/init.log 2>&1
screen -d -m -S frog /root/camlgrenouille-1.28/camlgrenouille.command

It does not work if I run /sbin/rc. I need to explicitely call runner (/sbin/runscript) and I also need to redirect output ! I do not have time to fix this now...

I need to unmount /proc and /dev/pts before because I have not searched yet for a better way to either clean mount table or safely unmounting before reboot.

File: /root/stop
/etc/init.d/rsyncd stop
/etc/init.d/sshd stop  
/etc/init.d/syslog-ng stop
killall camlgrenouille                            
umount /proc          
umount /dev/pts
chmod 700 ~/start chmod 700 ~/stop

And finally, on base system, add the following startup script :

File: /usr/syno/etc.defaults/rc.d/
if [ "$1" = "restart" ]; then
        $0 stop
        sleep 1
        $0 start

if [ "$1" = "start" ]; then
        chroot /volume1/public/gentoo /root/start

if [ "$1" = "stop" ]; then
        chroot /volume1/public/gentoo /root/stop
chmod 755 /usr/syno/etc.defaults/rc.d/

Telnet is not needed anymore : upload the DisableTelnet.pat firmware to your nas. YES !


  • Upgraded successfully to firmware 0590, 0600 and 0728. Intermediary patches updates were not tested. You will need to create the startup script again.


File Input/Output Error

  • Synology filesystem cannot handle two files in the same directory if they only differ in case :
    • ls returns input/output errors in this folder.
    • You are unable to remove any of the files.
  • Solution :
    • Move extra files to another folder.
    • Remove the folder with rm -rf.