Ubuntu Linux: Install RT2870 Chipset Based USB Wireless Adapter

/* Posted January 20th, 2011 at 1:32am [Comments: none]    */
/* Filed under Linux    */

This blog post listed Linux Compatible USB wireless adapters. It seems that many new Linux users frequently have problems learning how to install RT2870 driver under Linux. I also received email requesting installation instructions for the same device. This quick tutorial will explains how to install RT2870 based chipset device with WPA2 authentication and TKIP wireless encryption.

Our Sample Setup

The following instructions are tested on:

  • Ubuntu Linux 10.04.1 LTS
  • Kernel – Linux 2.6.32-24-generic-pae i686 (32 bit)
  • WPA2 with Linksys 160N router

RT2870 Chipset Based Devices Are Not Working Out Of Box

The main problem is conflicting driver which are shipped with default kernel. WPA2 is a method of security wireless networking with optional PSK for home users. The default driver only recognizes driver but always failed to join WPA2 based network. The solution is to install RT2870 driver from the vendor site.

Step #1: Disable Default Drivers

Type the following command to black list default drivers:
$ sudo vi /etc/modprobe.d/blacklist.conf
Append the following driver names:

blacklist rt2800usb
blacklist rt2x00lib
blacklist rt2x00usb

Save and close the file. Use the rmmod command to remove current drivers or just reboot the system:
$ sudo modprobe -r driverName
# you need to remove all of the above drivers one by one:
$ sudo modprobe -r rt2800usb

OR simply reboot the systems:
$ sudo reboot

Step 2: Install Compilers

Type the following command to install required packages so that you can compile source code:
$ sudo apt-get install build-essential fakeroot dpkg-dev
Finally, install Linux kernel headers so that you can compile kernel device drivers:
$ sudo apt-get install linux-headers-$(uname -r)

Step #3: Download Driver

Visit this page and download USB drivers [RT2870USB(RT2870/RT2770)].

Untar Tarball

Type the following command:
$ tar -jxvf 2010_0709_RT2870_Linux_STA_v2.4.0.1.tar.bz2
$ cd 2010_0709_RT2870_Linux_STA_v2.4.0.1

Compile RT2870 Wireless Lan Linux Driver

First, edit config.mk file as follows so that Network Manager can be used to set WPA2 auth info:
$ vi os/linux/config.mk
Set it as follows:

# Support Wpa_Supplicant

# Support Native WpaSupplicant for Network Manger

Save and close the file. To compile the driver, enter:
$ make
Sample outputs:

