Thursday, January 26, 2012

How to install rtorrent with ip filtering into your Iomega StorCenter ix4-200d


EDIT: this post is outdated now, please see this post instead with a much newer version of rtorrent that works with magnets and natively supports ip filtering

This tutorial uses unsupported features of the IOMEGA Storcenter ix4-200d. It worked for me but use it at your own risk! It should work (again, it is unsupported) on the ix2 Storcenter as well.
Tutorial tested on IOMEGA Storcenter ix4-200d firmware 3.1.14.995
The torrent software supplied with the Storcenter doesn't work well for me: some torrents never load, some disappear etc.. plus there is no ip filtering capability. The aim of the tutorial is to install rtorrent on the NAS which seems the most logical choice for a NAS (light weight and reliable) and explains how to enable ip filtering directly within rtorrent which is especially usefull since peerguardian/moblock can't be installed on the NAS because some kernel modules are missing...


1. SSH into your NAS
See my other post: How to ssh into your Iomega StorCenter ix4-200d


2. Install the software
See my other post here to setup at the minimum ikg and ipkg-opt. Then:
ipkg-opt install rtorrent
ipkg-opt install lighttpd
ipkg-opt install screen

If you don't want to connect remotely to rtorrent to manage it from you computer, you can skip the rest of this section...
Install nTorrent on your computer http://code.google.com/p/ntorrent/
Install xml-rpc on the NAS:
ipkg install optware-devel
ipkg install libcurl-dev
cd /opt/tmp/
svn checkout http://xmlrpc-c.svn.sourceforge.net/svnroot/xmlrpc-c/stable xmlrpc-c    
cd xmlrpc-c/
./configure --prefix=/opt
make
make install
Note: ou can choose something other that nTorrent. Please give me you feedback in the comments if you do.


