Archives for March, 2010

15
Mar

Write To or Read From a Given Sector Using dd

This comes in handy when trying to troubleshoot a drive. If you’re met with an error message like “I/O Error: Bad sector 40003″, then you can use ‘dd’ to verify that it’s bad. For example, to write to a given sector/block, use the following command:

dd if=/dev/urandom of=/dev/sdb seek=<sector_number> count=1 bs=512

To read from a given sector/block, use the following command (skip instead of seek):

dd if=/dev/sdb of=/dev/null skip=<sector_number> count=1 bs=512

12
Mar

Setup Auto Login Using mingetty

Here’s a guide on how to setup Linux to login automatically. This is meant for an embedded Linux environment more than a full-fledged desktop one, but it should work all the same. Before moving through this guide, ask yourself if you’d really like to login automatically or if you’d like to run a program automatically. Most folks want to login automatically so they can include a command line to be run in the ~/.bash_profile login scripts. This isn’t necessary. Instead, take a look at how to automatically run a program on system startup here:
http://www.thelinuxdaily.com/2010/01/automatically-start-a-script-at-linux-bootup/. If you’d still like to login automatically, then follow the steps below.

1.) The first thing to be done is to install mingetty

apt-get install mingetty

2.) Edit the /etc/inittab file to include the line (you’ll need to find your console port for this one):

1:2345:respawn:/sbin/mingetty --autologin root ttyAM0:

There, your system will now automatically login as root.

12
Mar

Submitting Kernel Source Tree to CVS

Today I attempted to submit a kernel source tree into CVS and was surprised when I found out that the …/drivers/sound/core/ was missing. Luckily, the fix was to simply include the -I ! parameter like so:

cvs import -I ! kernel/ INITIAL start

