2012-01-19

grub rescue >


Panic! On my dual boot pc, a failed linux upgrade had wiped the linux boot partion.
The Windows partitions is still there, but unbootable: the boot process was struck at a grub error


error: no such partition.

grub rescue >

The MRB had to be rewritten but I had no Windows install CD ready at hand.
By chance, I had a GParted Live CD in the desk drawer.
I've booted it and luckily it had the ms-sys command on board: ms-sys just rewrites a Windows MBR on the HD.

# ms-sys -m /dev/hda

Reboot.
Windows was back up and running.

2012-01-14

WNDR3800 NAS performance


UPDATE: there are some news on the subject.

The WNDR3800 has an USB 2.0 port for connecting an external storage.
I've done some testing with an external disk.
The disk used was a 120GB Packard Bell Store and Save 2400 bought back in 2008.
Firmware version of the WNDR3800 was V1.0.0.24
Since the test disk was primarily used to share files between several machines, it was already formatted with NTFS for windows compatibility.

The WNDR3800 exports USB storage by an SMB share and by HTTP: I mounted the share under /mountpoint

So, let's check write performance by creating a test file:

# dd if=/dev/zero of=/mountpoint/testfile bs=4096 count=102400
102400+0 records in
102400+0 records out
419430400 bytes (419 MB) copied, 94.4866 s, 4.4 MB/s

And now read performance:

# dd if=/mountpoint/testfile of=/dev/null
819200+0 records in
819200+0 records out
419430400 bytes (419 MB) copied, 42.9255 s, 9.8 MB/s

Writing is often slower than reading, but 9.8MB/s is the throughput of a 100Mb Ethernet, and we're using Gigabit here.
Let's try with HTTP:

# wget -O /dev/null http://192.168.1.1/shares/USB_Storage/testfile
--2012-01-13 19:08:42--  http://192.168.1.1/shares/USB_Storage/testfile
Connecting to 192.168.1.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 419430400 (400M) [application/download]
Saving to: `/dev/null'

100%[======================================>] 419,430,400 13.6M/s   in 30s    

2012-01-13 19:09:12 (13.4 MB/s) - `/dev/null' saved [419430400/419430400]

HTTP has lower overhead than CIFS, but we're still far from the high performance we can expect.
Maybe the disk is the bottleneck?
Let's try connecting the disk directly to the USB port of the pc:

# dd if=/media/data_ntfs/testfile of=/dev/null
819200+0 records in
819200+0 records out
419430400 bytes (419 MB) copied, 15.1453 s, 27.7 MB/s

It's not the disk: it's able to reach nearly 30MB/s
And now the write performance:

# dd if=/dev/zero of=/media/data_ntfs/testfile bs=4096 count=102400
102400+0 records in
102400+0 records out
419430400 bytes (419 MB) copied, 14.5965 s, 28.7 MB/s

So, this disk is not slower while writing: it seems that the WNDR3800 slows things down.
Could it be the NTFS format? Let's try with a linux filesystem that the Netgear firmware may natively support.
I reformatted the disk with ext2 and retried with the WNDR3800 connection:

# dd if=/dev/zero of=/mountpoint/testfile bs=4096 count=102400
102400+0 records in
102400+0 records out
419430400 bytes (419 MB) copied, 21.423 s, 19.6 MB/s

That's a huge gain versus NTFS.
Read time:

# dd if=/mountpoint/testfile of=/dev/null
819200+0 records in
819200+0 records out
419430400 bytes (419 MB) copied, 35.0745 s, 12.0 MB/s

Again, better than NTFS but strangely enough, lower than writing.
Let's check HTTP:

# wget -O /dev/null http://192.168.1.1/shares/T_Drive/testfile
--2012-01-14 14:24:24--  http://192.168.1.1/shares/T_Drive/testfile
Connecting to 192.168.1.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 419430400 (400M) [application/download]
Saving to: `/dev/null'

100%[======================================>] 419,430,400 18.9M/s   in 22s    

2012-01-14 14:24:46 (18.2 MB/s) - `/dev/null' saved [419430400/419430400]

