Tuesday, April 4, 2017

How to reboot Synology NAS from terminal when GUI is unresponsive

I own a Synology NAS (it's a Ds213j) that every now and then get unresponsive.
The web GUI doesn't works, the network share doesn't works.
But the NAS does still respond to ping, so the network is working.

When my NAS get unresponsive my first solution has always been to power-cycle it, by unplugging the power cable.
But this isn't very nice for a NAS, so I found another solution:  reboot the NAS from SSH terminal.

So here is a little guide about how to reboot the NAS via the SSH terminal.
This guide works on my Synology DS213j. On different model YMMV.

Disclaimer: with the instructions in this guide you can mess up your NAS, you can loose your data, and do a lot of bad things. So, be responsible of your actions, and do something only when you clearly uderstand the full consequence of your actions.
A NAS can contains a lot of data, and form a terminal console with administrative right is very easy to mess things up, lose data, or do bad things.


First thing: you need to enable SSH/Telnet access to your NAS.

Access the NAS GUI, click  "Control Panel", scroll to and click "Terminal & SNMP", Enalbe Telnet and SSH Services, Click Apply.
Important: Always use strong password for any account that can access your NAS.

Even more important: If your NAS is accessible from outside your LAN, take care about the security of any new service that you enable: are they going to be accessible form the internet? Do you need to protect the in some way? (firewall?)

Now you can access the terminal of your NAS. So, the next time you need to reboot your NAS you will be able to try to force a reboot by using the terminal.

How do you access the terminal of your NAS? There are many software that can do that, I use Putty, that is a free ssh/telnet client for windows. You can download Putty there.

After installing Putty, fire it up, and insert your NAS IP/host name.

 Click the "open" button, and this will take you there:
 
Now enter the username, and then the password.
The user must be part of the administrators group of your NAS.

Then You are logged in the terminal

Now you must type the command "sudo su", press enter, and then re-type the user password.
This will give your command prompt the administrative right.

Now we are ready to type the command that will reset/reboot the NAS.

There are 4 different command that you can use:

1) reboot
2) echo C >/dev/ttyS1
3) echo 1 >/dev/ttyS1
4) echo 0 >/dev/ttyS1

The "reboot" command should gracefully reboot your Synology NAS... but for me it doesn't works.
It just stop some NAS services, get me disconnected from the terminal, but the NAS doesn't reboot.

The "echo C >/dev/ttyS1" command is my favorite one: this will instantly hard-reset the NAS, like when you press the reset button on your computer. This is not nice for a NAS, but it's still better than unplugging the power when the NAS get unresponsive.

The  command "echo 1 >/dev/ttyS1" will instantly power off your NAS, like unplugging the power cable.

The  command "echo 0 >/dev/ttyS1" should be like pressing the NAS power button, I never tried that one.

So when my NAS get unresponsive, I usually go for the "echo C >/dev/ttyS1" command.
Press Enter, and the NAS get a forced reset!