Tuesday, November 25, 2008

usb storage - corrupted e2fs

I don't know how it happened, since I verify each time when I disconnect my external 350G USB drive. I wait for hal to indicate "OK to disconnect" each time. Nevertheless, it's corrupted. I found the list of superblock backups easily
# dumpe2fs /dev/sdb1 |grep superblock
Then, I attempted a customary
# fsck -b 32768 /dev/sdb1
with a backup block from the list, 32768. However, several attempts netted the the same response, that the device was busy
# umount /dev/sdb1
# fsck -b 32768 /dev/sdb1
fsck 1.40.8 (13-Mar-2008)
e2fsck 1.40.8 (13-Mar-2008)
/sbin/e2fsck: Device or resource busy while trying to open /dev/sdb1
Filesystem mounted or opened exclusively by another program?
Making sure, I ran
# umount /dev/sdb1
umount: /dev/sdb1: not mounted
But yet, again, if I tried to fsck, I got
# fsck -b 32768 /dev/sdb1
fsck 1.40.8 (13-Mar-2008)
e2fsck 1.40.8 (13-Mar-2008)
/sbin/e2fsck: Device or resource busy while trying to open /dev/sdb1
Filesystem mounted or opened exclusively by another program?
What was going on? I verified the blocksize
# dumpe2fs /dev/sdb1 |grep -i "block size"
dumpe2fs 1.40.8 (13-Mar-2008)
Block size: 4096
and proceeded with
# mke2fs -S -b 4096 -v /dev/sdb1
to restore the superblocks without touching the data. Unfortunately, this move resulted in stale file handles and the drive wouldn't mount. Another move would be
# e2fsck -y -f -v -C 0 /dev/sda3
# tune2fs -j /dev/sd3
This makes the file system into a Ext3 system, and so the blocks are off if I started with ext2 on the drive in the first place. So I lost everything. Years of data, photos, passwords, tax records, the lot. If I knew a little more about e2fsck, I might have been able to get there, but all I could find was what to do with e3 file systems.

Monday, November 24, 2008

voip - skype, others

Typically, I'm using Skype, and here's how I set it up.

1. Check the dependency requirements at the skype site and install them from netpkg or installpkg. I get the static tar.gz from the site.
2. Untar the package. The executable is included; all the junk just needs to be copied to proper directories.
3. I don't run Skype as root, but it's necessary to sudo or root to make some folders and place some files into the proper directories.
# mkdir /usr/share/skype
# cp -a sounds langs avatars /usr/share/skype
# cp skype (the bin) /usr/bin
# cp skype.desktop /usr/share/desktop
$ mkdir /home/[username]/.Skype
$ cp skype.conf ~/.Skype/

other voip

Sunday, November 23, 2008

postgresql - initialize

Links: PostgreSQL     pgAdmin     wxWidgets
I was interested in postgreql as an Amarok backend, after reading somewhere that the default sqllite and mysql databases were slower than postgresql once a collection became large. I read a primer at this Ubuntu forum, but it appeared that some of the commands there were outdated, or only applied in the Ubuntu environment. What I wanted to accomplish was a basic single-user implementation, that is to say, a home installation with some sort of GUI method to easily interact with it. That is the focus of this post; basic installation and interaction, not database design.

initialize as a user, NOT root (v. 9.04)

Databases are designed as scalable for distributed settings. Protocols for security and integrity are appropriately incorporated. On a standalone home system however, if I have to log-in to boot my system, log-in again as admin (root) to turn the server on and off, and then log-in again as a separate user to use the database, I simply will never use that database, PostgreSQL or otherwise. Away from work or, said otherwise, "on my own time", I use databases to attempt to save time, not to go insane. The method I implemented below is entirely insecure if used apart from a standalone, localhost environment, so be advised, but it requires no special logins or privileges and operates like any other CLI app one can use.
  • 1) Uninstall any distro versions (requires root) and compile PostgreSQL. It's a standard root "make install". Files went to /usr/local/pgsql/bin in my install.