HTTP confirms its lower overhead, but again, lower performance than writing.
So partition format has a considerable impact on WNDR3800 NAS performance.
One last test may be the use of a really simple filesystem: FAT.
Back to square one with a FAT32 partition:
Write:

# dd if=/dev/zero of=/mountpoint/testfile bs=4096 count=102400
102400+0 records in
102400+0 records out
419430400 bytes (419 MB) copied, 28.7441 s, 14.6 MB/s

Read:

# dd if=/mountpoint/testfile of=/dev/null
819200+0 records in
819200+0 records out
419430400 bytes (419 MB) copied, 41.2611 s, 10.2 MB/s

# wget -O /dev/null http://192.168.1.1/shares/USB_Storage/testfile
--2012-01-14 14:38:28--  http://192.168.1.1/shares/USB_Storage/testfile
Connecting to 192.168.1.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 419430400 (400M) [application/download]
Saving to: `/dev/null'

100%[======================================>] 419,430,400 13.1M/s   in 29s    

2012-01-14 14:38:57 (13.8 MB/s) - `/dev/null' saved [419430400/419430400]

FAT does not boost performance, and even if it did, I wouldn't use FAT as a filesystem for anything serious.


Format Read MB/sWrite MB/s
local USB27.728.7
NTFS9.84.4
ext212.019.6
FAT10.214.6

UPDATE: there is a new firmware available that changes some of this results.

2012-01-13

Xvnc black screen

I was configuring my workstation for remote VNC login following this blog post.
The checklist ends suggesting a reboot command.
If you don't obey, you'll only get a black screen on a VNC connection.
That seems to break the spell: no reboots under linux!

After some investigation it seems that the cause was gdm not accepting tcp connections from Xvnc.
A full reboot is not necessary, just a gdm restart:

Find the gdm instance started by init:

# ps -ef --forest

search the process tree for something like this:

root      3621     1  0 14:35 ?        00:00:00 /usr/sbin/gdm-binary -nodaemon
root      3707  3621  0 14:35 ?        00:00:00  \_ /usr/sbin/gdm-binary -nodaemon
root      3713  3707  0 14:35 tty7     00:00:00      \_ /usr/bin/Xorg :0 -br -audit 0 -auth /var/gdm/:0.Xauth -nolisten tcp vt7
gdm       3734  3707  0 14:35 ?        00:00:00      \_ /usr/libexec/gdmgreeter

the parent gdm here has PID 3621

# kill -1 3621

The console X session will restart, and after that, VNC logins will work.

Update:
On RHEL/CentOS 6, you must use kill -9 to reload gdm, and the vnc-server package is called tigervnc-server

2012-01-11

Motorola Defy wireless performance


Following my previous post, I've done some testing on my phone wi-fi performance compared to a full-blown PC.
Setup is the same as in the previous post, even the phone location is the same as the previous laptop location.
Data transfer was between the Defy and the desktop PC, wire-connected at gigabit speed to the Netgear WNDR3800.



Speed MB/s
2.4Ghz@54Mbs  2.5
2.4Ghz@130Mbs2.6
2.4Ghz@300Mbs2.6
5Ghz@300Mbs---

So, while the Defy supports 801.11n, it takes no advantage of it.
The 5Ghz network is not even recognised and the 300Mbs connection was not very reliable, I had to retry a couple of times before getting a full transfer.


2012-01-08

The hanged power brick

I don't like clutter on my desk, neither cable jams underneath, so here is a tool-less solution for placing a notebook power brick under the desk.

You'll need 2 adesive cable guides and a plastic strip:

Stick one tab on the side of the power brick:

Stick another on the side of the desk:

Now, slide the plastic strip aligning the tab on the desk and the one on the brick as shown:

 
Let the brick slide along the plastic strip until the plastic tabs will rest one onto another (here shown unattached):
 

