Freeing the Thecus N4100

The N4100 is a highly configurable NAS due to running Linux in the background. However Thecus, likely because they are unwilling to risk people breaking their NASes, cut off access to the OS, and forced people to interact with the NAS through the nice, but extremely limiting, web interface. With a little work the NAS can be freed from these restrictions and turned into the server it should be. This article is intended as a guide only - you won't be able to do anything useful with the NAS's extended capabilities if you aren't able to find your own way around, I merely wish to highlight some stumbling blocks I came across, to make the job faster for anyone else intending to free their N4100. Also note that some of this is written from memory, as it has been a while since I first started playing with my N4100, and I'm not going to reset it to how I got it and start again for the sake of this guide.

If you are not exactly sure what you are going to get by doing this, you are going to go from interacting with the NAS via a nice web interface to interacting with it via a shell. Though, of course, the web interface will still be there.

Disclaimer

All of this is done at your own risk. Thecus locked this stuff away to protect you from yourself. If anything on this page leads to you doing anything harmful your NAS, it is your fault and your problem. I accept absolutely no responsibility.

First Steps

The first thing you may want to do is update your firmware. While not necessary for any of the steps below as far as I know, Thecus added a much nicer web interface in later versions. So, if you still have the old static interface, you may wish to upgrade to get the shiny new dynamic AJAX interface. Next, you'll need to install three modules (I have links for the versions I use below; newer versions may be available):

SSHD - This module adds/enables an SSH server on the NAS
SYSUSER - This module adds the user 'sys'. This is the NAS's equivilant of 'root', and is necessary to use SSH as nobody has access by default.
META - This module runs scripts of your choice on startup and shutdown.