This parameter prevents CVS from ignoring folders like core. Here’s an excerpt from the cvs man page:

       -I name

         Specify file names that should be ignored during import.  You can use
         this option repeatedly.  To avoid ignoring any  files  at  all  (even
         those ignored by default), specify `-I !'.

11
Mar

The Terminal Prompt Environment Variable $PS1 and Others

A quick and dirty way to change your terminal prompt is to edit the ~/.profile or ~/.bash_profile files to include the line:

PS1="specify_prompt_here"

One example prompt would be to simply print the hostname followed by a colon:

PS1="\h : "

Vivek Gite of cyberciti.biz has a really good write-up of utilizing the PS1 environment variable as well as others which can be found here:
http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html

6
Mar

Setup Wireless Connections in Terminal

Wireless connections in Linux
Although this may not be helpful to those running modern Linux distributions, it may be helpful to those who are in an embedded environment where things like Network Manager aren’t available. It may even be useful to know how to configure a wireless connection in the terminal for troubleshooting purposes (or maybe you just prefer to do things quickly in the terminal without messing around with a GUI).

Wireless devices vary greatly, so it’s near impossible to create a guide that’s going to work for all of them, but for the most part, these steps will get you there. The first step is to find the correct wireless driver for you device’s chipset. Drivers that work pretty well with Linux are from ralink and zydas. There are others I’m sure, but it just so happens that the following steps work for both the rt2501usb (rt73) and zd1211b (zd1211rw or zd_b) drivers. Once you’ve located the correct driver, use “insmod” to insert the module and then check out /proc/net/wireless to make sure the device was recognized properly. For example:

[/bash]
root# insmod rt73.ko
root# cat /proc/net/wireless
Inter-| sta-|   Quality        |   Discarded packets               | Missed | WE
 face | tus | link level noise |  nwid  crypt   frag  retry   misc | beacon | 16
rausb0: 0000  100.  220   177        0      0      0      0      0        0
[bash]

Once you’ve gotten this far, you should install the wpa_supplicant and wireless-tools packages so you can take advantage of iwconfig and others. Here are a few useful commands:

Another thing to note of the below steps are that the rausb drivers are being using to connect to WPA and WPA2 access points. You may want to use wext instead depending on your environment and how the drivers were compiled. With that said, let’s get to it…

Unencrypted

   1) Bring the rausb0 interface up
      * ifconfig rausb0 up
   2) Associate with the AP
      * iwconfig rausb0 essid the_essid
   3) Assign a static IP
      * ifconfig rausb0 192.168.1.101

WEP Encryption

   1) Bring the rausb0 interface up
      * ifconfig rausb0 up
   2) Associate with AP
      * iwconfig rausb0 essid the_essid key the_key
   3) Assign a static IP
      * ifconfig rausb0 192.168.1.101

WPA Personal – TKIP

   1) Bring the rausb0 interface up
      * ifconfig rausb0 up
   2) Generate a configuration file for wpa_supplicant to use
      * ./wpa_passphrase the_essid the_password &gt; /etc/wpa_supplicant_custom.conf
   3) Use wpa_supplicant to associate with AP and run it in the background (-B)
      * ./wpa_supplicant -irausb0 -Dralink -c/etc/wpa_supplicant_custom.conf -B
   4) Assign a static IP
      * ifconfig rausb0 192.168.1.101

WPA2 Personal – TKIP or AES

   1) Bring the rausb0 interface up
      * ifconfig rausb0 up
   2) Generate a configuration file for wpa_supplicant to use
      * ./wpa_passphrase the_essid the_password &gt; /etc/wpa_supplicant_custom.conf
   3) Insert "proto=RSN" into "network" block in /etc/wpa_supplicant_custom.conf
   4) Use wpa_supplicant to associate with AP and run it in the background (-B)
      * ./wpa_supplicant -irausb0 -Dralink -c/etc/wpa_supplicant_custom.conf -B
   5) Assign a static IP
      * ifconfig rausb0 192.168.1.101

Adhoc Mode

   1) Bring the rausb0 interface up
      * ifconfig rausb0 up
   2) Setup rausb0 for Adhoc mode
      * iwconfig rausb0 mode ad-hoc channel 3 enc off essid the_essid
   3) Assign a static IP
      * ifconfig 169.254.114.101 netmask 255.255.0.0
   4) Add default gateway to route (optional)
      * route add default gw 169.254.114.100

5
Mar

Using exiftool to Create List of Pictures Matching a Keyword/Tag


JPEG Photos with EXIF data, the topic of this post

The exiftool utility is an indispensable tool in the arsenal of picture organization tools and can save you a ton of time when used properly. There are a TON of uses documented in its manual, but there are even more uses outside of that. You just need to be clever. Take the following shell script for example…

This script will call exiftool from the command line or terminal to search through a directory of photos, pick out the ones that match a particular keyword or tag (certainly not limited to these, it can be any attribute stored in exif data), and then save them to a file. The 2> /dev/null portion simply throws away any messages exiftool creates and only leaves you with the goodies in the $RESULT_FILE. Not only does it find the photos that you want with the “favorites” keyword, it also adds the path so you can use the terminal to open them, sort them, or copy them to another location.

#!/bin/sh

PICS_DIR=/home/username/pictures
KEYWORD=favorites
RESULT_FILE=favorite_photos.txt

echo -n "Now, grab all of your photos tagged with \"$KEYWORD\" in $PICS_DIR..."
(
   exiftool -ext .JPG -fast -p 'source$directory/$filename;destination$directory/$filename; \
   $Keywords' -qq -r -m "$PICS_DIR" | grep -i "$KEYWORD" > $RESULT_FILE
) 2> /dev/null
echo " done"

I have taken this one step further to develop this script (which I’ve appropriately named “picup”) that automatically uploads photos marked with “favorites” to an online gallery powered by ZenPhoto. Pretty clever if I do say so myself.

4
Mar

Simple Cross Compile Example

The following is a very introductory guide to cross compiling a simple C++ program targeted towards an ARM platform. Development environments differ greatly, but for the most part, they all follow similar steps like outlined below. The very first step is to obtain a cross compile toolchain. CodeSourcery has a free, lite gcc toolchain available for download (as mentioned in a previous post). Once you download an appropriate toolchain for your target, you’ll need to extract it on your development host machine. You’ll notice a directory structure similar to opt/crosstool/gcc-4.0.1-glibc-2.3.5/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu- which is what we’ll use here.
[Read more →]

« Previous Page

Switch to our mobile site