Bash on Synology DiskStation

I picked up a Synology DS415play, a couple weeks ago. I’ve been looking for a good way to store family memories, as well as have device-indepentet on-site storage and redundancy.

The Synology DiskStation is a Linux-based NAS, and I couldn’t stand that the default shell was ash. How to fix?

Process

I’m taking a lot from this post on the Synology forums, and trying to explain it in a litte more detail[1].

Finding the bootstrap file for the Intel Atom CE5335 was a bit of a challenge, since Synology doesn’t use it as widely used as some other CPUs in their lineup. Fortunately the thread I linked above has a relatively recent (Nov 2014) bootstrap for a DS214play, which uses the same CPU. I guessed it would be the same, and it was.

I’m going to assume that if you’re reading this, you are thinking of doing the same on your DiskStation, and that you have an ill-defined-but-higher-than-zero knowledge of both *nix systems and how to Google.

First, you’ll need to ssh into the NAS as root (root’s password is the same as the admin user password).

You’ll need to execute the following commands, command by command:

$ cd /volume1/@tmp  
$ wget http://ipkg.nslu2-linux.org/feeds/optware/syno-i686/cross/unstable/syno-i686-bootstrap_1.2-7_i686.xsh  
$ chmod +x syno-i686-bootstrap_1.2-7_i686.xsh  
$ sh syno-i686-bootstrap_1.2-7_i686.xsh  
$ rm syno-i686-bootstrap_1.2-7_i686.xsh

Line by line, the above does the following:

  1. Change into the Synology’s temp directory
  2. Download the bootstrap script
  3. Make the script executable
  4. Run the script
  5. Remove the script

At this point you have ipkg, the package manager, installed, but your shell doesn’t know about the folder it’s installed in. You’ll need to add /opt/bin/ and /opt/sbin/ to the PATH[2] in your .profile.

While you’re in your .profile, you might see a line that says HOME=/root/. I changed mine to HOME=~/, since I want this .profile to be portable between users. I’ve copied it to the admin user when I finished, so I have the same experience when I’ve connected as admin and root.

Now, if you type ipk and hit [tab] it should autocomplete to ipkg.

So, let’s install bash:

$ ipkg install bash`

Bam. You’ll get some output, then you should have bash installed.

Now, I needed conventions for getting into bash when I connect to the device. Again, the Synology forums came to the rescue.

Add the following to the end of your .profile:

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

The above checks if /opt/bin/bash is executable. If it is, the command will execute /opt/bin/bash. If it is not, it doesn’t execute /opt/bin/bash, therefore leaving you in ash.

Add the following to .bashrc:

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

The top line you may want to adjust to your taste. That’s how I like my prompt to look. Here’s a good tool to help you build the prompt that suits you.

The second line sets the SHELL variable to /opt/bin/bash. Remember that .bashrc is only read by bash when bash is started, so the SHELL only gets set if bash is called.

Now before you close your current SSH session, start a second. You should get your new, fancy bash prompt. Success!

Once you have that good feeling, copy .profile and .bashrc to /volume1/homes/admin/, and start another ssh session, this time connecting as admin. If that works, you’re set.


  1. I find that if I start a project like this by thinking about (and sometimes outlining) a post like this as I go, I have a better understanding of what I’m doing. Often, if I can’t follow the thread from beginning to the end, I don’t actually begin the project because I feel like I don’t understand the process well enough.  ↩

  2. Here’s an explanation of the PATH variable in UNIX, if you’re not familiar.  ↩