These modules were written for the N5200, but some/most/all N5200 modules work on the N4100. Install the modules using the web interface. Once this is done, you may have to reboot the NAS. If the modules are working, you should be able to connect to the NAS using an SSH client, and log in as 'sys' using whatever password you set when installing the module (you might have to set the password by configuring it after installing, I can't remember).

This done, you are now free to do whatever you want with the NAS. The body of this guide is information on what you can do, from specific ideas I have implemented, to general information about where things can be found.

Random Notes

Much of the N4100's filesystem and configuration files are generated on startup. Configuration files will restore their original contents and files in such 'volatile' parts of the filesystem will disappear. /raid/data is non-volatile, aside from that I am not certain.

Due to the above, if you break something, the NAS should restore itself on reboot. That said, try not to break anything.

There are no canonical configuration files - they are actually generated by scripts using data from an SQLite database on boot. You can access those databases and probably change the values - but I wouldn't advise it.

I find that sometimes after exiting vi there is still some part of it running in the background, using most/all of the CPU to do nothing. Check by running top, take of note of its PID if it is there, and kill it using kill -9 PID. Maybe it is doing something useful, and kill -9 might be overkill (hurf hurf), but I'm from Windows, where any and all processes are terminated with extreme prejudice.

Things to Do

Add a non-root User

As I mentioned, 'sys' is the NAS's 'root'. If you are going to be using the command line to interact with the NAS regularly (which is must faster for file operations and such than using file sharing), you may want a non-root user. You can add a user in the web interface, however this user will not have ssh access - attempts to log in will fail. This is because the user's home directory and shell have not been set. To fix this, log in as 'sys' after creating the new user. Your new user will need a home directory - I am not certain if this is created by the NAS or not. The standard seems to be to put these in /raid0/data, so create the folder /raid0/data/newuser if it does not already exist. Once this is done, open /etc/passwd in vi (or your editor of choice). Find the line that references your new user. The final two entries in the line will be /dev/null. Replace the first one with the home directory, /raid0/data/newuser, and the second one with /bin/sh. There are other lines in the file which can guide you as to what it should look like when done, such as sys's line. Once this is done, save. Attempt to log in with your new user. It should work.

Free Samba

Samba is one thing on the NAS which is heavily restricted when used via the web interface. It is capable of much, much more when manipulated directly, in particular, sharing any directory in the filesystem, and following symbolic links. To do all this nice stuff, you must switch to configuring samba using its configuration file rather than the web interface. The trick with this is that this is one of the configuration files mentioned above which recreate themselves on boot. So before you can configure it, you must stop the NAS wiping out your changes on reboot.

There are several ways of doing this - you could play with the original database settings, or write a script which edits the configuration file after it is generated. My preference is a little less refined - simply do what the NAS does. Have a canonical configuration file somewhere, and copy it to where it is needed on boot - but after the NAS has done this with its own one. So, on every boot, the NAS will generate the default configuration, and then your script will replace it with yours.

Doing this removes the property that Samba will 'fix itself' on reboot if you make a config change which breaks it - however this property can be restored by removing your startup script. Anyway, here's how to go about this:

First, create your configuration file. The NAS's own one is a good place to start, and the directory it is in is a non-volatile one, so you can store your one there too. SSH in as 'sys' and go to /raid/sys. Copy smb.conf to mysmb.conf. Now you need to make it so that this will replace the NAS's file on startup. Go to /raid/data/module/META/system/etc/startup and create a file called sambaconf. In this file place the following code:

#!/bin/sh

#Wait for samba to load
while ! ps | grep -v grep | grep smbd &>/dev/null; do
sleep 1
done

cp /raid0/sys/mysmb.conf /raid0/sys/smb.conf
cp /raid0/sys/mysmb.conf /app/etc/samba/smb.conf
cp /raid0/sys/mysmb.conf /tmpfs/tmp/smb.conf

/img/bin/rc/rc.samba restart 1

This script is based on one found on one of the NAS-related wikis. It loops, waiting for samba to load, then copies the configuration file. The NAS creates three copies of the configuration file, this script replaces them all, as this is simpler than determining which ones actually matter. It then restarts Samba. Obviously if you change the name/location of your 'mysmb.conf', make the appropriate change in the script. Close the file, add the execute permission (chmod a+x sambaconf), and you should now be able to configure samba by changing the settings in mysmb.conf. Details of what can be put in this file can be found online. Rememeber to rerun the script above whenever you make changes to the configuration so they will take effect.

RTorrent in Shell

The N4100 apparently has the ability to download torrents. I've never seen where this is in the web interface, if anywhere, but it does mean that the NAS has a torrent client on it by default. Being shell-based it is a little trickier to use than a GUI-based one, but it also offers a far finer degree of control than anything I've seen/heard of. Anyway, it is located at /opt/bin/rtorrent.

If you run /opt/bin/rtorrent without doing anything else it will exit with an error regarding the terminal. To fix this, enter "TERM=vt100" into the shell. This will set the TERM environment variable to vt100, which will allow rtorrent to work for reasons I'm not entirely clear on. Occasionally your shell will be broken when you exit rtorrent. I think this may be related to running it as sys, I'm not certain.

You can avoid having your shell instance of rtorrent interfere with any others (for instance, ones run via the web interface, if that is actually possible) by giving it some configuration options:
"-p X-Y" - specifies a port range in which to open the incoming port. Default seems to be 6950-6960, so try -p 6970-6980 to stay out of the way of any instances using the default.
"-s dir" - specifies a session directory - basically where rtorrent puts the files it creates during normal operation, and where it 'remembers' what torrents it was working on when exited. I normally make this a subdirectory of the directory I store the torrents in. Make sure to create the directory first.

Once you get it started, look up the instructions online to figure out how to use it.

Other Stuff

SQLite and Databases

SQLite can be found in /opt/bin. Two of the databases the system has are /raid0/sys/raid.db, which has some info to do with the RAID (obviously) and I think the shares etc, and /app/cfg/conf.db, which contains much of the system's configuration settings, including the admin and e-mail notification account passwords in plaintext. These are both probably the canonical source of these settings, but I don't particularly feel like playing with them to find out.

Startup Scripts

Startup scripts are found in /img/bin/rc. This includes assemble_conf, which generates the samba configuration file which I instructed you to override above. The scripts in this folder are useful for finding out where things are hidden in the system, in particular assemble_conf will lead you to the databases I highlighted above.

Downloads

Some useful downloads which work with my current version of the N4100 firmware (3.00.05):

N5200_META_2.00.00 - The META module
N5200_SSHD_2.00.00 - The SSHD module
N5200_SYSUSER_2.00.02 - The SYSUSER module
7za - 7zip extractor executable binary
unrar - rar extractor executable binary

Other Resources

NAS Website

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.