Note that the plastic strip is simply inserted inside the guides of the plastic tabs and can be extracted at will.
The power brick will be hold by the tabs:



The brick is not fastened in any way, and it can be pulled out when needed on the road.
Once back at the desk, the same plastic strip can be reused to hold the brick again.


2012-01-07

WNDR3800 wireless performance

After looking at wired performance, I've got a spin at wireless:
Test conditions were as follows:

Router Firmware Version: V1.0.0.24
PC 1: notebook with Intel PRO/Wireless 4965 AG
PC 2: desktop with nVidia Corporation CK804 Ethernet (Gigabit speed)
PC 1 was within one meter from the router

On PC 1:
# dd if=/dev/zero bs=4096 count=102400 | nc 192.168.1.31 1999

On PC 2:
# nc -l 1999 | dd of=/dev/null

Speed reported is from dd output on PC 1:


Speed MB/s
2.4Ghz@54Mbs  2.6
2.4Ghz@130Mbs8.1
2.4Ghz@300Mbs9.3
5Ghz@300Mbs9.0



2012-01-06

WNDR3800 backdoor

The Netgear WNDR3800 firmware is a version of OpenWRT, and that's one of the reasons I've bought this router.
While being open is a good thing, being wide open maybe it's not.

This firmware has a backdoor, enabled by a simple utility (the windows version is available directly from the Netgear support site).
Once executed, it gives root access to the router without any authentication.
Consequences may vary from simple denial of service (you can reboot at will), or something more elaborate: download the /etc/shadow file, run John the Ripper, and get the admin password. Then, logging on with the web interface, you can flash a full version of OpenWRT, install tcpdump and capture all unencrypted traffic.

Problem is that the backdoor can be enabled by any device connected to the router, even via wireless; so be aware that allowing someone to simply use your connection, means giving them full root access.
The backdoor is not accessible from the Guest Network, so if you are going to allow someone to use your wireless, at least give them only the Guest Network.

USB car audio crash

All of a sudden, the Sony car stereo of my Ford C-Max refused to read the USB Flash Drive I've been using for more than a year.



The USB stick was untouched for a long time, no new tunes were added and I don't even remember the last time I've pulled it out of the plug.
The display was struck on the name of the last song played and every attempt of changing song resulted in an endless "Loading Data" screen.

Even the classic joke of exit and re-enter the car, gave no results :-)

The USB stick was perfectly readable on a PC, songs were not corrupted and played flawlessy on my home stereo.
I even reformatted it and loaded back all the songs, but the result was the same.

As a last resort I tried another USB stick: the car stereo went back to life, and after that, even the original USB stick worked again.

2012-01-05

Netgear Genie... oh really?

A runner up for the first place in the User Interface Bad Design Contest: the Netgear Genie.
I was setting up wifi scheduling as I did on my old router, but I've found that the schedules were off by one hour.
No big deal, maybe the router defaulted to GMT, but where did they put the time settings?
Maybe under Administration?
Even Advanced Setup would be somewhat logical...
But no... it seems that to Netgear engineers, time belongs to security.



2012-01-04

Netgear WNDR3800 switch performance

I'm trying the WNDR3800.
Some reviews are reporting less than stellar performance on the gigabit switch.
I've done some testing myself.
Using 2 linux pcs, with gigabit ethernet ports, I've put the first in receiving mode:

# nc -l 1999 >/dev/null

and then I started sending data from the second one:

# cat /dev/zero | nc 192.168.1.2 1999

The result is well over 110 MB/s:



Then, I've repeated the test using a straight cable connection between the two machines:


The result is pretty much the same, so the switch part of the WNDR3800 does not significantly impact performances.

2012-01-01

Realtime monitoring of syslog messages

Swatch is perl script that continuously monitor log files and acts upon patterns that may show up.
Based on some previous work, I wrote some scripts to use it as a daemon.

