Debian Chroot - SynoCommunity/spksrc GitHub Wiki

Intro

Debian is a free operating system (OS) that comes with over 29000 packages, precompiled software bundled up in a nice format for easy installation on your DiskStation. Debian Chroot allows you to benefit from the Debian OS inside your DiskStation, alongside DSM. This package is intended for advanced users only.

Installation

Once the installation finished in the Package Center, it continues in the background and you can see its status to Installing under Overview in the left pane. The installation finished, the status will automatically change to Installed.

In the same pane, you can monitor how many services are running and perform update operations.

Usage

As soon as the status is Installed, you can start using the chroot. To do so, connect to the DiskStation through SSH (root user) and use the following command: /var/packages/debian-chroot/scripts/start-stop-status chroot.

On the first use (after several minutes, for things to install), it is recommended to perform some configuration operations:

  • Update: type apt-get update followed by apt-get upgrade
  • Locales: type apt-get install locales and then dpkg-reconfigure locales
  • Timezone: execute dpkg-reconfigure tzdata

Configure Services

Debian Chroot allows you to manage the packages you installed in the chroot directly from DSM.

Under Services in the left pane, you can manage services that you manually installed previously in the chroot: start and stop them easily.

Configuration

  • Manually install in the chroot the service you chose
  • Configure it by editing the correct configuration files
  • In the interface, click on Add and fill the form. The launch script will be launched with the start argument to start the service and stop to stop it. The status command shall return 0 exit code if the service is started or 1 if it is stopped.

Example: SSH Server

  • Install the SSH server: apt-get install ssh
  • Edit the configuration file: /etc/ssh/sshd_config in order to change the port number and other things if necessary
  • Click on Add and put the name SSHD, the launch script /etc/init.d/ssh and the status command ps -p $(cat /var/run/sshd.pid)

Manual Example: SSH Server

The GUI of the chroot app is broken in DSM6. We would have to work around it at the moment. Services init information is stored in a SQLite database. Consult a SQLite FAQ on how to query, insert, update and delete rows of data in a table of such a database.

You would need to satisfy dependencies first. If your service needs others running – like syslog, for instance – start these beforehand. Compare to a native Debian installation, if possible.

  • SSH into as admin on Synology
  • sudo sqlite3 /volume1/@appstore/debian-chroot/var/debian-chroot.db
  • Create the SSH Server entry with: INSERT INTO services VALUES ('0', 'SSHD', '/etc/init.d/ssh','ps -p $(cat /var/run/sshd.pid)');
  • Verify with: SELECT * FROM services;

[** rmarabini note: for me the right insert comand was:

INSERT INTO services VALUES ('0', 'SSHD', '/etc/init.d/ssh start','ps -p $(ps aux | grep -e /usr/sbin/sshd | grep -v grep | tr -s " " | cut -d " " -f2)');

]

[** snaunton note: regarding rmarabini note above, an easy way of returning an exit code of 0 for a running or 1 for a non-running process is just to use:

ps aux | grep /path/to/binary | grep -v grep

Note that this will pick up processes running outside of the chroot as well, so if there is a /path/to/binary on the NAS as well as the chroot then this method will not be accurate, so you may need to do something like, for example, use a fairly innocuous command line parameter so you can differentiate the chroot process from the NAS one, e.g.

ps aux | grep "/path/to/binary -log-file /var/log/binary.log" | grep -v grep

The third parameter should also be command which accepts one parameter with the value of "stop" or "start".

For the sshd example:

INSERT INTO services VALUES ('0', 'SSHD', '/etc/init.d/ssh','ps aux | grep /usr/sbin/sshd | grep -v grep');

]

Proceed likewise with additional services to start. Don’t forget to raise the row ID (0 in the example above) for each entry. Double check the status command; if it does not return an exit code of 0 for a running service or 1 for a stopped service, the chroot app WILL hang. To verify services, stop and start the chroot app via the Synology Package Center.