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.

2 comments:

  1. Great post
    Our dsm is outdated, since synology decided to stop the updates.
    Do you think it is possible to install a fresh distro onto the ds209+II, or at last, upgrade the php server and mysql?

    ReplyDelete
    Replies
    1. Hello Marco, I also got stuck with updating my DS209+II at DSM 4.2. AFAIK there are php packages installable at least for upgrade to version 5.2 of php via ipkg (try "/opt/bin/ipkg list | grep php" on a ssh shell on your NAS). There are also some mysql packages listed, but I don't use either php or mysql, so I don't know if you need even newer versions. It is also possible to install a compiler toolchain on the synology AFAIK (or to cross-compile on another faster computer) the packages yourself.

      I never searched or tried to install an alternative OS on the synology, but I am pretty sure that it's possible to build your own Linux Distro (e.g. with Linux from Scratch) that might work. But in my opinion, it's not worth the effort.

      Btw. minor updates seem still to be available for the DS209+II.

      Delete