The following packages are needed from the EPEL repositories:
swatch-3.2.3-2.el5.noarch.rpm
perl-Mail-Sendmail-0.79-9.el5.1.noarch.rpm

While these are from the base repositories
perl-DateManip
perl-Date-Calc
perl-TimeDate

Here is the /etc/init.d/swatch

#!/bin/sh
#
# swatch: watch system log
#
# chkconfig: 345 10 99
# description: The Simple WATCHer is an automated monitoring tool \
# that is capable of alerting system administrators \
# of anything that matches the patterns described \
# in the configuration file, whilst constantly searching \
# logfiles using perl.
#
# processname: swatch
# config: /etc/sysconfig/swatch/swatch
# pidfile: /var/run/swatch.pid

CHECK_LOG="undefined_logfile"
SWATCH_CONF="undefined_conf"
SWATCH_BIN="/usr/bin/swatch"
SWATCH_PID_FILE="/var/run/swatch.pid"
SWATCH_SCRIPTDIR="/var/run"
SWATCH_LOG="/var/log/swatch"

. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/swatch/swatch ]; then
        . /etc/sysconfig/swatch/swatch
else
        echo "/etc/sysconfig/swatch/swatch does not exists."
        exit 0
fi

if [ ! -x ${SWATCH_BIN} ]; then
        echo "File ${SWATCH_BIN} not installed!"
        exit 0
fi

if [ ! -f ${SWATCH_CONF} ]; then
        echo "File ${SWATCH_CONF} does not exist."
        exit 0
fi

prog=swatch
RETVAL=0

start() {
        echo -n $"Starting $prog: "
        daemon "$SWATCH_BIN --daemon -c $SWATCH_CONF -t $CHECK_LOG --pid-file=$SWATCH_PID_FILE --script-dir=$SWATCH_SCRIPTDIR >>$SWATCH_LOG"
        RETVAL=$?
        if [ $RETVAL = 0 ]; then
                success
        else
                failure
        fi
        echo
        return $RETVAL
}

stop() {
        echo -n $"Stopping $prog: "
        killproc "$SWATCH_BIN"
        RETVAL=$?
        if [ $RETVAL = 0 ]; then
                success
        else
                failure
        fi
        echo
        return $RETVAL
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        status)
                status $prog
                RETVAL=$?
                ;;
        restart)
                stop
                start
                RETVAL=$?
                ;;
        *)
                echo $"Usage: $0 {start|stop|status|restart}"
                exit 1
                ;;
esac

exit $RETVAL

The config files:
Where to watch: /etc/sysconfig/swatch/swatch

# log to watch
CHECK_LOG="/var/log/messages"

# regular expressions
SWATCH_CONF="/etc/sysconfig/swatch/swatchrc"

What to watch: /etc/sysconfig/swatch/swatchrc

# swatch config
watchfor   /regex_to_watch/
        mail addresses=user\@domain,subject=swatch_alert

And the logrotate stuff: /etc/logrotate.d/swatch

/var/log/swatch {
    postrotate
        /etc/init.d/swatch restart 2> /dev/null > /dev/null || true
    endscript
}

WiFi toggle on Asus WL-550gE


I don't feel confortable sleeping with my wifi on, so here is a script to turn it off at night:

First I created 2 scripts, one to turn it off:

# vi /root/wifi-off

#!/bin/sh
 
uci set wireless.@wifi-device[0].disabled=1
wifi
echo wifi disabled

And one to turn it back on:

# vi /root/wifi-on

#!/bin/sh
 
uci set wireless.@wifi-device[0].disabled=0
wifi
echo wifi enabled


Then I started up wifi at boot

# vi /etc/rc.local

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

/root/wifi-on

exit 0


Crontab:

# crontab -e

 0  7 * * * /root/wifi-on
59 23 * * * /root/wifi-off


The cron service is not enabled by default in OpenWRT:

# /etc/init.d/cron enable
# /etc/init.d/cron start

Good night...