3. Configure the software
Fix paths in the startup script:
vi /opt/etc/init.d/S99rtorrent
Some absolute paths need to be set. Replace screen with /opt/bin/screen in lines like:
su -c "/opt/bin/screen -ls | grep -sq "\.${srnname}[[:space:]]" " ${user} || su -c "/opt/bin/screen -dm -S ${srnname} 2>&1 1>/dev/null" ${user} | tee -a "$logfile" >&2
except:
su -c "/opt/bin/screen -S ${srnname} -X screen /opt/bin/rtorrent ${options} 2>&1 1>/dev/null" ${user} | tee -a "$logfile" >&2
replace:
if ps | grep -sq ${pid}.*rtorrent ; then # make sure the pid doesn't belong to another process
with
if ps auxxx | grep -sq ${pid}.*rtorrent ; then # make sure the pid doesn't belong to another process
Configure rtorrent (you should get a real rtorrent help for this, I am just trying to get you to a point where is works!):
vi /opt/etc/rtorrent.conf
set download and torrent directories:
instead of
directory = /opt/share/torrent/work/
set something like
directory = /mnt/pools/A/A0/torrents/rtorrent/download
instead of
schedule = watch_directory,5,5,load_start=/opt/share/torrent/dl/*.torrent
set something like
schedule = watch_directory,5,5,load_start=/mnt/pools/A/A0/torrents/rtorrent/torrents/*.torrent
comment out:
#schedule = untied_directory,5,5,stop_untied=
add at the end:
#files rwx for everybody
system.set_umask = 0000
Run:
mkdir /opt/share/torrent/session
Then, create the directories rtorrent/download and rtorrent/torrents inside the torrent share using regular NAS access (to have the right permissions)


4. Configure the software for remote access
This is only if you want to manage your rtorrent remotely:
Thanks to http://www.nslu2-linux.org/wiki/HowTo/RtorrentWithRemoteGUI for the setup.
Security warning: if you follow these steps, anybody that can access port 8081 of you NAS will be able to send commands to rtorrent! You want to make sure that this port is only accessible from your local network.
vi /opt/etc/lighttpdlighttpd.conf
between
#                               "mod_rrdtool",
and
"mod_accesslog" )
add
"mod_scgi",
and at the end add:
scgi.server = (
"/RPC2" => ( 
    "127.0.0.1" => (
        "host" => "127.0.0.1",
        "port" => 5000,
        "check-local" => "disable"
        )
    )
)
vi /opt/etc/rtorrent.conf
and at the end add:
scgi_port = localhost:5000


4. Test your setup
/opt/bin/rtorrent -n -o import=/opt/etc/rtorrent.conf
if you get:
rtorrent: Fault occured while inserting xmlrpc call.
did you install xmlprc correctly? is ld.so.conf updated correctly? did you run ldconfig?

to connect to the running instance:
/opt/bin/screen -r rtorrent
and kill the terminal (putty) to exit or press Ctrl-a d.

For remote access: you can start lighthttpd on the NAS
/opt/etc/init.d/S80lighttpd start
and then start nTorrent on your computer and connect to your NAS port 8081 (by default) on path /RPC2.



5. Get rtorrent to start automatically on reboot
Follow the tutorial How to run a program at boot on Iomage Strocenter You just need to add the following lines to the script:
/opt/etc/init.d/S80lighttpd start >> /opt/init-opt.log
/opt/etc/init.d/S99rtorrent start >> /opt/init-opt.log
If you have another brand of NAS (or a regular linux OS), just try to link the startup scripts to /etc/rc2.d/ like ou would normally do an a linux box:
ln -s /opt/etc/init.d/S80lighttpd /etc/rc2.d/S80lighttpd
ln -s /opt/etc/init.d/S99rtorrent /etc/rc2.d/S99rtorrent


6. Get a peerguardian like protection
First, I tried to install peerguardian linux but ran into a wall: the LifeLine OS on the Iomega Storcenter does not have the right kernel modules. I tried to recompute the kernel from the sources given by IOMEGA on their website (it is available for download in the support section) I got it to compile but insmod of the required module (x_tables.ko) does freeze the kernel (hard reboot required). Since I could not think of a safe way to push further in this direction (without risking to brick the NAS), I investigated other possibilities...(post a comment if you want more details on the kernel compilation)
I thought about abandoning rtorrent altogether and try Vuze (which has ip filtering).I got it to run but it was pretty unstable (jre crash)...

Luckily, someboby wrote a patch for rtorrent so that it supports ip filtering. I got it to compile on my NAS (version 0.8.6) and here is the result.You just need to:
cd /opt/bin/
mv rtorrent rtorrent.sav
wget http://dl.dropbox.com/u/50398581/rtorrent-0.8.6/rtorrent
that will give you a rtorrent with ip filtering supported.
Note: this only work if you previously installed version 0.8.6 of rtorrent!

The precompiled version will only work if you have an "armel" architecture. Otherwise, you need to recompile from source (see point 7 below)

The some config:
vi /opt/etc/rtorrent.conf
and add at the end
ip_filter=/mnt/pools/A/A0/torrents/rtorrent/ipfilter/level1
schedule = filter,18:30:00,24:00:00,reload_ip_filter=
thanks to http://bogdan.org.ua/2011/04/01/rtorrent-enhanced-with-ipfilter-and-geoip-debian-squeeze-amd64-package.html

Now, we need to download and update regularly the ip filter file:
vi /etc/cron.daily/rtorrent_ipfilter
#!/bin/sh
cd /mnt/pools/A/A0/torrents/rtorrent/ipfilter/
wget http://list.iblocklist.com/?list=bt_level1
mv index.html\?list\=bt_level1 level1new.gz
gunzip level1new.gz
rm level1
mv level1new level1
then:
mkdir /mnt/pools/A/A0/torrents/rtorrent/ipfilter/
cd /etc/cron.daily/
chmod a+x rtorrent_ipfilter
./rtorrent_ipfilter
That's it: you just need to restart rtorrent to enjoy ip filtering. The ip filter file will be update everyday thanks to the cron (and rtotorrent will reload it).




7. In case you want/need to compile rtorrent with ip filtering yourself!
This is usefull if you are compiling a different version or a different architecture (please comment and report your success if you do so).

First, you need the header files for libsigc++-2.0.
wget http://ftp.de.debian.org/debian/pool/main/libs/libsigc++-2.0/libsigc++-2.0-dev_2.0.18-2_armel.deb
dpkg --instdir=/opt/ --admindir=/opt/dpkg/ -i libsigc++-2.0-dev_2.0.18-2_armel.deb

Then, take care of litorrent. I recompile libtorrent to install the correct headers as I don't find them anywhere (I didn't look for a deb archive with the correct headers but that might have done the trick...):
wget http://libtorrent.rakshasa.no/downloads/libtorrent-0.12.6.tar.gz
tar -xvf libtorrent-0.12.6.tar.gz
cd libtorrent-0.12.6
PATH=$PATH:/opt/bin
Then:
vi configure
and add at the begining of the configure script:
OPENSSL_CFLAGS='-I/opt/include/'
OPENSSL_LIBS='-L/opt/lib/ -lopenssl'
STUFF_LIBS='-L/opt/lib/ -lsigc-2.0'
STUFF_CFLAGS='-I/opt/usr/include/sigc++-2.0/ -I/opt/usr/lib/sigc++-2.0/include'
Note that I do edit the configure because I don't manage to get ipkg-config to work correctly. Using /opt/bin/pkg-config works better than the /bin/pkg-config but still not good enough...
./configure --prefix=/opt/
make
make install

Then, the main thing: rtorrent
ipkg-opt install libcurl-dev
ipkg-opt install ncurses-dev
PATH=$PATH:/opt/bin
wget http://libtorrent.rakshasa.no/downloads/rtorrent-0.8.6.tar.gz
tar -xvf rtorrent-0.8.6.tar.gz
cd rtorrent-0.8.6
vi configure
and add at the begining of the configure script:
sigc_LIBS='-L/opt/lib/ -lsigc-2.0 -L/lib/'
sigc_CFLAGS='-I/opt/usr/include/sigc++-2.0/ -I/opt/usr/lib/sigc++-2.0/include -I/opt/include/ncurses'
libcurl_LIBS='-L/opt/lib/ -lcurl'
libcurl_CFLAGS='-I/opt/include/'
libtorrent_LIBS='-L/opt/lib/ -ltorrent'
libtorrent_CFLAGS='-I/opt/include/'
I did not know were to put the ncurses include, that's why you'll find it in sigc_CFLAGS...

Now, install the patch to have ip filtering (more details on the patch here http://libtorrent.rakshasa.no/ticket/239):
wget http://libtorrent.rakshasa.no/raw-attachment/ticket/239/rtorrent-0.8.6-ip_filter_no_boost-fast-bsd2.patch
/opt/bin/patch-patch -p1 < rtorrent-0.8.6-ip_filter_no_boost-fast-bsd2.patch
./configure --prefix=/opt/ --with-xmlrpc-c=/opt/bin/xmlrpc-c-config
Then, I got the following issue:
/opt/arm-none-linux-gnueabi/lib/libdl.so.2: undefined reference to `_dl_tls_get_addr_soft@GLIBC_PRIVATE'
My system is starting to be a mess. The problem comes from the fact that I have 2 libdb.so libs:
root@xxx:/opt/tmp/rtorrent-0.8.6# ls -l /mnt/apps/lib/libdl.so.2
lrwxrwxrwx 1 root root 12 Sep  9 20:46 /mnt/apps/lib/libdl.so.2 -> libdl-2.8.so
root@xxx:/opt/tmp/rtorrent-0.8.6# ls -l /mnt/system/opt/arm-none-linux-gnueabi/lib/libdl.so.2
lrwxrwxrwx 1 root root 12 Jan  6 22:47 /mnt/system/opt/arm-none-linux-gnueabi/lib/libdl.so.2 -> libdl-2.5.so
to fix the issue:
rm /mnt/system/opt/arm-none-linux-gnueabi/lib/libdl.so.2
Then, compile and install:
make
make install
final issue:
Could not compile XMLRPC-C test.
This one came from a mismatch between heders and libs. Recompiling the package xml-rpc from source did fix the issue. 8. What's next In a different post, I will detail how to install Vuze headless (without graphical interface)... I don't recommand installing vuze because I ran into stability issues while testing it (several jre crashes). However, a new Jre version might solve the issue...
On top of that, you can't do much from the Web UI: when you want to setup something, you ofen have to use the Vuze command line inteface and I did not find any proper documentation for it.
Note as well that rss feeds features don't work in headless mode.

9 comments:

  1. Hi, Congratulations for your blog, very technical.
    I have the old version of ix4-200d does not cloud, you know the upgrade to version cloud edition?
    Maurizio.

    ReplyDelete
    Replies
    1. @MaurizioM
      thanks for your support. Regarding your question, I never tried the conversion since I have an ix4-200d Cloud edition myself. From what I read (source: http://www.chriscolotti.us/technology/how-to-convert-an-iomega-ix4-200d-to-an-ix4-200d-cloud-edition/), there is no safe/supported way to do the conversion. Some pepole also write about using a formatted USB drive to reinstall the CE OS completely on the ix4 (http://forum.nas-central.org/viewtopic.php?f=251&t=4401), but the procedure is unsupported and I haven't tested it myself, so I can't really comment. Maybe another way would be to let me know the features you miss on your NAS and we may find a safer way to add them to your device ...

      Delete
  2. I'm a total newcomer to Linux, but this tutorial has allowed me to install and use UNRAR on my NAS - GODSEND.

    Thanks for the help.

    ReplyDelete
  3. hi Vincent,
    I broke my ix4, and I look for an image of system files for the version Cloud edition.
    To repair my ix4 I found only the files of the version no cloud (uilising the Nas-central procedure which works)

    Could you help me?

    ReplyDelete
    Replies
    1. I don't know how to generate an image... not home right know but I'll try to have a quick look at the end of the week.

      Delete
    2. can you try to replace the ix4-boot.tgz in your USB key with the file available here:
      http://depositfiles.com/files/nfwnda80c

      I extracted the data from my NAS, it seems to be in the right format but I did not test it. Let me know if it works!

      Delete
  4. Do You know how to install airprint suport, means avahi-daemon

    ReplyDelete
  5. I don't have any apple devices myself, so I can't give you a precise tutorial.
    However, I might be able to help on a specific problem during the installation.

    Did you manage to get cups running?
    does
    ipkg-opt install cups
    works? (see http://vincesoft.blogspot.fr/2012/01/how-to-install-software-into-your.html for details on ipkg-opt)

    If yes, did you try to follow a tutorial such as http://archlinuxarm.org/support/guides/applications/cups-apple-airprint?
    where does it fail?

    Cheers

    ReplyDelete
  6. I managed to find a problem of mine for compiling perl on my ix2-200d by googling and hitting your page:

    Then, I got the following issue:
    /opt/arm-none-linux-gnueabi/lib/libdl.so.2: undefined reference to `_dl_tls_get_addr_soft@GLIBC_PRIVATE'

    ReplyDelete