Thursday, April 16, 2015

Install Bash-Shell in favour of Ash-Shell on your Synology

Objective


I wanted to use the bash-shell on my Synology DS209+II. There are no official packages from Synology provided, but I knew there is a way to install custom and optional packages via ipkg.

Motivation


As my Synology is mostly running 24/7, I wanted establish a custom download-script which is started and stopped as a cron-job at certain periods of time. The script itself uses some commands relying on a bash-shell, but the Synology default command shell is just the less powerful ash-shell.


Prerequisites



Solution


Open a ssh-connection to your Synology


Log into your Synology as root using ssh (e.g "ssh -l root DiskStation").

Install the Bash-Shell-Package:

DiskStation$> ipkg install -A bash

You should see something like this:

DiskStation> ipkg install bash
Installing bash (3.2.54-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/syno-e500/cross/unstable/bash_3.2.54-1_powerpc.ipk
Installing readline (6.1-2) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/syno-e500/cross/unstable/readline_6.1-2_powerpc.ipk
Installing ncurses (5.7-3) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/syno-e500/cross/unstable/ncurses_5.7-3_powerpc.ipk
Configuring bash
Configuring ncurses
update-alternatives: Linking //opt/bin/clear to /opt/bin/ncurses-clear
Configuring readline
Successfully terminated.

Now, Bash-Shell is installed, but when you log into your Synology it's not yet automatically started. You are still with Ash-Shell.

Activate automatic log-in with Bash


You could exchange the shell type for log-in in your /etc/passwd on your Synology, by exchanging the line (here it's done for user: root):

root:x:0:0:root:/root:/bin/ash

by

root:x:0:0:root:/root:/bin/bash

Unfortunatelly doing so, has the disadvantage, that you might loose the ability to log into your Synology at all from remote after an upgrade of your Firmware. Because optional packages like Bash are installed into /opt may be inavailable after a system-update. To prevent this accidental lock-out, it's preferred to continue to log-in with Ash-Shell, but start Bash automatically at once after you're successfully logged in.

To achive this you have to create/edit the file .profile in the homeaccount of the user the should be able to log-in on your Synology. Go to your homeaccount (e.g. /root/ for the user: root) and type the following as the proper user on you Synology:

DiskStation$> vi .profile

If the file has content, just add this lines to it:

# ...

if [[ -x /opt/bin/bash ]]; then
    exec /opt/bin/bash
fi

That's it. Next time, when root logs into your Synology, he is on a Bash-Shell.

Refine Configuration


If you want to use a different command prompt or to have some alias-commands, or at least the proper shell name in your "SHELL" environment variable, it's advisable also to create a .bashrc in the homeaccount, with the following example content (feel free to alter it to your convenience):

DiskStation$> vi .bashrc

PS1='\u@\h:\w \$ '
export SHELL=/opt/bin/bash

The first line gives you a nice bash prompt. The second explicitly sets the "SHELL" variable to your correct shell.

If you want also other scripts automatically using Bash instead of Ash, additionally create a symbolic link to it in /bin/:

DiskStation$> ln -s /opt/bin/bash /bin/bash

ADVICE: Keep a separate root shell window open until you have confirmed all of the changes work.

Sunday, April 12, 2015

Prepare your Synology NAS to install custom packages via ipkg

Objective


I wanted to use the bash-shell and a newer wget on my Synology DS209+II. There are no official packages from Synology provided, but I knew there is a way to install custom and optional packages via ipkg. Unfortunatelly ipkg must be so called bootstrapped, because it is already a custom package itself.

Motivation


As my Synology is mostly running 24/7, I wanted establish a custom download-script which is started and stopped as a cron-job at certain periods of time. The script itself uses some commands relying on a bash-shell, but the Synology default command shell is just the less powerful ash-shell. Also some of the wget-options I use in that script seem to be broken in the version of wget that my Synology has installed.

Prerequisites


  • DS209+II
  • Proper bootstrap script for your Synology NAS

Solution


Download the proper boostrap script


First you have to find out which processor is used on your specific Synology NAS.

Log into your Synology as root using ssh (e.g "ssh -l root DiskStation") and type the following command:

DiskStation$> cat /proc/cpuinfo

Doing so on my DS209+II printed the following information:

processor : 0
cpu : e500v2
clock : 1066.560000MHz
revision : 2.2 (pvr 8021 0022)
bogomips : 133.32
timebase : 66660000
platform : MPC8544 DS
model : MPC8544DS
Vendor : Freescale Semiconductor
PVR : 0x80210022
SVR : 0x80340011
PLL setting : 0x4
Memory : 512 MB
Memory : 512 MB

Now I know I have a Freescale PowerPC (e500v*), I can download the proper boostrap script here:

You can find a list of all bootstrap scripts here (column: "Optware-Pfad/IPKG"):
Processors used in Synology NAS Systems (German)

Now download the proper script and copy it to your Synology.

On the (still open) ssh connection "cd" into the folder where you stored the script and type (script name for your Synology type may differ!):

DiskStation$> sh syno-e500-bootstrap_1.2-7_powerpc.xsh

After you hit enter and you see something like this:

Optware Bootstrap for syno-e500.
Extracting archive... please wait
bootstrap/
bootstrap/bootstrap.sh
bootstrap/ipkg-opt.ipk
bootstrap/ipkg.sh
bootstrap/optware-bootstrap.ipk
bootstrap/wget.ipk
1330+1 records in
1330+1 records out

you already have installed an older version of ipkg.

Now you first have to remove this version, before installing the new one.

Backup your old ipkg configuration (only if you already have ipkg on your system)


If you have already installed ipkg and other custom packages via ipkg then make a backup of the following folders on you Synology:

  • /volume1/@optware
  • /usr/lib/ipkg

then remove all existing optware packages:

DiskStation$> rm -rf /volume1/@optware && rm -rf /usr/lib/ipkg

Afterwards, you must *reboot your Synology* and then restart the bootstrap script.

Re-Install ipkg


Again, log-into your Synology via ssh as root and type:

DiskStation$> sh syno-e500-bootstrap_1.2-7_powerpc.xsh

Now you should see a full install log:

Optware Bootstrap for syno-e500.
Extracting archive... please wait
bootstrap/
bootstrap/bootstrap.sh
bootstrap/ipkg-opt.ipk
bootstrap/ipkg.sh
bootstrap/optware-bootstrap.ipk
bootstrap/wget.ipk
1330+1 records in
1330+1 records out
Creating temporary ipkg repository...
Installing optware-bootstrap package...
Unpacking optware-bootstrap.ipk...Done.
Configuring optware-bootstrap.ipk...Setting up ipkg arch-file
Done.
Installing ipkg...
Unpacking ipkg-opt.ipk...Done.
Configuring ipkg-opt.ipk...WARNING: can't open config file: /usr/syno/ssl/openssl.cnf
Done.
Removing temporary ipkg repository...
Installing wget...
Installing wget (1.12-2) to root...
Configuring wget
Successfully terminated.
Creating /opt/etc/ipkg/cross-feed.conf...
Setup complete.

Update your $PATH variable, so that the ipkg can be found after reboot.
Therefore open the file $HOME/.profile and edit the line with your PATH:

PATH=/opt/bin:/opt/sbin:[the content that was already there]

Finally it's recommended to update your ipkg-package to ensure to use the newest version:

DiskStation$> ipkg update

Downloading http://ipkg.nslu2-linux.org/feeds/optware/syno-e500/cross/unstable/Packages.gz
Inflating http://ipkg.nslu2-linux.org/feeds/optware/syno-e500/cross/unstable/Packages.gz
Updated list of available packages in /opt/lib/ipkg/lists/cross
Successfully terminated.

If you use "ipkg upgrade" instead of "ipkg update", also all already installed custom packages are upgraded, too.

Boostrap done. Now you can install optional packages via the ipkg command on your Synology.

References:

  1. https://www.naschenweng.info/2012/01/17/synology-dsm-4-0-beta-breaks-ipkg/