Thursday, January 7, 2010

hacking eGreat EG-R1 (installing torrent client, samba, ssh, plowshare etc..)

Hello,

I am presenting here my way how to run some useful applications on this (e)great device.

IMPORTANT: This guide is not for the beginners. Some linux skills are necessary, otherwise you can broke your box! Please be careful, never proceed to the next step until previous was successfully done. Good luck.

Step 1. Preparation of environment, installation of ipkg package management system (must be done)

What we need:
- ssh/telnet client (for windows it's putty - http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe
- USB memory stick (256M+) or USB/SATA harddisk which will be formated as ext3 filesystem, SATA disk is the best solution here

So let's start:
- connect USB stick to the box and power it on.
- launch putty and open a Telnet connection to ip address of the box, log in as "root"
- check if you have connection to the Internet:
ping www.google.com
if you don't see "is alive!", something's wrong

- let's check if we see USB stick "/tmp/usbmounts/sda1" (if we are using USB disk with more than one partition, we will see also sda2, sda3 etc...).

mount
/dev/root on / type yaffs2 (ro,noatime)
none on /dev type devfs (rw)
none on /proc type proc (rw,nodiratime)
devpts on /dev/pts type devpts (rw)
none on /sys type sysfs (rw)
none on /tmp type ramfs (rw)
/dev/mtdblock/2 on /usr/local/etc type yaffs (rw,noatime)
/dev/rd/0 on /mnt/rd type vfat (rw,nodiratime,fmask=0022,dmask=0022,codepage=cp437,iocharset=iso8859-1)
/dev/scsi/host2/bus0/target0/lun0/part1 on /tmp/usbmounts/sda1 type vfat (ro)

- see info about free space and disk size (in case of more disk partitions, identify correct partition by it's size:
df -h

NOTICE: note the line with correct partition to notepad for later
examp. "/dev/scsi/host2/bus0/target0/lun0/part1 on /tmp/usbmounts/sda1 type vfat (ro)"

- remount "/" as read/write:
mount / -o remount,rw

- we must free some space in /.
the best way is to substitute any big chinesse bitmap font which we never use with arial.ttf

- in case of 1.0.4.10 firmware do:
cp /usr/local/bin/Resource/tahoma.ttf /usr/local/bin/Resource/yahei.ttf

- in case of 1.0.3.5 firmware do:
cp /usr/local/bin/Resource/tahoma.ttf /usr/local/bin/Resource/yahei.ttf

- in case of 1.0.3.2 firmware do:
cp /usr/local/bin/Resource/arial.ttf /usr/local/bin/Resource/yahei.ttf

- in case of 1.0.2.3 firmware try :
cp /usr/local/bin/Resource/arial.ttf /usr/local/bin/Resource/msyh.ttf
(if is your firmware older than 1.0.2.3, update it)

- format selected partition:
umount /tmp/usbmounts/sda1

mkfs.ext3 -L opt /dev/scsi/host2/bus0/target0/lun0/part1

tune2fs -o journal_data_writeback /dev/scsi/host2/bus0/target0/lun0/part1

- mount it back as ext3:
mount /dev/scsi/host2/bus0/target0/lun0/part1 /tmp/usbmounts/sda1 -o noatime,data=writeback

- create directories and symlinks:
mkdir /tmp/usbmounts/sda1/root; ln -s /tmp/usbmounts/sda1/root /root

mkdir /tmp/usbmounts/sda1/opt; ln -s /tmp/usbmounts/sda1/opt /opt

- correct root profile and environment:
echo -e PATH="/opt/bin:/opt/sbin:\$PATH"\\nHOME=/root\\nTERM=xterm\\nINPUTRC=/etc/inputrc\\nPAGER=more\\nexport PATH TERM INPUTRC PAGER\\nalias mc=\"mc -c\"\\n"" >/root/.profile

cp -p /etc/passwd /etc/passwd.bak; sed "s/root::0:0:root::\/bin\/sh/root::0:0:root:\/root:\/bin\/sh/" < /etc/passwd.bak > /etc/passwd

- create a root password to be secure:
passwd root

exit

- connect back and check if you are now in your home directory on usb disk:
pwd; echo $PATH


Installation of ipkg package system:

mkdir /opt/tmp; cd /opt/tmp

wget http://www.kovari.priv.hu/download/ipkg-cl.tgz; tar -xvf ipkg-cl.tgz; rm ipkg-cl.tgz

mv /opt/tmp/ipkg-cl /usr/local/bin

wget http://ipkg.nslu2-linux.org/feeds/optware/oleg/cross/stable/uclibc-opt_0.9.28-13_mipsel.ipk

ipkg-cl install uclibc-opt_0.9.28-13_mipsel.ipk

wget http://ipkg.nslu2-linux.org/feeds/optware/oleg/cross/stable/ipkg-opt_0.99.163-10_mipsel.ipk

ipkg-cl install ipkg-opt_0.99.163-10_mipsel.ipk

rm *.ipk

- download list of packages:
/opt/bin/ipkg update

- test it by installing Nano text editor (we will need it later):
ipkg install nano


Step 2. Auto mounting of /opt and /root after reboot + starting of SSH daemon:
(must be done)

- we need UUID number of our ext3 filesystem:
tune2fs -l /dev/scsi/host2/bus0/target0/lun0/part1 | grep UUID
output will be something like:
Filesystem UUID: a46bd0c3-0479-481b-8b36-cebc69b6c397

note your UUID to notepad, for example "a46bd0c3-0479-481b-8b36-cebc69b6c397"

>>Now be very careful!!!<<
- open the starting script and put following lines at the bottom of file:
NOTE: as k="a46bd0c3-0479-481b-8b36-cebc69b6c397" use your disk UUID!!!

nano /usr/local/etc/rcS
input following text at the bottom of file:

# Mounting /opt and /root
sleep 60
mount / -o remount,rw
rm /opt
rm /root

# my disk UUID:
k="a46bd0c3-0479-481b-8b36-cebc69b6c397"

# disk checking and mounting:
for i in `mount | awk '/\/dev\/scsi\// {print $1}'`
do
if [ `tune2fs -l $i | awk '/UUID/ {print $3}'` = $k ]
then m=`mount | grep $i | awk '{print $3}'`
umount $m
fsck.ext3 -f $i
mount $i $m -o noatime,data=writeback
ln -s "$m/opt" /opt
ln -s "$m/root" /root
fi
done

sleep 1
# starting SSH:
/opt/etc/init.d/S40sshd start
(to save press ctrl+x, then "y")

Ok, so let's reboot the box ant check if everything is OK
reboot

Wait approx 2 minutes and log in back, check if you are in your home directory and if /opt and /root exist:
pwd; ls -lad /opt; ls -lad /root


Step 3. Installation of OpenSSH/SFTP
(strongly recommended if you are connected to the Internet)

ipkg install openssh openssh-sftp-server

- reboot wait approx. 2 minutes and try to connect via SSH:
reboot
(in putty change type of connection from Telnet to SSH and log in back as root)

OPTIONAL:
If you want to disable Telnet (we have SSH working now) just comment (#) following line in /etc/inetd.conf:
#telnet stream tcp nowait root /usr/sbin/telnetd telnetd

How to use SFTP:
- connect via sftp client to the same ip and port as SSH.
For more detailed configuration you have to modify "/opt/etc/openssh/sshd_config".
More info here - https://help.ubuntu.com/community/SSH/OpenSSH/Configuring

If you want to have all disks mounted as writable, add this to rcS at the bottom:
(good idea if you plan to use SAMBA or torrent client)
nano /usr/local/etc/rcS

# remount disks as "rw"
for i in `mount | awk '/\/tmp\/usbmounts\/sd/ {print $3}'`
do mount $i -o remount,rw
done


Step 4. Installation of Transmission torrent client

- install packages:
ipkg install transmission

mkdir /root/transmission

- create a directory for downloads:
mkdir /root/downloads

- create a config file, adjust settings as you need, specially "rpc-username" and "rpc-password", more info here: http://trac.transmissionbt.com/wiki/EditConfigFiles

nano /root/transmission/settings.json
paste following text in to it:
{
"alt-speed-down": 50,
"alt-speed-enabled": false,
"alt-speed-time-begin": 540,
"alt-speed-time-day": 127,
"alt-speed-time-enabled": false,
"alt-speed-time-end": 1020,
"alt-speed-up": 50,
"bind-address-ipv4": "0.0.0.0",
"bind-address-ipv6": "::",
"blocklist-enabled": false,
"dht-enabled": true,
"download-dir": "\/root\/downloads",
"encryption": 0,
"lazy-bitfield-enabled": true,
"message-level": 2,
"open-file-limit": 16,
"peer-limit-global": 120,
"peer-limit-per-torrent": 30,
"peer-port": 51413,
"peer-port-random-high": 65535,
"peer-port-random-low": 49152,
"peer-port-random-on-start": false,
"peer-socket-tos": 0,
"pex-enabled": true,
"port-forwarding-enabled": true,
"preallocation": 1,
"proxy": "",
"proxy-auth-enabled": false,
"proxy-auth-password": "",
"proxy-auth-username": "",
"proxy-enabled": false,
"proxy-port": 80,
"proxy-type": 0,
"ratio-limit": 1.0000,
"ratio-limit-enabled": false,
"rpc-authentication-required": true,
"rpc-bind-address": "0.0.0.0",
"rpc-enabled": true,
"rpc-password": "your_password",
"rpc-port": 9091,
"rpc-username": "admin",
"rpc-whitelist": "*.*.*.*",
"rpc-whitelist-enabled": false,
"speed-limit-down": 150,
"speed-limit-down-enabled": false,
"speed-limit-up": 100,
"speed-limit-up-enabled": false,
"umask": 18,
"upload-slots-per-torrent": 7
}

- set up a web engine for it:
rm -rf /tmp/www

ln -s /opt/share/transmission/web/ /tmp/www

- finally let's run the transmission daemon:
/opt/bin/transmission-daemon -g /root/transmission/

- wait for a moment and try to connect to transmission web page, it should work now:
http://ip_of_box:9091

IMPORTANT: If you want to change any setting in "settings.json" , you must first stop transmission daemon:
killall transmission-daemon; sleep 1;killall transmission-daemon
then edit "settings.json" and start is back

- if the transmission webpage is working OK, add to the start script:
nano /usr/local/etc/rcS

# starting Transmission:
rm -rf /tmp/www
ln -s /opt/share/transmission/web/ /tmp/www
/opt/bin/transmission-daemon -g /root/transmission/

- reboot box to test start script:
reboot
wait approx. 2 minutes and access Transmission web page, it should work.


Step5. SAMBA installation
(if you want to access your box over home network)

- download EG-R1_BT_SAMBA package from eGreat site and unpack:
cd; wget http://www.egreatworld.com/download/EG-R1_BT_SAMBA.rar

ipkg install unrar

unrar x EG-R1_BT_SAMBA.rar

cd EG-R1\ BT_SAMBA_20091017EN/

ipkg install samba_3.0.23c_mipsel.ipk

cd; rm -rf EG-R1*

mv /tmp/package /opt/

ln -s /opt/package /tmp/package

- edit smb.conf:
nano /opt/package/samba/lib/smb.conf

- add line:
guest ok=yes
up line "guest account=root"

- change line "domain logons=Yes" to
domain logons=No

- change line "client NTLMv2 auth=yes" to
client NTLMv2 auth=no

- add at the bottom:
[Storage]
comment = Storage
browseable = yes
writable = yes
path = /tmp/usbmounts/

- start SAMBA daemons:
/tmp/package/script/samba start

- after a while, you should see box on the network as "Venus"

- edit start script and add at the bottom:
nano /usr/local/etc/rcS

# Samba start
rm /tmp/package
ln -s /opt/package/ /tmp/package
/tmp/package/script/samba start

- reboot box to test SAMBA autostart
reboot
wait approx. 2-3 minutes, then log back in and check if samba is running:
ps -ef | grep mbd

if you see this, it's OK:
378 root 1732 S N /tmp/package/samba/sbin/smbd -D
381 root 1080 S N /tmp/package/samba/sbin/nmbd -D
383 root 1716 S N /tmp/package/samba/sbin/smbd -D

after a while you can access your disks from the home network (tested on Windows7 and XP)


Step 6. Plowshare Download manager
(it supports Megaupload, Rapidshare, 2Shared, 4Shared, ZShare, Badongo, DepositFiles and Mediafire)

- it include programs:
plowdown
plowup
plowdel

- install packages:
ipkg install coreutils imagemagick tesseract-ocr tesseract-ocr-lang-eng grep bash plowshare

- create a symlink (if doesn't exist):
ln -s /proc/self/fd /dev/fd

- add to the rcS script at the bottom:
nano /usr/local/etc/rcS

# plowshare fix
ln -s /proc/self/fd /dev/fd

Usage is very simple, go to the download directory and do:
plowdown http://www.rapidshare.com/files/86545320/Tux-Trainer_25-01-2008.rar
or
plowdown list.txt
(in list.txt is list of links to download, 1 link for line)

To ensure that all links from list will be downloaded, create a simple script in downloads directory:
cd ~/downloads; nano plow_down.sh

while true
do plowdown -m $1
sleep 120
done

chmod +x plow_down.sh

usage is: ./plow_down.sh list.txt

more info here: http://code.google.com/p/plowshare/wiki/Readme

NOTE: the "parse failed.." message mean that all public download slots are occupied, you have to wait 2 minutes and try again


Step 7. Installation of SCREEN
(ideal in combination with plowshare)


We have to solve problem, how to run plowshare in the background, so we don't need to be connected over putty all the time. The "screen" is ideal solution. It's a virtual terminal in which we can run programs, detach it, and reconnect back when we want.

- install package
ipkg install screen

- make a config file:
nano /root/.screenrc

- add following text:
shell -$SHELL
startup_message off
hardstatus alwayslastline '%{= wk}%?%-Lw%?%{r}(%{k}%n*%f%t%?(%u)%?%{r})%{k}%?%+Lw%?%?%= %m/%d %C%A'
activity ''

NOTE: when you put text to nano, it will split this line, correct it to be one:
hardstatus alwayslastline '%{= wk}%?%-Lw%?%{r}(%{k}%n*%f%t%?(%u)%?%{r})%{k}%?%+Lw%?%?%= %m/%d %C%A'

- run the program:
screen -R
( -R will connect us to the already running screen if it exist)

We are now in screen 0 and can start plowdown. To detach terminal just press "ctrl+a" then "d",
(see "[detached]" message). Screen is now running in the background and we can disconnect from putty. To connect back to the screen just run "screen -R".

More information here: http://erdelynet.com/tech/openbsd/my-gnu-screen-config/


Step 8. Installation of rTorrent terminal client

rTorrent is lightweight alternative of Transmission. I am using it because it consume less cpu and memory and I don't need web features of Transmission.

ipkg install rtorrent

- create a temp. directory:
mkdir /root/downloads/rtorrent

- create a config file:
ln -s /opt/etc/rtorrent.conf /root/.rtorrent.rc

- modify it as you need:
nano /root/.rtorrent.rc

- before start is good idea to run screen, because rtorrent can't run in the background as Transmission. So just launch "screen -R" and then run "rtorrent".

- some basic control keys:
backspace - start download torrent link you paste
up, down - move between torrents
left, right - more info about torrent
ctrl + d - stop downloading, 2x remove torrent
ctrl + r - recalculate checksum

more info here:
http://libtorrent.rakshasa.no/wiki/RTorrentUserGuide

Step 9. Installation of NFS server (unfs3)

NFS has better performance then Samba, so why do not use it?

ipkg install portmap unfs3

- add your directory to /etc/exports, in my case "/tmp/usbmount/sda1" and my home network is 192.168.1.0/24 (IP range from 192.168.1.1 to 192.168.1.255):

echo "/tmp/usbmounts/sda1/ 192.168.1.0/24(rw,async,no_root_squash)" >> /etc/exports

- test if NFS is working OK, run:

/tmp/usbmounts/ext3/opt/etc/init.d/S55portmap; /tmp/usbmounts/ext3/opt/etc/init.d/S56unfsd


- add at the end of the start script "/usr/local/etc/rcS":

# NFS start
/tmp/usbmounts/ext3/opt/etc/init.d/S55portmap
/tmp/usbmounts/ext3/opt/etc/init.d/S56unfsd

- reboot.

Regards Brano






When unmirrorlv command failed

So what to do?

1. Make a backup before you do anything

2. Create the map file to specify the PPs you want to remove:
# lquerylv -L `getlvodm -l fslv00` -r > /tmp/mapfile

3. vi /tmp/mapfile and remove all good PP's, keep PP's you want to unmirror.

4. Deallocate the PPs using lreducelv (- s "number_of_lines_in_map_file" )

# lreducelv -l `getlvodm -l fslv00` -s 12 /tmp/mapfile

After we are done we should then see lslv -m fslv00 have only one copy

Example:
lquerylv -L `getlvodm -l fsdwhsas2lv` -r > /tmp/fsdwhsas2lv.map
lreducelv -l `getlvodm -l fsdwhsas2lv` -s 24 /tmp/fsdwhsas2lv.map
mklvcopy -s'y' fsdwhsas2lv 2 hdisk74 (now I can extend mirror to 2nd good disk)
syncvg -l dwh2home24lv