make -C tools
make[1]: Entering directory `/tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/tools'
gcc -g bin2h.c -o bin2h
make[1]: Leaving directory `/tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/tools'
cp -f os/linux/Makefile.6 /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/Makefile
make -C /lib/modules/2.6.32-24-generic-pae/build SUBDIRS=/tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-24-generic-pae'
  CC [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/crypt_md5.o
  CC [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/crypt_sha2.o
  CC [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/crypt_hmac.o
  CC [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/crypt_aes.o

  CC [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/rtusb_io.o
  CC [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/rtusb_bulk.o
  CC [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/rtusb_data.o
  CC [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/cmm_data_usb.o
  CC [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/ee_prom.o
  CC [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/rtmp_mcu.o
  CC [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/rtusb_dev_id.o
  CC [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../os/linux/rt_usb.o
  CC [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../os/linux/rt_usb_util.o
  CC [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../os/linux/usb_main_dev.o
  LD [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/rt2870sta.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/rt2870sta.mod.o
  LD [M]  /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/rt2870sta.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-24-generic-pae'

Note: You may see a LOTs of warnings during the compilation, and this is *normal* so don’t panic.

Install Driver

Type the following command:
$ sudo make install
Sample outputs:

make -C /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux -f Makefile.6 install
make[1]: Entering directory `/tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux'
rm -rf /etc/Wireless/RT2870STA
mkdir /etc/Wireless/RT2870STA
cp /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/RT2870STA.dat /etc/Wireless/RT2870STA/.
install -d /lib/modules/2.6.32-24-generic-pae/kernel/drivers/net/wireless/
install -m 644 -c rt2870sta.ko /lib/modules/2.6.32-24-generic-pae/kernel/drivers/net/wireless/
/sbin/depmod -a 2.6.32-24-generic-pae
make[1]: Leaving directory `/tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux'

Install Latest Firmware

Again visit this page and download “Firmware RT28XX/RT30XX USB series (RT2870/RT2770/RT3572/RT3070)”. Unzip and install the firemware:
$ unzip RT2870_Firmware_V22.zip
$ cd RT2870_Firmware_V22/
#### Make a backup of existing old firmware ####
$ mkdir -p $HOME/backup/lib/firmware
$ cp /lib/firmware/rt2870.bin $HOME/backup/lib/firmware
#### Install the firmware (for 64 bit Linux systems, you may have to use /lib64/firmware) #####
$ sudo cp rt2870.bin /lib/firmware/
##### **** backup and move existing driver, do NOT SKIP this STEP ****######
$ sudo mv /lib/modules/$(uname -r)/kernel/drivers/net/wireless/rt2870sta.ko $HOME/backup/

Update usb.ids

Type the following commands:
$ mkdir -p $HOME/backup/var/lib/usbutils
$ cp /var/lib/usbutils/usb.ids $HOME/backup/var/lib/usbutils
$ sudo wget -O /var/lib/usbutils/usb.ids http://www.linux-usb.org/usb.ids

Step #4: Configure Driver

Connect your USB device and type the following command to verify that Wireless USB LAN adapter is detected:
$ lsusb
Sample outputs:

Bus 002 Device 007: ID 0411:00e8 MelCo., Inc. Buffalo WLI-UC-G300N Wireless LAN Adapter
Bus 002 Device 006: ID 05ac:0220 Apple, Inc. Aluminum Keyboard (ANSI)
Bus 002 Device 005: ID 05ac:1006 Apple, Inc. Hub in Aluminum Keyboard
Bus 002 Device 004: ID 413c:2513 Dell Computer Corp.
Bus 002 Device 003: ID 413c:2513 Dell Computer Corp.
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 007: ID 413c:8160 Dell Computer Corp.
Bus 001 Device 006: ID 413c:8162 Dell Computer Corp.
Bus 001 Device 005: ID 413c:8161 Dell Computer Corp.
Bus 001 Device 004: ID 0a5c:4500 Broadcom Corp. BCM2046B1 USB 2.0 Hub (part of BCM2046 Bluetooth)
Bus 001 Device 003: ID 0a5c:5800 Broadcom Corp. BCM5880 Secure Applications Processor
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

/etc/Wireless/RT2870STA/RT2870STA.dat Configuration

You need to edit /etc/Wireless/RT2870STA/RT2870STA.dat file, enter:
$ sudo vi /etc/Wireless/RT2870STA/RT2870STA.dat
Set SSID (nixcraft is my SSID):


Set country (IN = INDIA, US = USA, etc):


Set authentication information (do not skip this if you want WPA2 based authentication):


See README_STA for other detailed information about each field. Save and close the file.

Step #5: Connect To the Internet

Type the ifconfig command and you should see ra0:
$ ifconfig ra0

ra0       Link encap:Ethernet  HWaddr 00:1d:73:bc:e4:6e
          inet6 addr: fe80::21d:73ff:febc:e46e/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:5157 errors:0 dropped:0 overruns:0 frame:0
          TX packets:206 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1093810 (1.0 MB)  TX bytes:16772 (16.7 KB)

You can now connect to the Internet by clicking on Network manager ( The network-manager is the one which is found in the systray. The icon of two computers, one below to the other on the left-side). Clicking on NM-applet will give you the types of connection/hardware you have available Select Wireless Device Select nixcraft SSID (or scan of SSID) Make sure you set “WPA2″ as wireless security. Once connected you can browse the Internet or verify IP info:
$ ifconfig ra0
Sample outputs:

ra0       Link encap:Ethernet  HWaddr 00:1d:73:bc:e4:6e
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::21d:73ff:febc:e46e/64 Scope:Link
          RX packets:6711 errors:0 dropped:0 overruns:0 frame:0
          TX packets:271 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1420879 (1.4 MB)  TX bytes:22312 (22.3 KB)

Verify gateway or just ping to public ip:
$ route -n
$ ping google.com
$ ping cyberciti.biz

A Note About Kernel Upgrades

You need to reinstall the driver using the above steps.

Further readings:

Featured Articles:


Download Ubuntu 10.10 (Maverick Meerkat) CD ISO / DVD Images

/* Posted January 18th, 2011 at 1:31am [Comments: none]    */
/* Filed under Linux    */

The latest version of the popular Linux desktop distribution Ubuntu 10.10 has been released and available from the official project web site. New features since Ubuntu 10.04 includes – Gnome 2.32, KDE 4.5.0 (QT 4.7), new KDE browser Rekonq, Pulse Audio as the default sound server, Firefox 3.6.9, OpenOffice 3.2.1, Evolution 2.30.3, Shotwell, Btrfs with experimental support, kernel 2.6.35, and X.org version 1.9.

Fig.01: Ubuntu 10.10 (Maverick Meerkat) Desktop

Fig.01: Ubuntu 10.10 (Maverick Meerkat) Desktop

Download Ubuntu 10.10

Ubuntu (Maverick Meerkat) 10.10 DVD

  1. 64 Bit DVD version
  2. 32 Bit DVD version

How Do I Upgrade To Ubuntu v10.10?

You can directly upgrade to Ubuntu 10.10 from Ubuntu 10.04, see upgrade howto here.

Featured Articles:


HowTo: Use Bash Parameter Substitution Like A Pro

/* Posted January 16th, 2011 at 1:31am [Comments: none]    */
/* Filed under Linux    */

The $ character is used for parameter expansion, and command substitution. You can use it for manipulating and/or expanding variables on demands without using external commands such as sed or awk.

#1: Getting Up Default Shell Variables Value

The syntax is as follows:


If parameter not set, use defaultValue. In this example, your shell script takes arguments supplied on the command line. You’d like to provide default value so that the most common value can be used without needing to type them every time. If variable $1 is not set or passed, use root as default value for u:


Consider the following example:

echo "Setting php-cgi at ${_jail_dir}..."
# rest of the script ...

You can now run this script as follows:

./script.sh /jail              # --- set php jail at /jail dir
./script.sh /home/httpd/jail   # ---- set php jail at /home/httpd/jail dir
./script.sh                    # --- set php jail dir at /home/phpcgi (default)

Here is another handy example:

        local d="$1"               # get dir name
        local p=${2:-0755}      # get permission, set default to 0755
        [ $# -eq 0 ]  { echo "$0: dirname"; return; }
        [ ! -d "$d" ]  mkdir -m $p -p "$d"

Use this substitution for creating failsafe functions and providing missing command line arguments in scripts.

#1.1: Setting Default Values

The syntax is as follows:


The assignment (:=) operator is used to assign a value to the variable if it doesn’t already have one. Try the following examples:

echo $USER

Sample outputs:


Now, assign a value foo to the $USER variable if doesn’t already have one:

echo ${USER:=foo}

Sample outputs:


Unset value for $USER:

unset USER
echo ${USER:=foo}

Sample outputs:


This make sure you always have a default reasonable value for your script.

Tip: ${var:-defaultValue} vs ${var:=defaultValue}

Please note that it will not work with positional parameter arguments:

var=${1:=defaultValue}  ### FAIL with an error cannot assign in this way
var=${1:-defaultValue}    ### Perfect 

#2: Display an Error Message If $VAR Not Passed

If the variable is not defined or not passed, you can stop executing the Bash script with the following syntax:

${varName?Error varName is not defined}
${varName:?Error varName is not defined or is empty}
${1:?"mkjail: Missing operand"}
MESSAGE="Usage: mkjail.sh domainname IPv4"             ### define error message
_domain=${2?"Error: ${MESSAGE}"}  ### you can use $MESSAGE too

This is used for giving an error message for unset parameters. In this example, if the $1 command line arg is not passed, stop executing the script with an error message:

_domain="${1:?Usage: mknginxconf domainName}"

Here is a sample script:

# Purpose: Wrapper script to setup Nginx Load Balancer
# Author: Vivek Gite
_domain="${1:?Usage: mknginxconf domainName}"     ### die if domainName is not passed ####
[ ! -f $_db ]  { echo "$0: Error $_db file not found."; exit 1; }
line=$(grep "^${_domain}" $_db) || { echo "$0: Error $_domain not found in $_db."; exit 2; }
# Get domain config info into 4 fields:
# f1 - Domain Name|
# f2 - IPv4Vip:httpPort:HttpsPort, IPv6Vip:httpPort:HttpsPort|
# f3 - PrivateIP1:port1,PrivateIP2,port2,...PrivateIPN,portN|
# f4 - LB Type (true [round robin] OR false [session])
# -------------------------------------------------------------------------------
read -r f1 f2 f3 f4  "$line"
# Do we want ssl host config too?
set -- $f2
[ "$3" == "443" ]  ssl="true"
# Build query
# Call our master script to setup nginx reverse proxy / load balancer (LB) for given domain name
$_setup "$d" $ips

#2.1: Display an Error Message and Run Command

If $2 is not set display an error message for $2 parameter and run cp command on fly as follows:

_message="Usage: chkfile commandname"
# Run another command (compact format)
_cmd="${2:? $_message $(cp $_file $HOME/.output)}"
$_cmd "$_file"

#3: Find Variable Length

You can easily find string length using the following syntax:

echo ${#variableName}

Here is a sample shell script to add a ftp user:

# Usage : Add a ftp user
# die if username/password not provided
[ $# -ne 2 ]  { echo "Usage: addftpuser username password"; exit 1;}
# Get username length and make sure it always = 8
[[ ${#_fuser} -ge 9 ]]  { echo "Error: Username should be maximum 8 characters in length. "; exit 2;}
# Check for existing user in /etc/passwd
/usr/bin/getent passwd "${_fuser}" /dev/null
# Check exit status
[ $? -eq 0 ]  { echo "Error: FTP username "${_fuser}" exists."; exit 3; }
# Add user
/sbin/useradd -s /sbin/nologin -m  "${_fuser}"
echo "${_fpass}" | /usr/bin/passwd "${_fuser}" --stdin

Each Linux or UNIX command returns a status when it terminates normally or abnormally. You can use command exit status in the shell script to display an error message or take some sort of action. In above example, if getent command is successful, it returns a code which tells the shell script to display an error message. 0 exit status means the command was successful without any errors. $? holds the return value set by the previously executed command.

#4: Remove Pattern (Front of $VAR)

The syntax is as follows:


You can strip $var as per given pattern from front of $var. In this example remove /etc/ part and get a filename only, enter:

echo ${f#/etc/}

The first syntax removes shortest part of pattern and the second syntax removes the longest part of the pattern. Consider the following example:


You just want to get filename i.e. dnstop-20090128.tar.gz, enter (try to remove shortest part of $_url) :

echo "${_url#*/}"

Sample outputs:


Now try using the longest part of the pattern syntax:

echo "${_url##*/}"

Sample outputs:


This is also useful to get a script name without using /bin/basename:

echo "$_self is called"

Create a script called master.info as follows:

# Purpose: Display jail info as per softlink
# Author: Vivek Gite
# find out script name
[ "$VERBOSE" == "1" ]  echo "Called as $_self for "$_j" domain(s)"
for j in $_j
	export _DOMAIN_NAME=$j
	source functions.sh
        # call appropriate functions as per script-name / softlink
	case $_self in
		uploaddir.info) echo "Upload dir for $j: $(get_domain_upload_dir)" ;;
		tmpdir.info) echo "/tmp dir for $j: $(get_domain_tmp_dir)" ;;
                mem.info) echo "$j domain mem usage (php+lighttpd): $(get_domain_mem_info)" ;;
                cpu.info) echo "$j domain cpu usage (php+lighttpd): $(get_domain_cpu_info)" ;;
                user.info) echo "$j domain user and group info: $(get_domain_users_info)" ;;
                diskquota.info) echo "$j domain disk quota info (mysql+disk): $(get_domain_diskquota_info)" ;;
		*) warn "Usage: $_self"

Finally, create softlink as follows:
# ln -s master.info uploaddir.info
# ln -s master.info tmpdir.info
# ln -s master.info mem.info

You can now call script as follows:
# ./mem.info example.org
# ./cpu.info example.com example.net

#4.1: Remove Pattern (Back of $VAR)

The syntax is as follows:


Exactly the same as above, except that it applies to the back of $var. In this example remove .tar.gz from $FILE, enter:

echo ${FILE%.tar.gz}

Sample outputs:


Rename all *.perl files to *.pl using bash for loop as Apache web server is configured to only use .pl file and not .perl file names:

for p in /scripts/projects/.devl/perl/*.perl
	mv "$p" "${p%.perl}.pl"

You can combine all of them as follows to create a build scripts:

# Usage: Build suhosin module for RHEL based servers
# Author: Vivek Gite
# ----
# Set default value for $2
# Get tar ball names
# Remove .tgz and get dir name
# Download software
wget $URL -O "${DLHOME}/$FILE"
wget $vURL -O "${DLHOME}/$vFILE"
# Extract it
tar -zxvf $FILE
cd "$DEST"
# Build it and install it
phpize --clean  phpize  ./configure  make  read -p "Update/Install $SOFTWARE [Y/n] ? " answer
shopt -s nocasematch
[[ $answer =~ y|es  ]]  make install
shopt -u nocasematch

If you turn on nocasematch option, shell matches patterns in a case-insensitive fashion when performing matching while executing case or [[ conditional expression.

#5: Find And Replace

The syntax is as follows:


Find word unix and replace with linux, enter:

x="Use unix or die"
sed 's/unix/linux' $x

You can avoid using sed as follows:

echo "${x/unix/linux}"
echo "${out}"

To replace all matches of pattern, enter :


You can use this to rename or remove files on fly

cp "${y}" "${y/.conf/.conf.bak}"

Here is another example:

         # RHEL php modules path
	for i in $_php_modules/*
		p="${i##*/}"                  ## Get module name
		ini="/etc/php.d/${p/so/ini}"  ## Get ini file by replacing .so with .ini extension
                # make sure file exists
		[ ! -f "$ini" ]  echo “$i php module exists but $ini file not found.”

The following function installs required modules in chrooted php-cgi process

        # get jail name
	local n="${_chrootbase}/${d##/}"
	local p=""
	local ini=""
        # enable only ${_php_modules_enabled} php modules and delete other .ini files if exists in jail
	for i in $_php_modules/*
                # find out if module is enabled or not
		if [[ ${_php_modules_enabled} = *${p}*   ]]
			[ "$VERBOSE" == "1" ]  echo " [+] Enabling php module $p"
			$_cp -f "$i" "$n/${_php_modules##/}"      ## install it
			copy_shared_libs "$i"                     ## get shared libs in jail too
			[ -f "${ini}" ]  $_rm -f "${ini}"	  ## if old .ini exists in jail, just delete it

#6: Substring Starting Character

The syntax is as follows:


Expands to up to length characters of parameter starting at the character specified by offset.

#### strip extra slash from $file  ####

Extract craft word only:

echo ${x:3:5}"

To extract phone number, enter:

# strip std code
echo "${phone:4}"

Summary: String Manipulation and Expanding Variables

For your ready references here are all your handy bash parameter substitution operators. Try them all; enhance your scripting skills like a pro:


Update: Oct/14/2010 - I had some problem with mysql database, this is an older version restored from the cache and backup. I'm afraid that we lost all comments related to this post.

Featured Articles:


Download Fedora 14 CD / DVD ISO

/* Posted January 14th, 2011 at 1:31am [Comments: none]    */
/* Filed under Linux    */

Fedora Linux version 14 has been released and available for download ( jump to download link ). Fedora Linux is a community-based Linux distribution. Fedora is sponsored by Red Hat, Inc. Fedora is considered as the second most popular distro, behind Ubuntu Linux for desktop and laptop usage.

Fig.01: Fedora Linux v.14 desktop (image credit: wikipedia)

Fig.01: Fedora Linux v.14 desktop (image credit: wikipedia)

What’s New In Fedora 14

The new features in Fedora Linux ver. 14 are:

  • Updated Boost to the upstream 1.44 release
  • Addition of the D compiler (LDC) and D standard runtime library (Tango)
  • Concurrent release of Fedora 14 on the Amazon EC2 cloud
  • Updated Fedora’s Eclipse stack to Helios releases
  • Replacement of libjpeg with libjpeg-turbo
  • Inclusion of virt-v2v tool
  • Inclusion of Spice framework for VDI deployment
  • Updates to Rakudo Star implementation of Perl 6
  • NetBeans IDE updated to the 6.9 release
  • Inclusion of ipmiutil system management tool
  • Inclusion of a tech preview of the GNOME Shell environment

Fedora 14 Download

You can download Fedora Linux 14 via the web/ftp server or via BitTorrent (recommended).

32 bit vs 64 bit Fedora 14 Version

  • For almost all PCs select 32 bit version. For e.g., most machines with Intel/AMD/etc type processors. Good for desktop usage. Almost all multimedia plugins and software works with 32bit edition.
  • Choose 64 bit version to take full advantage of computers based on the AMD64 or EM64T architecture (e.g., Athlon64, Opteron, EM64T Xeon, Core 2 Due, Core 2 Quad, and so on). For servers and advanced feature such as hardware error detection, access to more than 4GB RAM and so on; use 64bit version.

Fedora 14 DVD ISO download

Fedora download: Fedora 14 CD ISO download

There are total 5 ISO images (5 CDs):

Fedora Linux 14 DVD ISO BitTorrent download

Download images from the following mirror:

Fedora 14 DVD ISO BitTorrent download

See complete list of torrents here .

Fedora Linux 14 Download Mirrors

Featured Articles:


Linux / UNIX Desktop Fun: Terminal ASCII Aquarium

/* Posted January 12th, 2011 at 1:30am [Comments: none]    */
/* Filed under Linux    */

You can now enjoy mysteries of the sea from the safety of your own terminal using ASCIIQuarium. It is an aquarium/sea animation in ASCII art created using perl.

Install Term::Animation

First, you need to install Perl module called Term-Animation. Open a command-line terminal (select Applications Accessories Terminal), and then type:
$ sudo apt-get install libcurses-perl
$ cd /tmp
$ wget http://search.cpan.org/CPAN/authors/id/K/KB/KBAUCOM/Term-Animation-2.4.tar.gz
$ tar -zxvf Term-Animation-2.4.tar.gz
$ cd Term-Animation-2.4/
$ perl Makefile.PL make make test
$ sudo make install

Download and Install ASCIIQuarium

While still at bash prompt, type:
$ cd /tmp
$ wget http://www.robobunny.com/projects/asciiquarium/asciiquarium.tar.gz
$ tar -zxvf asciiquarium.tar.gz
$ cd asciiquarium_1.0/
$ sudo cp asciiquarium /usr/local/bin
$ sudo chmod 0755 /usr/local/bin/asciiquarium

How do I view my ASCII Aquarium?

Simply type the following command:
$ /usr/local/bin/asciiquarium
$ perl /usr/local/bin/asciiquarium

(Fig.01: ASCII Aquarium [ click to enlarge ] )

Download: KDE and Mac OS X Version

Download – If you’re running Mac OS X, try a packaged version that will run out of the box. For KDE users, try a KDE Screensaver based on the Asciiquarium.

Featured Articles:


Linux Commands For Shared Library Management & Debugging Problem

/* Posted January 9th, 2011 at 11:10pm [Comments: none]    */
/* Filed under Linux    */

If you are a developer, you will re-use code provided by others. Usually /lib, /lib64, /usr/local/lib, and other directories stores various shared libraries. You can write your own program using these shared libraries. As a sys admin you need to manage and install these shared libraries. Use the following commands for shared libraries management, security, and debugging problems.

What is a Library In Linux or UNIX?

In Linux or UNIX like operating system, a library is noting but a collection of resources such as subroutines / functions, classes, values or type specifications. There are two types of libraries:

  1. Static libraries – All lib*.a fills are included into executables that use their functions. For example you can run a sendmail binary in chrooted jail using statically liked libs.
  2. Dynamic libraries or linking [ also known as DSO (dynamic shared object)] – All lib*.so* files are not copied into executables. The executable will automatically load the libraries using ld.so or ld-linux.so.

Linux Library Management Commands

  1. ldconfig : Updates the necessary links for the run time link bindings.
  2. ldd : Tells what libraries a given program needs to run.
  3. ltrace : A library call tracer.
  4. ld.so/ld-linux.so: Dynamic linker/loader.

Important Files

As a sys admin you should be aware of important files related to shared libraries:

  1. /lib/ld-linux.so.* : Execution time linker/loader.
  2. /etc/ld.so.conf : File containing a list of colon, space, tab, newline, or comma separated directories in which to search for libraries.
  3. /etc/ld.so.cache : File containing an ordered list of libraries found in the directories specified in /etc/ld.so.conf. This file is not in human readable format, and is not intended to be edited. This file is created by ldconfig command.
  4. lib*.so.version : Shared libraries stores in /lib, /usr/lib, /usr/lib64, /lib64, /usr/local/lib directories.

#1: ldconfig command

You need to use the ldconfig command to create, update, and remove the necessary links and cache (for use by the run-time linker, ld.so) to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/usr/lib, /lib64 and /lib). The ldconfig command checks the header and file names of the libraries it encounters when determining which versions should have their links updated. This command also creates a file called /etc/ld.so.cache which used to speed linking.


In this example, you’ve installed a new set of shared libraries at /usr/local/lib/:
$ ls -l /usr/local/lib/
Sample outputs:

-rw-r--r-- 1 root root 878738 Jun 16  2010 libGeoIP.a
-rwxr-xr-x 1 root root    799 Jun 16  2010 libGeoIP.la
lrwxrwxrwx 1 root root     17 Jun 16  2010 libGeoIP.so - libGeoIP.so.1.4.6
lrwxrwxrwx 1 root root     17 Jun 16  2010 libGeoIP.so.1 - libGeoIP.so.1.4.6
-rwxr-xr-x 1 root root 322776 Jun 16  2010 libGeoIP.so.1.4.6
-rw-r--r-- 1 root root  72172 Jun 16  2010 libGeoIPUpdate.a
-rwxr-xr-x 1 root root    872 Jun 16  2010 libGeoIPUpdate.la
lrwxrwxrwx 1 root root     23 Jun 16  2010 libGeoIPUpdate.so - libGeoIPUpdate.so.0.0.0
lrwxrwxrwx 1 root root     23 Jun 16  2010 libGeoIPUpdate.so.0 - libGeoIPUpdate.so.0.0.0
-rwxr-xr-x 1 root root  55003 Jun 16  2010 libGeoIPUpdate.so.0.0.0

Now when you run an app related to libGeoIP.so, you will get an error about missing library. You need to run ldconfig command manually to link libraries by passing them as command line arguments with the -l switch:
# ldconfig -l /path/to/lib/our.new.lib.so
Another recommended options for sys admin is to create a file called /etc/ld.so.conf.d/geoip.conf as follows:


Now just run ldconfig to update the cache:
# ldconfig
To verify new libs or to look for a linked library, enter:
# ldconfig -v
# ldconfig -v | grep -i geoip

Sample outputs:

	libGeoIP.so.1 - libGeoIP.so.1.4.6
	libGeoIPUpdate.so.0 - libGeoIPUpdate.so.0.0.0

Troubleshooting Chrooted Jails

You can print the current cache with the -p option:
# ldconfig -p
Putting web server such as Apache / Nginx / Lighttpd in a chroot jail minimizes the damage done by a potential break-in by isolating the web server to a small section of the filesystem. It is also necessary to copy all files required by Apache inside the filesystem rooted at /jail/ directory , including web server binaries, shared Libraries, modules, configuration files, and php/perl/html web pages. You need to also copy /etc/{ld.so.cache,ld.so.conf} files and /etc/ld.so.conf.d/ directory to /jail/etc/ directory. Use the ldconfig command to update, print and troubleshoot chrooted jail problems:

### chroot to jail bash
chroot /jail /bin/bash
###  now update the cache in /jail ###
###  print the cache in /jail ###
ldconfig -p
### copy missing libs ###
cp /path/to/some.lib /jail/path/to/some.lib
ldconfig -v | grep some.lib
### get out of jail ###
### may be delete bash and ldconfig to increase security (NOTE path carefully) ###
cd /jail
rm sbin/ldconfig bin/bash
### now start nginx jail ###
chroot /jail /usr/local/nginx/sbin/nginx


A rootkit is a program (or combination of several programs) designed to take fundamental control of a computer system, without authorization by the system’s owners and legitimate managers. Usually, rootkit use /lib, /lib64, /usr/local/lib directories to hide itself from real root users. You can use ldconfig command to view all the cache of all shared libraries and unwanted programs:
# /sbin/ldconfig -p | less
You can also use various tools to detect rootkits under Linux.

Common errors

You may see the errors as follows:

Dynamic linker error in foo
Can’t map cache file cache-file
Cache file cache-file foo

All of the above errors means the linker cache file /etc/ld.so.cache is corrupt or does not exists. To fix these errors simply run the ldconfig command as follows:
# ldconfig

Can’t find library xyz Error

The executable required a dynamically linked library that ld.so or ld-linux.so cannot find. It means a library called xyz needed by the program called foo not installed or path is not set. To fix this problem install xyz library and set path in /etc/ld.so.conf file or create a file in /etc/ld.so.conf.d/ directory.

#2: ldd command

ldd (List Dynamic Dependencies) is a Unix and Linux program to display the shared libraries required by each program. This tools is required to build and run various server programs in a chroot jail. A typical example is as follows to list the Apache server shared libraries, enter:
# ldd /usr/sbin/httpd
Sample outputs:

	libm.so.6 = /lib64/libm.so.6 (0x00002aff52a0c000)
	libpcre.so.0 = /lib64/libpcre.so.0 (0x00002aff52c8f000)
	libselinux.so.1 = /lib64/libselinux.so.1 (0x00002aff52eab000)
	libaprutil-1.so.0 = /usr/lib64/libaprutil-1.so.0 (0x00002aff530c4000)
	libcrypt.so.1 = /lib64/libcrypt.so.1 (0x00002aff532de000)
	libldap-2.3.so.0 = /usr/lib64/libldap-2.3.so.0 (0x00002aff53516000)
	liblber-2.3.so.0 = /usr/lib64/liblber-2.3.so.0 (0x00002aff53751000)
	libdb-4.3.so = /lib64/libdb-4.3.so (0x00002aff5395f000)
	libexpat.so.0 = /lib64/libexpat.so.0 (0x00002aff53c55000)
	libapr-1.so.0 = /usr/lib64/libapr-1.so.0 (0x00002aff53e78000)
	libpthread.so.0 = /lib64/libpthread.so.0 (0x00002aff5409f000)
	libdl.so.2 = /lib64/libdl.so.2 (0x00002aff542ba000)
	libc.so.6 = /lib64/libc.so.6 (0x00002aff544bf000)
	libsepol.so.1 = /lib64/libsepol.so.1 (0x00002aff54816000)
	/lib64/ld-linux-x86-64.so.2 (0x00002aff527ef000)
	libuuid.so.1 = /lib64/libuuid.so.1 (0x00002aff54a5c000)
	libresolv.so.2 = /lib64/libresolv.so.2 (0x00002aff54c61000)
	libsasl2.so.2 = /usr/lib64/libsasl2.so.2 (0x00002aff54e76000)
	libssl.so.6 = /lib64/libssl.so.6 (0x00002aff5508f000)
	libcrypto.so.6 = /lib64/libcrypto.so.6 (0x00002aff552dc000)
	libgssapi_krb5.so.2 = /usr/lib64/libgssapi_krb5.so.2 (0x00002aff5562d000)
	libkrb5.so.3 = /usr/lib64/libkrb5.so.3 (0x00002aff5585c000)
	libcom_err.so.2 = /lib64/libcom_err.so.2 (0x00002aff55af1000)
	libk5crypto.so.3 = /usr/lib64/libk5crypto.so.3 (0x00002aff55cf3000)
	libz.so.1 = /usr/lib64/libz.so.1 (0x00002aff55f19000)
	libkrb5support.so.0 = /usr/lib64/libkrb5support.so.0 (0x00002aff5612d000)
	libkeyutils.so.1 = /lib64/libkeyutils.so.1 (0x00002aff56335000)

Now, you can copy all those libs one by one to /jail directory

# mkdir /jail/lib
# cp  /lib64/libm.so.6 /jail/lib
# cp /lib64/libkeyutils.so.1 /jail/lib

You can write a bash script to automate the entire procedure:

        local d="$1"            # JAIL ROOT
        local pFILE="$2"        # copy bin file libs
        local files=""
	## use ldd to get shared libs list ###
        files="$(ldd $pFILE |  awk '{ print $3 }' | sed  '/^$/d')"
        for i in $files
          dcc="${i%/*}" # get dirname only
          [ ! -d ${d}${dcc} ]  mkdir -p ${d}${dcc}
          ${_cp} -f $i ${d}${dcc}
        # Works with 32 and 64 bit ld-linux
        sldl="$(ldd $pFILE | grep 'ld-linux' | awk '{ print $1}')"
        [ ! -f ${d}${sldl} ]  ${_cp} -f ${sldl} ${d}${sldlsubdir}

Call cp_support_shared_libs() it as follows:

cp_support_shared_libs "/jail" "/usr/local/nginx/sbin/nginx"

Report Missing Functions

Type the following command:
$ ldd -d /path/to/executable

Report Missing Objects

Type the following command:
$ ldd -r /path/to/executable

Determine If Particulate Feature Supported Or Not

TCP Wrapper is a host-based Networking ACL system, used to filter network access to Internet. TCP wrappers was original written to monitor and stop cracking activities on the UNIX / Linux systems. To determine whether a given executable daemon supports TCP Wrapper or not, run the following command:
$ ldd /usr/sbin/sshd | grep libwrap
Sample outputs:

	libwrap.so.0 = /lib64/libwrap.so.0 (0x00002abd70cbc000)

The output indicates that the OpenSSH (sshd) daemon supports TCP Wrapper.

Other usage of ldd command

You can use the ldd command when an executable is failing because of a missing dependency. Once you found a missing dependency, you can install it or update the cache with the ldconfig command as mentioned above.

#3: ltrace command

The ltrace command simply runs the specified command until it exits. It intercepts and records the dynamic library calls which are called by the executed process and the signals which are received by that process. It can also intercept and print the system calls executed by the program. Its use is very similar to strace command.
# ltrace /usr/sbin/httpd
# ltrace /sbin/chroot /usr/sbin/httpd
# ltrace /bin/ls

Sample outputs:

__libc_start_main(0x804fae0, 1, 0xbfbd6544, 0x805bce0, 0x805bcd0 
strrchr("/bin/ls", '/')                                                                                                                            = "/ls"
setlocale(6, "")                                                                                                                                   = "en_IN.utf8"
bindtextdomain("coreutils", "/usr/share/locale")                                                                                                   = "/usr/share/locale"
textdomain("coreutils")                                                                                                                            = "coreutils"
__cxa_atexit(0x8052d10, 0, 0, 0xbfbd6544, 0xbfbd6498)                                                                                              = 0
isatty(1)                                                                                                                                          = 1
getenv("QUOTING_STYLE")                                                                                                                            = NULL
getenv("LS_BLOCK_SIZE")                                                                                                                            = NULL
getenv("BLOCK_SIZE")                                                                                                                               = NULL
getenv("BLOCKSIZE")                                                                                                                                = NULL
getenv("POSIXLY_CORRECT")                                                                                                                          = NULL
getenv("BLOCK_SIZE")                                                                                                                               = NULL
getenv("COLUMNS")                                                                                                                                  = NULL
ioctl(1, 21523, 0xbfbd6470)                                                                                                                        = 0
getenv("TABSIZE")                                                                                                                                  = NULL
getopt_long(1, 0xbfbd6544, "abcdfghiklmnopqrstuvw:xABCDFGHI:"..., 0x0805ea40, -1)                                                                  = -1
__errno_location()                                                                                                                                 = 0xb76b8694
malloc(40)                                                                                                                                         = 0x08c8e3e0
memcpy(0x08c8e3e0, "", 40)                                                                                                                         = 0x08c8e3e0
output truncated
free(0x08c8e498)                                                                                                                                   = 
free(NULL)                                                                                                                                         = 
free(0x08c8e480)                                                                                                                                   = 
__fpending(0xb78334e0, 0xbfbd6334, 0xb78876a3, 0xb78968f8, 0)                                                                                      = 0
fclose(0xb78334e0)                                                                                                                                 = 0
__fpending(0xb7833580, 0xbfbd6334, 0xb78876a3, 0xb78968f8, 0)                                                                                      = 0
fclose(0xb7833580)                                                                                                                                 = 0
+++ exited (status 0) +++

The ltrace command is a perfect debugging utility in Linux:

  1. To monitor the library calls used by a program and all the signals it receives.
  2. For tracking the execution of processes.
  3. It can also show system calls, used by a program.

ltrace Command Examples

Consider the following c program:

#include stdio.h
int main(){
	printf("Hello worldn");
	return 0;

Compile and run it as follows:
$ cc hello.c -o hello
$ ./hello

Now use the ltrace command to tracking the execution of processes:
$ ltrace -S -tt ./hello
Sample outputs:

15:20:38.561616 SYS_brk(NULL)                                                                                                                      = 0x08f42000
15:20:38.561845 SYS_access("/etc/ld.so.nohwcap", 00)                                                                                               = -2
15:20:38.562009 SYS_mmap2(0, 8192, 3, 34, -1)                                                                                                      = 0xb7708000
15:20:38.562155 SYS_access("/etc/ld.so.preload", 04)                                                                                               = -2
15:20:38.562336 SYS_open("/etc/ld.so.cache", 0, 00)                                                                                                = 3
15:20:38.562502 SYS_fstat64(3, 0xbfaafe20, 0xb7726ff4, 0xb772787c, 3)                                                                              = 0
15:20:38.562629 SYS_mmap2(0, 76469, 1, 2, 3)                                                                                                       = 0xb76f5000
15:20:38.562755 SYS_close(3)                                                                                                                       = 0
15:20:38.564204 SYS_access("/etc/ld.so.nohwcap", 00)                                                                                               = -2
15:20:38.564372 SYS_open("/lib/tls/i686/cmov/libc.so.6", 0, 00)                                                                                    = 3
15:20:38.564561 SYS_read(3, "177ELF010101", 512)                                                                                            = 512
15:20:38.564694 SYS_fstat64(3, 0xbfaafe6c, 0xb7726ff4, 0xb7705796, 0x8048234)                                                                      = 0
15:20:38.564822 SYS_mmap2(0, 0x1599a8, 5, 2050, 3)                                                                                                 = 0xb759b000
15:20:38.565076 SYS_mprotect(0xb76ee000, 4096, 0)                                                                                                  = 0
15:20:38.565209 SYS_mmap2(0xb76ef000, 12288, 3, 2066, 3)                                                                                           = 0xb76ef000
15:20:38.565454 SYS_mmap2(0xb76f2000, 10664, 3, 50, -1)                                                                                            = 0xb76f2000
15:20:38.565604 SYS_close(3)                                                                                                                       = 0
15:20:38.565709 SYS_mmap2(0, 4096, 3, 34, -1)                                                                                                      = 0xb759a000
15:20:38.565842 SYS_set_thread_area(0xbfab030c, 0xb7726ff4, 0xb759a6c0, 1, 0)                                                                      = 0
15:20:38.566070 SYS_mprotect(0xb76ef000, 8192, 1)                                                                                                  = 0
15:20:38.566185 SYS_mprotect(0x08049000, 4096, 1)                                                                                                  = 0
15:20:38.566288 SYS_mprotect(0xb7726000, 4096, 1)                                                                                                  = 0
15:20:38.566381 SYS_munmap(0xb76f5000, 76469)                                                                                                      = 0
15:20:38.566522 __libc_start_main(0x80483e4, 1, 0xbfab04e4, 0x8048410, 0x8048400 
15:20:38.566667 puts("Hello world" 
15:20:38.566811 SYS_fstat64(1, 0xbfab0310, 0xb76f0ff4, 0xb76f14e0, 0x80484c0)                                                                      = 0
15:20:38.566936 SYS_mmap2(0, 4096, 3, 34, -1)                                                                                                      = 0xb7707000
15:20:38.567126 SYS_write(1, "Hello worldn", 12Hello world
)                                                                                                  = 12
15:20:38.567282  )                                                                                                               = 12
15:20:38.567348 SYS_exit_group(0 
15:20:38.567454 +++ exited (status 0) +++

You need to carefully monitor the order and arguments of selected functions such as open() [used to open and possibly create a file or device] or chown() [used to change ownership of a file] so that you can spot simple kinds of race conditions or security related problems. This is quite useful for evaluating the security of binary programs to find out what kind of changes made to the system.

ltrace: Debugging Memory I/O Usage For HA Based Cluster Computers

The ltrace command can be used to trace memory usage of the malloc() and free() functions in C program. You can calculate the amount of memory allocated as follows:
[node303 ~]$ ltrace -e malloc,free ./simulator arg1 agr2 arg3
The ltrace will start ./simulator program and it will trace the malloc() and free() functions. You can find out I/O problems as follows:
[node303 ~]$ ltrace -e fopen,fread,fwrite,fclose ./simulator arg1 agr2 arg3
You may need to change function names as your programming languages or UNIX platform may use different memory allocation functions.

#4: ld.so/ld-linux.so Command

The ld.so or / ld-linux.so used as follows by Linux:

  1. To load the shared libraries needed by a program.
  2. To prepare the program to run, and then runs it.

List All Dependencies and How They Are Resolved

Type the following command:
# cd /lib
For 64 bit systems:
# cd /lib64
Pass the –list option, enter:
# ./ld-2.5.so --list /path/to/executable

Other options

From the man page:

  --verify                   verify that given object really is a dynamically linked object we can handle
  --library-path PATH   use given PATH instead of content of the environment variable LD_LIBRARY_PATH
  --inhibit-rpath LIST    ignore RUNPATH and RPATH information in object names in LIST

Environment Variables

The LD_LIBRARY_PATH can be used to set a library path for finding dynamic libraries using LD_LIBRARY_PATH, in the standard colon seperated format:
$ export LD_LIBRARY_PATH=/opt/simulator/lib:/usr/local/lib
The LD_PRELOAD allow an extra library not specified in the executable to be loaded:
$ export LD_PRELOAD=/home/vivek/dirhard/libdiehard.so
Please note that these variables are ignored when executing setuid/setgid programs.

Recommend readings:

Featured Articles:


StarCraft Running on PS3

/* Posted February 27th, 2009 at 8:40am [Comments: 3]    */
/* Filed under How-To, Linux, PS3, Video Games, Windows    */

Think this is impressive? Want to play StarCraft on your PS3 as well? It’s definitely possible. The requirements? You need to take advantage of your PS3′s little known capability to run Linux. Linux you ask? Yes, because that’s the only way to run Windows. Since StarCraft came out way back in the day when Windows 95 was king, that’s all you need to install on top of Linux through an emulation layer. Fortunately, the PS3 has enough horsepower to run Windows 95, even via software emulation, so StarCraft is actually playable. Just imagine it, playing StarCraft on your big screen TV! Read more »


Download 101 Linux Hacks eBook PDF Free

/* Posted February 18th, 2009 at 10:56am [Comments: 12]    */
/* Filed under Linux, Reference    */


Not sure how long this will last, but if you use Linux regularly, you may be interested in Ramesh’ Natarajan’s eBook Linux 101 Hacks which is currently available for free download from his website at www.thegeekstuff.com. The password to get in is “linuxrocks” and the eBook itself is in PDF format. Subtitled “Practical Examples to Build a Strong Foundation in Linux,” the book is filled with detailed explanations on a variety of useful Linux commands and command options that you may or may not have heard of and “hacks” to make ones you use regularly more effective like a true Linux veteran.

Read more »


Compare Directories and File Content in Linux without Dircmp

/* Posted February 17th, 2009 at 12:28pm [Comments: 3]    */
/* Filed under How-To, Linux    */


Dircmp is a great Linux tool that allows users to compare the directory contents of two similar directories in order to spot differences in between subdirectory structures or file content. However, dircmp is not a luxury afforded by all Linux distributions. CentOS, for example, does not include the dircmp tool and the source code is not easily available. Plus even if it was, who would want to spend time to build it when you can do the exact same thing with your trusty friend: diff.

Read more »


Download Ubuntu Pocket Reference Guide PDF Free

/* Posted January 28th, 2009 at 8:53am [Comments: 6]    */
/* Filed under Linux, Reference    */


For users who using Ubuntu Linux or are considering switching to this popular distro, this free pocket reference guide is available for download in PDF from the book’s website. While the print edition is available for $9.94 from Amazon, The Ubuntu Pocket Guide and Reference PDF is practically identical to the print edition except that it’s absolutely free. The book covers Ubuntu 8.04 LTS, 8.10 and beyond and doesn’t require the reader to have any Linux background. In fact, it’s particularly useful for Microsoft Windows users who are switching to Ubuntu. Linux gurus will still find it useful since it will save them from having to wade through tiresome documentation just to look up a few commands.

Read more »


Page 4 of 71234567