Step 2 isn't strictly necessary, but updating one's PATH shortens subsequent shell commands. If one doesn't care about that, jump to Step 3 and include the /usr/local/pgsql/bin prefix to one's shell commands. Either way, be sure to remain a user beginning at Step 3.
  • 2) Root-up and add /usr/local/pgsql/bin to one's /etc/profile (Slackware) PATH statement. Do # source /etc/profile after updating one's PATH, and then check it (as user) with $ echo $PATH.
  • 3) Create some directory in one's home directory, eg $ mkdir /home/foo/pgdatabases
  • 4) Initialize databases into the directory created in Step 3: $ initdb --encoding=utf8 --locale=POSIX --pgdata=/home/foo/pgdatabases. It will provide a success message with status information. You can also look in /home/foo/pgdatabases to verify administrative files were created in there.
  • 5) Turn on PostgreSQL service:$ postgres -D /home/foo/pgdatabases -r somelogifyouwant.txt It will enter an interactive mode prompt.
  • 6) Create some databases or use a script. Eg, at the pgsql prompt, to create a database called "contacts", CREATE DATABASE contacts ENCODING 'utf8';.
    Alternatively, leave the postges terminal running, open another bash terminal, and enter commands from there. The same command from above, but in shell format, is: $ createdb -E utf8 -e contacts. This should give a success status message or some error.
  • 7) Similar command options exist for table creation. Or, if one has scripts, it's a similar process as with MySQL - run them from the pgsql terminal or from a separate shell.
  • 8) To shutdown the database, CTRL C in the pgsql terminal. The connection will close with status messages.
  • 9) Bathroom. Brush teeth and soft picks for gums.
  • 10) Depart for girlfriend's house. If you forgot to create a girlfriend, remain online and create and depart for that gym. Database project secondary or tertiary priority for you.


I'd also install pgAdmin, which makes database administration easier via a GUI. Put it in a user directory also. However, pgAdmin is very finnicky to compile, as you will see; much more difficult to install that PostgreSQL. PgAdmin is a hog in that it requires the infamous wxWidgets for its Unicode support when reading strings from the datatbase. This wouldn't be so bad, but WxWidgets is also a pig. It relies on gtk, cairo, pango, atk, and a slew of other python dependencies, to install. This means wxWidgets itself is such a rabbit hole of dependencies that it can lead to entirely re-installing an OS. Unfortunately, when I attempted to install pgAdmin, configure found I had no wxWidgets already on my system. This meant I would have to install wxWidgets, and that I would probably face a great deal of associated frustration, time loss, and so forth, until it was accomplished. For example, it could be entirely possible that I might need to to back-up and completely reinstall my OS, just to solve this one dependency problem, perhaps 2 weeks of work. So, although installing the database was simple (less than an hour), GUI access to the database was an entirely different story.

wxWidgets (wxGTK 2.8.10)

After looking at the various versions of wxWidgets, and noting that my OS installation was from 2008, and that I already had versions of pango, cairo, and so on from around that period, I chose wxGTK2.8.10 (03/2009). I started with a basic:
$ configure
This compiled and installed nicely. Miracle. Back to pgAdmin: would this older version of wxWidgets be recent enough to support the latest pgAdmin?

pgAdmin round 2

As seen above, pgAdmin initially lacked wxWidgets. Now we had wxWidgets. Trying again...
$ configure: error: Your wxWidgets installation cannot support pgAdmin in the selected configuration. This may be because it was configured without the --enable-unicode option, or the combination of dynamic/static linking and debug/non-debug libraries selected did not match any installed wxWidgets libraries.

return to wxWidgets

Uninstall wxWidgets, make clean and
$ configure --enable-shared --enable-monolithic --with-gtk=2 --with-libpng=builtin --with-zlib=builtin --with-expat=builtin --with-libtiff=builtin --with-regex=builtin --with-libjpeg=builtin --enable-unicode --enable-debug
This compiles and installs. Let's see if that solves the "unicode" problems for pgAdmin. Seeing how this works yet?

pgAdmin round 3

Score: so far, wxWidgets had miraculously installed twice, pgAdmin has failed twice. So, lets try again with unicode...
$ configure: error: Your wxWidgets installation cannot support pgAdmin in the selected configuration. This may be because it was configured without the --enable-unicode option, or the combination of dynamic/static linking and debug/non-debug libraries selected did not match any installed wxWidgets libraries.
Ah-hah! PgAdmin can s*ck my d*ck.

return to wxWidgets

