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.

skype
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 - user level install

Want to set-up a relational database and have browser access through localhost on our local machine. If successful, we can next learn cloud install or connect clusters. DBeaver is installed as our GUI admin tool. PgAdmin is good when running but often spawns lib errors. Regardless, the install portions of administration are CLI.

installation steps (2 hrs)

1. server (1 hour)

An entirely initalized PostgreSQL cluster has two parts, a database and a server. The server acts like Apache and manages connections. We start with that portion first, the databases need to be created from within the server. The one exception is when we run "initdb", a default database "postgres is created, so it can communicate with an admin tools.

Pacman installs the PostgreSQL server into a "bin" directory. This is fine. But, we want all configuration and data writing into our home directory, and we don't want to have to become another user or admin to run PostgreSQL. The idea is simple backup, portability, and user-level permissions; nothing root or weird PAM errors.

1a. install server

# pacman -S postgresql dbeaver

Postgresql install is about 51MB, not too bad. Service runs on port 5432 (change this in postgresql.conf ), and is not a systemctl service. At the user level we can start it, and stop it without becoming root.

1b. intitialize default cluster

Like any other application, I want to access all PostgreSQL files and tasks at the user level: never want to become root or change to another user. Yet when pacman installs Postgresql, it creates a "postgres" group in /etc/group and does not append $USER (eg. 'foo') to this group.

When initdb initializes PostgreSQL, it creates a default cluster and DB named "postgres" and puts them in /var/lib/postgres/data. No! I want the files in the home "foo" directory, like any other app.

Solution: 1) Append ourselves ("foo") to the "postgres" group in /etc/group. 2) run $ initdb and specify our home directory as the data repository.

# nano /etc/group [add self to postgrep group]
$ mkdir postgres
$ initdb -D /home/foo/postgres/data

1c. lockfile hack

There's a third permissions issue. When PostgreSQL runs at user-level, it is thwarted attempting to write a session lockfile into a root controlled /run/postgresql folder. To properly solve this error probably requires manipulating groups, but I simply changed the permissions on /run/postgresql to $USER. The problem disappeared.

# mkdir /run/postgresql/
# chown -R foo:foo /run/postgresql

1d. start server

With all the above accomplished, we can start the server as a user.

$ postgres -D '/home/foo/postgres/data'

1e. make permanent

We'd prefer not to have to delineate the data directory each time we start the posgres server. So we want set the path correctly. This initdb wiki notes the "PGDATA" variable added to the /home/foo/.bashrc file will make this permanent.

$ nano .bashrc
export PGDATA="/home/foo/postgres/data"

Logout and back in and then verify using "$ listenv". Now we can start our cluster (server) with $ postgres

1e. logs, tables, configuration

Unless modified in postgresql.conf, logs will appear in our home directory. Tables are in /home/foo/postgres/data.We can also configure the server, apart from the database and cluster, in /home/foo/postrgres/data/postgresql.conf. This would arrange which port we listen on, and other features. The security related conf is pg_hba.conf. There are others. All of these control the server, not the databases themselves

2. connect to defaults (10 minutes)

With a lot of work, our server environment has been completed. default "postgres" cluster and database were created by the initdb process. Let's leave them so we don't disrupt any administrative dependencies, but let's also move on to creating our own cluster and databases.

From the CLI, there is plenty we can arrange without dbeaver. DBeaver kicks butt once our databases are filled with data. For now though, to check our connection and create databases, we want to use the psql command. Our default username is "foo" when we connect because that's the user we ran initdb. The default database "postgres" however also must be called. So here is our connection command.

$ psql -U foo postgres

Again, there are three entitites: the cluster and the default DB are named "postgres", and the username is our own home directory name.

3. create clusters and databases (whatever no. of hours)

Our server environment is complete and our plans for data begin. We might have created a UML schema or it might be trial and error against a CSV or something else.

We're connected to the database through psql, so now we want to make a cluster and a database

BTW, there are many pages about dropping clusters and databases, and we can delete them from the data folder as well, so it's not that difficult to drop. Ok, but let's add.

4. dbeaver

Now that we're at step 3, we can add dbeaver to visualize our setup. Dbeaver is java and so needs JDBC compliant databases. Postgres is Type 4 java-compliant, inherently java-compatible. Dbeaver connects to a user at startup, 'postgres' by default, so change it to your $USER, eg "foo".

concepts

Roles and users

Somewhat confusing -- an imperfect analogy is that roles are governments and users are those operating within those governments. None of these will be created until we create a database. Just turning on the server ("postgres" command) does not create a database nor its associated roles.

postgres - users and roles  (22:52) E-Multi-Skills Database Tutorials, 2020. users can login, roles cannot. Role is a function, user is a client. Dbeaver seeks to connect to a role. It will operate as an agent so it nees a role with significant privileges.
postgres - roles, schema, security  (32:31) databasetorque, 2021. role can cally.
PBX - true overhead costs  (11:49) Rich Technology Center, 2020. Average vid, but tells hard facts. Asteriks server ($180) discussed.

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.

drivers
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:

EXTRA_CFLAGS+= $(WFLAGS)
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)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
   return pci_register_driver(&rt61_driver);
#else
   return pci_module_init(&rt61_driver);
#endif
}
to this:
static INT __init rt61_init_module(VOID)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
   return pci_register_driver(&rt61_driver);
#else
   return pci_register_driver(&rt61_driver);
#endif
}


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

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?

grep
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.

sed
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.
#!/bin/bash

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

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
index=0
cat $2 | while read line
do
if [ $index -eq 0 ] && [ -d "$line" ]; then
dir=$line
elif [ $index -eq 0 ] && [ ! -d "$line" ]; then
exit
elif [ $index -gt 0 ]; then
findSt=`echo ${line%% *}`
repSt=`echo ${line##* }`
fi
if [ "$1" == '-f' ] && [ ! "$repSt" == '' ] && [ ! "$findSt" == '' ]; then
search $dir $findSt $repSt
elif [ "$1" == '-t' ] && [ ! "$repSt" == '' ] && [ ! "$findSt" == '' ]; then
nothing $dir $findSt $repSt
fi
let "index += 1"
done
else
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."
echo
fi

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-0.10.5.6-r3861-20080903.tar.gz , or the newest one there, make, and install.
4. reboot again and lsmod
5. iwconfig ath0

WEP
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.

WPA
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:

network={
ssid="BART Transit"
#psk="oct2008@rezt9bit"
psk=3ad964f16045787dec86a4730e9dec4bedaa9e24f2998eacfa363e80510e3393
key_mgmt=WPA-PSK
proto=WPA
}
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
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?