Pages

April 6, 2008

Setup Debian Etch on NSLU2 for torrent downloading

Hi, if you don't already have cheap, small, power efficient and silent file server at home, meet NSLU2. This is way of setting up Debian after its installing for more or less torrent downloading.


As external USB harddisk, I use Toshiba 120GB. Linux identifies it pretty anonymously:
SCSI device sda: 234389464 512-byte hdwr sectors (120007 MB)
sda: Write Protect is off
sda: Mode Sense: 0b 00 00 08
sda: assuming drive cache: write through
sda: sda1 sda2 sda3
sd 0:0:0:1: Attached scsi disk sda

First to tell, I used firmware Debian/NSLU2 Stable 4.0r3. Follow the guide. Second, you NEED to choose 3 modules to load during install process:
partman-auto
partman-ext3
usb-storage-modules

In my setup, I have 3 partitions:
/dev/sda1  (bootable) 4GB    /
/dev/sda2 1 GB swap
/dev/sda3 106 GB /data

So, after installing debian (please make your swap partition at least 256 MB big) on your SLUG, I recommend to make these steps:

- setup static ip
# cat /etc/network/interfaces
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet static
address 192.168.1.77
netmask 255.255.255.0
gateway 192.168.1.254

- clean up services
update-rc.d -f nfs-common remove
update-rc.d -f portmap remove
update-rc.d -f atd remove
update-rc.d -f exim4 remove

- comment all services in file /etc/inetd.conf

- modify /etc/default/rcS and enable FSCKFIX
# grep FSCKFIX /etc/default/rcS
FSCKFIX=yes

- make /dev/urandom same as /dev/random by creating file /etc/udev/chaos.rules and symlink to this file
# cat /etc/udev/chaos.rules
KERNEL=="random", NAME="chaos"
KERNEL=="urandom", NAME="random"
# ls -la /etc/udev/rules.d/z80_chaos.rules
lrwxrwxrwx 1 root root 21 Apr 2 21:17 /etc/udev/rules.d/z80_chaos.rules -> /etc/udev/chaos.rules

- install dropbear (set it on port 2222), enable it, ensure it works after reboot, then disable ssh
apt-get install dropbear
update-rc.d -f ssh remove

- modify sysctl
# cat /etc/sysctl.conf
net.ipv4.conf.default.forwarding=1
net.ipv4.ip_forward=1
vm.overcommit_memory=1
kernel.panic=10

- install usefull stuff
apt-get install psmisc screen openvpn rtorrent dtach samba dash ntpdate sudo beep htop sysstat

- I have simple samba rw access for everyone in my private network (/data/share permisions 777)
# cat /etc/samba/smb.conf
[global]
server string = nslu2
netbios name = nslu2
security = share
guest ok = yes
[data]
path = /data/share
read only = no

- setup hostname and /etc/hosts
# cat /etc/hostname
nslu2
# cat /etc/hosts
127.0.0.1 localhost
192.168.1.77 nslu2

- change line in /etc/inittab:
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

to
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -h now

- also you can comment out getty line for serial line, if you dont have HW modified NSLU2.
#T0:23:respawn:/sbin/getty -L ttyS0 115200 linux

- if you will be using openvpn, modify /etc/modules
# cat /etc/modules
tun

- disable ipv6 in /etc/modprobe.d/aliases, change line
alias net-pf-10 ipv6

to
alias net-pf-10 off

- shedule periodic time synchronizing (permissions of ntp.sh: 755)
# cat /etc/cron.daily/ntp.sh
#!/bin/sh
ntpdate tak.cesnet.cz > /dev/null 2> /dev/null

- make dash symlink to /bin/sh to save memory and time
dpkg-reconfigure dash

- disable loading of device mapper modules by modifying start script (just insert "exit 0" as second line)
# head /etc/init.d/libdevmapper1.02
#!/bin/sh
exit 0
PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=libdevmapper1.02

- modify /etc/rc.local
# cat /etc/rc.local
#!/bin/sh -e
/usr/bin/beep -l 45 -f 15 -d 150
modprobe -r sr_mod
modprobe -r cdrom
exit 0

- modify /etc/fstab and add noatime option to ext3 filesystems
# grep ext3 /etc/fstab
/dev/sda1 / ext3 defaults,noatime,errors=remount-ro 0 1
/dev/sda3 /data ext3 defaults,noatime 0 2

- Just to be complete, this is list of all programs I am running in parallel on my SLUG:
noip.org client (compiled program name: noip2)
dtach + rtorrent 0.7.9 - custom compiled for Xscale processor
samba
dropbear
openvpn
syslog
cron

More specific:
# uname -a
Linux nslu2 2.6.18-6-ixp4xx #1 Tue Feb 12 00:57:53 UTC 2008 armv5tel GNU/Linux
# uptime
00:43:41 up 3 days, 6:08, 1 user, load average: 0.28, 0.30, 0.27
# pstree
init-+-cron
|-dropbear---dropbear---dash---pstree
|-dtach---rtorrent
|-events/0
|-khelper
|-klogd
|-ksoftirqd/0
|-kthread-+-aio/0
| |-kblockd/0
| |-khubd
| |-2*[kjournald]
| |-kpsmoused
| |-kseriod
| |-kswapd0
| |-2*[pdflush]
| |-scsi_eh_0
| `-usb-storage
|-mtdblockd
|-nmbd
|-noip2
|-openvpn
|-smbd---2*[smbd]
|-syslogd
`-udevd
# free
total used free shared buffers cached
Mem: 29988 29108 880 0 312 19916
-/+ buffers/cache: 8880 21108
Swap: 979956 6756 973200
# cat /proc/cpuinfo
Processor : XScale-IXP42x Family rev 2 (v5l)
BogoMIPS : 266.24
Features : swp half fastmult edsp
CPU implementer : 0x69
CPU architecture: 5TE
CPU variant : 0x0
CPU part : 0x41f
CPU revision : 2
Cache type : undefined 5
Cache clean : undefined 5
Cache lockdown : undefined 5
Cache format : Harvard
I size : 32768
I assoc : 32
I line length : 32
I sets : 32
D size : 32768
D assoc : 32
D line length : 32
D sets : 32

Hardware : Linksys NSLU2
Revision : 0000
Serial : 0000000000000000

As you can see, my NSLU2 is mainly for torrent downloading + file sharing. Few recommendations for rtorrent:
- run rtorrent as user, not root!
- renice rtorrent to +19, system will be more responsive, if you are downloading many torrents

- custom working .rtorrent.rc:
$ cat .rtorrent.rc
min_peers = 1
max_peers = 12
min_peers_seed = 1
max_peers_seed = 5
max_uploads = 5
max_uploads_global = 20
max_downloads_global = 30
upload_rate = 20
download_rate = 200
directory = ./tor/leech
session = ./tor/.session
schedule = watch_directory,10,10,load_start=./tor/watch/*.torrent
#*/
schedule = tied_directory,10,10,start_tied=
schedule = untied_directory,10,10,stop_untied=
schedule = ratio,60,60,"stop_on_ratio=100,200M,1000"
on_start = link2,"create_link=base_path,,.started"
on_stop = link2,"delete_link=base_path,,.started"
on_finished = link2,"create_link=base_path,,.finished"
on_erase = link2,"delete_link=base_path,,.finished"
port_range = 45551-45551
port_random = no
check_hash = no
use_udp_trackers = yes
send_buffer_size = 4096
receive_buffer_size = 4096
encryption=allow_incoming,try_outgoing,enable_retry

Thats all folks, enjoy!

No comments:

Post a Comment