Uninstall wxWidgets, make clean and
$ configure --enable-shared --with-odbc=builtin --enable-unicode
This compiles and installs. Maybe having ODBC capacity will help with database communication.

pgAdmin round 4

Score: so far, wxWidgets had miraculously installed three times, pgAdmin has failed three times. So, lets try again with unicode...
$ configure: error: Your wxWidgets installation cannot support pgAdmin in the selected configuration. This may be because it was configured without the --enable-unicode option, or the combination of dynamic/static linking and debug/non-debug libraries selected did not match any installed wxWidgets libraries.
Of the hundreds of linked static and dynamic libraries, there is no way to know which combination would work. Noting this, we can say this error message from pgAdmin falls deeply into the "worthless" category of error messages.

return to wxWidgets (wxX11-2.8.12)

Hell, let's try this X11 version. Can't hurt, but didn't succesfully complete. Configure created a makefile, but running make crashed with the following error
./include/wx/filedlg.h:101: error: 'HasFlag' was not declared in this scope
make: *** [.pch/wxprec_coredll/wx/wxprec.h.gch] Error 1

return to wxWidgets (back to wxGTK 2.8.10)

Let's go back to the wxGTK 2.8.10 version of wxWidgets, since we previously were able to compile and install. After that, let's try a Slackware precompiled pgAdmin build instead of attempting to compile pgAdmin. So first wxGTK 2.8.10....
$ configure --enable-unicode
This configured, compiled, and installed successfully, so now we have wxWidgets with unicode support in place. Lets get a precompiled Slack .tgz build of pgAdmin and see if we can use installpkg to shove it in.

pgAdmin round 5 (pgadmin3-1.6.2.tgz)

So here goes nuttin'...
# installpkg pgadmin3-1.6.2.tgz
Installing package pgadmin3-1.6.2...
pgadmin3-1.6.2: pgAdmin III - PostgreSQL Tools
pgadmin3-1.6.2: pgAdmin III is the most popular Open Source management tool for
pgadmin3-1.6.2: the PostgreSQL Object Relational Database Management System.
pgadmin3-1.6.2: http://www.pgadmin.org/
pgadmin3-1.6.2: http://www.postgresql.org/
And now we're gonna see...
$ pgadmin3
So for the first time we're at least getting an image. However, the window crashed when I attempted to change anything about the window or to connect to the server. Upon crashing, the terminal revealed glibc memory errors which had to do with pgAdmin itself. To stop these errors, I added the glibc error prefix:
$ G_SLICE=always-malloc pgadmin3 &
It's clunky, but workable, preventing crashes, but still does not connect by itself.

final touches (summary of hacks)

The above opening command prevented crashes but still does not connect. For pgAdmin to connect to a database cluster, the server must be running, say with
$ postmaster -D /home/foo/pgdatabases
which can easily be terminated any time with a simple
$ killall postmaster
I therefore placed the startup postmaster command in my /home/foo/.profile. So here are the pieces of this working GUI PostgreSQL installation:
  • PostgreSQL installation (simple compile): v. 9.0.4
  • wxWidgets (compile with "--enable-unicode"): wxGTK-2.8.10
  • pgAdmin (slackware .tgz w/installpkg): v. 3-1.6.2
Configuration tweaks include...
  • starting the server in one's home .profile so it's running in the background for a CLI (psql) or pgAdmin to immediately connect
  • when starting pgAdmin, add glibC error hacks, such as G_SLICE=always-malloc
With these in place, one can easily install and interact with the database via a GUI. The discussion of building the database structure for specific need is much more complex. One needs to understand the kinds of fields, how they are related, the best ways to avoid duplication of effort, and so forth. One can receive a Bachelor's degree for a proper understanding of these design elements, and they cannot be covered in this simple installation post.

wifi - ralink pci rt2600 drama

--(edited 20090421)--
I had occasion to reinstall Slackware the other day. Default distribution drivers for the ralink rt2600 are the rt61pci series drivers which seem to provide only flaky and, therefore, annoying connections.

First, retrieve the latest drivers from Ralink's linux page . For me, this was the 2008_0723_RT61_Linux_STA_v1.1.2.2.tar.bz2 driver. Unfortunately, the README was almost unintelligible, without even proper line returns. It only gives a portion of the necessary information, and hours are required to find the solution. Highly annoying. Taken together with the drivers, both the kernel source and headers are required. So:
a. drivers
b. kernel source
c. kernel headers

file changes
Prior to compiling, there are some changes, at least to these 2008 and 2009 versions. After copying Makefile.6 to Makefile, change the CFLAGS statement around line 28 to:

If you don't like to change the Makefile, you can export the KBUILD_NOPEDANTIC just prior to compiling, but this is a necessary environment variable, one way or the other.

Another change, this one suggested, is near the end of the rtmp_main.c file. Here, we want to change as follows: from
static INT __init rt61_init_module(VOID)
   return pci_register_driver(&rt61_driver);
   return pci_module_init(&rt61_driver);
to this:
static INT __init rt61_init_module(VOID)
   return pci_register_driver(&rt61_driver);
   return pci_register_driver(&rt61_driver);

As noted above and described here, if you don't change the enviroment setting in the Makefile, you'll need to add
as a command just prior to compiling. For systems with csh and tcsh environments, the command is apparently

putting it together

$ tar -xvjf 2008_0723_RT61_Linux_STA_v1.1.2.2.tar.bz2
$ cd 2008*
$ cd Module
$ cp Makefile.6 Makefile
$ chmod 755 Configure
$ Configure
$ export KBUILD_NOPEDANTIC=1 (if you didn't change the Makefile)
$ make

Root up

# mkdir /etc/Wireless
# mkdir /etc/Wireless/RT61STA
# cp *.bin /etc/Wireless/RT61STA (three firmware files)
# cp sta.dat /etc/Wireless/RT61STA (configuration file)
# cp rt61.ko /lib/modules/<kernel>/kernel/drivers/net/wireless
final steps
# nano /etc/modprobe.d/blacklist
blacklist rt61pci
blacklist rt2x00pci
blacklist rt2x00lib (save and close)

# nano /etc/modprobe.d./modprobe.conf
alias ra0 rt61 (save and close)

# depmod -a

Saturday, November 22, 2008

slackware - find and replace

I occasionally encounter compatibility problems with Internet Explorer and Firefox when writing site pages. When I do, finding and replacing one word across many files can be a problem. For example, I recently learned that Internet Explorer does not process the word "grey" - it apparently has to be spelled "gray". So how to find and replace all instances of "grey" with "gray" across all the directories on the site?

Of course, finding text is no problem for grep. If it's only one or two files, I can have grep locate the file for me and change them by hand.
grep -lr 'text' *
where "l" provides the line number, "r" will recursively check all files, 'text' is the text I want to locate, and "*" means all files will be checked.

To replace the text, we can use sed

grep and sed script
To both find and replace the text, we need a mix of sed and grep together. A simple bash script follows that does it just fine.

function search {
find $1 -type f \( -name '*php' \) -print | while read file
echo replacing \"$2\" with \"$3\" in $file
sed "s,$2,$3,g" < "$file" > "$file".tmp
mv "$file".tmp "$file"

function nothing {
echo "dir: $1 search string: $2 replace string: $3"

# A directory has been given. Search for files containing the term, and replace it
if [ -d "$1" ]; then
search $1 $2 $3

# A file has been given. Search the file for the term and replace it
elif [ -f "$1" ]; then
sed "s,$2,$3,g;" < "$1" > "$1".tmp
mv "$1".tmp "$1"

# A file to parse or test has been given. If parse, set the directory,
# then step though every file in the directory replacing search / rplace pairs.
# Keep going until there are no more pairs.
elif [ "$1" == '-f' ] || [ "$1" == '-t' ] && [ -f "$2" ]; then
cat $2 | while read line
if [ $index -eq 0 ] && [ -d "$line" ]; then
elif [ $index -eq 0 ] && [ ! -d "$line" ]; then
elif [ $index -gt 0 ]; then
findSt=`echo ${line%% *}`
repSt=`echo ${line##* }`
if [ "$1" == '-f' ] && [ ! "$repSt" == '' ] && [ ! "$findSt" == '' ]; then
search $dir $findSt $repSt
elif [ "$1" == '-t' ] && [ ! "$repSt" == '' ] && [ ! "$findSt" == '' ]; then
nothing $dir $findSt $repSt
let "index += 1"
echo "Search and replacer:"
echo "useage:"
echo "$0 [directory to search] [phrase to search for] [replacement phrase]"
echo "$0 [file to search] [phrase to search for] [replacement phrase]"
echo "$0 [-f|-t] [file to parse]"
echo "To parse a file the first line should be the directory, then each line after is a pair of terms"
echo "and replacements seperated by white space. If the -f os given, the file will be parsed. If -t "
echo "is given then the file will be read and the terms that would be replaced are output."

You can see at the top that this only works on php files, so I just changed the "php" to "css".

Thursday, November 13, 2008

slackware 12.0 - wpa, wicd

I'm using the Atheros AR242x 64 (5007 chipset) in a Toshiba Satellite running Zenwalk 5.2. So, this is not technically a Slackware 12.0 post - the Slackware foundation of Zenwalk means they are similar. I'll edit the specifically Slackware aspects of this post over Christmas break. For Zenwalk WPA, I mostly followed these excellent instructions .

Atheros AR242x 64 (5007 chipset)
The information here was helpful for understanding this newer chip. For a module, Zenwalk provides ath5k, but ath5k wasn't responding well to configuration attempts, so I turned to a Madwifi module. Incidentally, the Madwifi site also contains information on ath5k here, and it appears the ath5k module will eventually be effective. Currently however, the steps which worked with the Madwifi module were:

1. in /etc/modprobe.d/blacklist, blacklist the "ath5k" module
2. reboot and lsmod - make sure ath5k is gone
3. download madwifi-hal- , or the newest one there, make, and install.
4. reboot again and lsmod
5. iwconfig ath0

WEP is trivial, merely requiring the two iwconfig commands "essid" and "key restricted", matched to whatever network I was using. Because I'm multihomed, the order of bringing-up the interfaces was the only other pay-attention issue. If the interfaces are activated backwards in /etc/rc.d/rc.local, then dhcpcd apparently attempt to assign DNS to the interface on the LAN, rather than the one on the WLAN. blah blah blah.

The basis here was again gained at this Zenwalk wiki , but there are a couple of tweaks or clarifications. It appears that wpa_supplicant relies upon inserting the wext module into the kernel.
1. using wpa_passphrase with the [essid] and [password] varies with the WLAN with which one wants to connect. The command is used similarly to the WEP iwconfig ath0 key restricted "xxxxx", which varies with each WLAN. Wpa_password then, is not a key for the laptop I'm working from, it's a password key hashed for the WLAN I'm attempting to connect with. This means I have a different entry for each WPA WLAN I'm working on.
2. wpa_password [essid] [password] > /etc/wpa_supplicant.conf is a brilliant way to start the initial conf file. And, as noted in the wiki, the file can be this simple to work:

ssid="BART Transit"
3. The following command line from the wiki configured ath0 properly on the first shot:
wpa_supplicant -i wlan0 -D wext -c /etc/wpa_supplicant.conf -B
the "-B" switch is added to make the program run as a daemon, and might not be necessary.
4. After the above, I had only to dhcpcd ath0 to get a valid connection.
5. One issue appears to be quickly enabling or disabling configurations for different WLANs via /etc/wpa_supplicant.conf. (see wicd below).
6. Permanence/boot - inserting the line in Step 3 above into an /etc/rc.local should work if I have an /etc/wpa_supplicant.conf file with a single network configuration in it.

more wpa_supplicant.conf
Wpa_supplicant is not necessary for WEP security, since we can program the card directly with CLI commands to prepare WEP. However, if one chooses to run wpa_supplicant for everything, /etc/wpa_supplicant.conf files appear able to configure WEP and unencrypted connections, in addition to WPA connections. The conf files are useful for storing various wi-fi location configurations. Each connection requires a different conf file, eg etc.wpa_supplicant1.conf, etc.wpa_supplicant2.conf, etc. Apparently wicd can do this with a gui interface which manages switching. But this also means the wicd daemon must run - additional memory usage.

A site with the wpa_supplicant.conf commands is this one, and a site that shows the different WLAN setups in the "conf" file is here (scroll down).

Wicd configuration files live in /etc/wicd/encryption/templates. A primer for converting wpa_supplicant.conf files to wicd configurations is at this site. Once the various templates are in place, it appears we can switch between them using the wicd gui, though it's unclear if dhcpcd would need to be killed and restarted in the command line?