Latest entries
Connecting linux laptop to the Internet using Nokia e61
Finally I replaced my old Sony Ericsson t68i phone with new shiny Nokia e61 . It is really great smartphone (should I say multimedia computer? :) with every imaginable feature built-in. Just to name a few: 3G, Wi-Fi, Bluetoth, USB cable, Irda, MiniSD card reader, 320×240 screen, QWERTY keyboard.
While it is possible to browse internet using phone itself laptop provides much better user experience for doing it.
Connecting my linux laptop to the internet using Nokia e61 phone was surprisingly easy. I’ve managed to setup network connection using both USB cable and bluetooth in less than half an hour. Under Windows cable connection was working out of the box with Nokia software, but bluetooth doesn’t work at all (but I haven’t tried too hard to make it work).
If you want to use internet from your laptop using Nokia e61 (and most probably other Nokia phones as well) as modem you need:
- recent kernel with bluetooth and ACM (for using phone as USB modem, CONFIG_USB_ACM kernel configuration option) support
- bluez-utils
- wvdial – of course it is possible to use ppp only, but I found wvdial much simpler to configure
My further instructions are gentoo specific, though they shouldn’t differ too much for other distributions.
USB modem
On my system (kernel-2.6.18, udev-103) when I plug USB cable and selected PC Suite mode on my Nokia phone proper drivers are loaded and proper devices are created automatically. This is really how it should work! After phone is connected /dev/ttyACM0 device should be created.
If you have problems with it try to load drivers manually:
modprobe cdc_acm
modprobe usbserial vendor=0x0421 product=0x044d
wvdial configuration is also very simple (T-Mobile specific):
[Dialer usb-tmobile]
Modem = /dev/ttyACM0
Phone = *99#
Username = t-mobile
Password = t-mobile
Bluetooth
Follow these steps:
- make sure that /etc/init.d/bluetooth is started
- add your laptop to paired deviced of the phone from Menu / Connectivity / Bluetooth (Paired devices -> Options -> New Paired Device)
- Use sdptool browse command to find channel number that is used for dial up networking:
...
Service Name: Dial-Up Networking
Service RecHandle: 0x10052
Service Class ID List:
"Dialup Networking" (0x1103)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 2
...
- find bluetooth address of your phone using hcitool scan command.
- edit /etc/bluetooth/rfcomm.conf to configure RFCOMM port:
...
rfcomm2 {
# Automatically bind the device at startup
bind yes;
# Bluetooth address of the device found using hcitool
device 00:11:22:33:44:55;
# RFCOMM channel for the connection found using sdptool
channel 2;
# Description of the connection
comment "Modem (Nokia e61)";
}
...
- make sure that RFCOMM_ENABLE = true in /etc/conf.d/bluetooth
- configure wvdial:
[Dialer bluetooth-tmobile]
Modem = /dev/rfcomm2
Phone = *99#
Username = t-mobile
Password = t-mobile
Devices permissions
By default modem devices belongs to root group, so only root user can use them. In order to allow regluar users that belong to group tty to use modem create file in /etc/udev/rules.d with following content:
KERNEL=="rfcomm[0-9]*", GROUP="tty"
KERNEL=="ttyACM[0-9]*", GROUP="tty"
That’s all. Now type wvdial bluetooth-tmobile and go online :)
Posted by ksh on December 14, 2006 | 9 comments | e61, linux
Renaming network interfaces using udev rules
By default network interfaces in Linux have non-informative names, like eth0 or eth1. It is more convenient to give them logical names. F.e. wireless link can be named wlan and ethernet link – lan.
There are several ways to rename network interfaces but I find solution with udev to be the easiest solution. All that you should do is to add following rules to udev (usually this can be done by adding file with new rules to /etc/udev/rules.d directory):
SUBSYSTEM=="net", SYSFS{address}=="00:13:02:65:74:c1", NAME="wlan"
SUBSYSTEM=="net", SYSFS{address}=="00:18:d3:05:e3:da", NAME="lan"
SYSFS{address} in these rules is hardware address of network card and can be found in /sys/class/net/ethN/address file, where ethN – old name of the interface you want to rename. Note that string comparison in udev rules is case sensitive.
Posted by ksh on November 6, 2006 | 0 comments | linux
Starting with UML
I have been using Linux for a long time but mostly for developing high level applications in java and python and as home operating system (multimedia, Internet surfing and so on). From everyday usage I’ve gained understanding of how different parts of Linux system work together, how to configure and use various applications, how to find what’s going wrong and many other things. So my experience was mostly “in user-mode” and I have little understanding (except some common principles that are applicable to all modern operating systems) how kernel of Linux works. Recently I became very interested in it for several reasons:
- I’ve bought laptop and there is plenty of hardware that is currently not supported by Linux, including built-in web cam, microphone and IR-receiver.
- Linux crashed several times on my laptop and I have no idea why and even how to find out the reason.
- Some nice features like suspend-to-ram and hibernate don’t work and again I can’t figure why.
- It’s just interesting and about having fun :)
Unfortunately it is hard to start with kernel development especially taking into account that my knowledge of C language is limited to university courses that I took several years ago. Linux kernel is very large piece of code and it is easily possible to get lost in it.
To have something to start with I’ve decided to play with UML . In particular I’ve thought about creating my own filesystem image for running UML and running UML process in debugger. So exploring source code for UM architecture I can learn about system
programming for Linux (such things like signals, threads, etc) and at the same time learn about kernel by exploring rest of kernel sources.
In this post I am going to describe how to create very simple basic filesystem image and run UML with it.
At first you need to create empty file with ext2 filesystem inside:
dd if=/dev/zero of=minimal-1.ext2 count=10k bs=1024
/sbin/mke2fs minimal-1.ext2
To mount this file as real file system run following command as root:
mount minimal-1.ext2 minimal-1/ -t ext2 -o loop=/dev/loop1
Statically linked busybox can serve as minimal Linux distribution. Installation is pretty straightforward:
make menuconfig
make
make install
Make sure that at least following busybox applets are enabled:
- init* (CONFIG_INIT)
- ash (or any other shell, make it default shell, CONFIG_ASH, CONFIG_FEATURE_SH_IS_ASH)
- mount/umount (CONFIG_MOUNT, CONFIG_UMOUNT)
and it is configured for static build (CONFIG_STATIC). It is also very convenient to configure mounted at the previous step directory as installation prefix (PREFIX).
Now it is time to make some missing directories in just created filesystem:
mkdir minimal-1/proc
mkdir minimal-1/dev
mkdir minimal-1/tmp
mkdir minimal-1/etc
and devices for consoles, terminals and virtual hard drive (run following commands as root):
cd minimal-1/dev
mknod console c 5 1
mknod tty0 c 4 0
mknod tty1 c 4 1
mknod tty2 c 4 2
mknod tty3 c 4 3
mknod tty4 c 4 4
mknod tty5 c 4 5
mknod ubda b 98 0
Only 2 things are left: /etc/fstab:
/dev/ubda /boot ext2 defaults 1 2
none /proc proc defaults 0 0
and startup script (called by init) /etc/init.d/rcS:
#!/bin/sh
# mount proc
/bin/mount /proc
# remount root file system in rw mode
/bin/mount -o remount /
echo "Started!"
Thats all! Now you can unmount created file system or run sync several times to make sure that all changes are written to the file and use it as root image for UML:
./linux ubda=minimal-1.ext2
In the next posts I am going to describe my further experiments with UML.
Posted by ksh on September 5, 2006 | 2 comments | linux
Watch
In this post I am going to write about very useful utility called watch and its possible usages. I discovered it several weeks ago, but since then I use it quite often. It’s a pity that I didn’t know about this program all the time that I had been using Linux. This utility executes given program periodically, showing output fullscreen. It can be used to monitor any kind of information about your system.
Below you can find some examples:
- Monitor wireless connection (bit rate, signal quality and so on):
watch -n1 -d /sbin/iwconfig eth1 - Monitor CPU temperature:
watch cat /proc/acpi/thermal_zone/TZS*/temperature - Monitor CPU frequency:
watch sudo cat /sys/devices/system/cpu/cpu*/cpufreq/cpuinfo_cur_freq - Monitor disc usage:
watch df
And of course (as with almost any UNIX utility) you can invent a lot of other ways how to use watch.
Short guide to Wi-Fi under Linux
Recently I bought notebook and needed to connect to hotel Wi-Fi network (to install Gentoo linux :) All information that I’ve found didn’t help me to setup wireless connection in less a minute. This guilde explains (in very simple way) how to connect your PC to Wi-Fi network under linux.
You should have following applications installed on your PC:
- Wi-Fi driver (this guide covers Intel 3945)
- wireless-tools
- dhcp
Follow these 7 simple steps:
- Load Wi-Fi driver (Intel 3495 specific):
modprobe ipw3945
ipw3945d - Figure out the name of network interface that is bound to Wi-Fi card:
iwconfig - Find list of available networks:
iwlist scanning - Connect to one of it:
iwconfig eth1 essid ESSID
where eth1 – network interface found at the second step and ESSID – id of wireless network found at the third step - (optional, I haven’t used it) If network is secured you should also specify key:
(This sets a hex WEP key)
iwconfig eth0 key 1234123412341234abcd
(This sets an ASCII key – prefix it with “s:”)
iwconfig eth0 key s:some-password - Obtain IP address using DHCP:
dhcpclient eth1 - Make sure that everything is ok:
ifconfig
Probably these steps are too simplistic and will not work in all cases, but they work fine for me and when I was in need for simple instructions I haven’t found such small guide.
I am in London!
I have changed my previous job and now I work in London.
Yesterday I arrived to the city and today was my first day at new job!
London is really great and full of things to discover :)
I already seen Big Ben on the way from airport to the hotel.
Logwatch and Gentoo
Today I have upgraded logwatch package on my VPS server to the latest version (7.1).
Most noticeable change in this version comparing to previous (6.0.2) installed on my system – whole new directory structure (see Details on how to create your own filter, create local customizations, etc for more details).
Logwatch is very useful tool if you want to know what your server is doing the whole day. It provides nice summary of log of every service, like list of emerged packages, number of mails sent by your mail server, number of failed authentication attempts through SSH, summary of served by apache files, free disk space, information about possible attacks on your server by using known hacks and a lot more.
Unfortunately default configuration of just installed package is not compliant with default logfiles used by gentoo and some services are missing in result report. logwatch provides easy way to override default configuration in /etc/logwatch/conf/override.conf file. Below is file that I am using on my gentoo server:
logwatch: Detail = High
logfiles/cron: LogFile = messages
logfiles/cron: Archive = messages.*.gz
logfiles/cron: *OnlyService = cron
logfiles/http: LogFile = apache2/*access_log
logfiles/http: Archive = apache2/*access_log.*.gz
logfiles/maillog: LogFile = messages
logfiles/maillog: Archive = messages.*.gz
Posted by ksh on July 22, 2006 | 4 comments | gentoo, linux
Django Blog: Notifying about new comments by email
Every blogger is interested in comments for his/her blog posts. So do I. Unfortunately there are no so much comments on my blog (only two), but I hope there will be more in future :)
But how could the author of the blog be notified about new comments? One possibility is to create feed for new comments and subscribe to it using your favourite feed reader (f.e. Google Reader). In fact I had been using this approach until recently. But I think that more convenient approach is to be notified by email. Now I am going to describe how I implemented this functionality in my blog.
The problem seems to be simple – just send email after comment object is saved to database. But I am using django.contrib.comments application and can not modify its code.
Fortunately django provides way to hook into process of the object saving. Internally Django (or more strictly speaking post magic-removal version of Django) uses PyDispatch framework – multiple-producer-multiple-consumer signal-dispatching system :) Despite this complex name idea of this framework is really simple: you can produce signals using following method
dispatcher.send(signal=Any, sender=Anonymous,
*args, **kwargs)
and register listeners for the signals using:
dispatcher.connect(receiver, signal=Any, sender=Any,
weak=True)
Check sources of django.dispatch package for more details.
Django ORM framework supports following signals defined in django.db.models.signals package:
| signal | when given signal is sent | args | kwargs |
| pre_init | before model object initialization (from constructor) | positional arguments to init | keyword arguments to init |
| post_init | after object is initialized | None | instance = self |
| pre_save | just before saving object to database | None | instance = self |
| post_save | after saving object to database | None | instance = self |
| pre_delete | just before deleting object from database | None | instance = self |
| post_delete | after deleting object from database | None | instance = self |
For all these signals model class serves as sender.
Now our task becomes very easy – write and register post_save signal listener for FreeComment class:
from django.db import models
from django.db.models import signals
from django.dispatch import dispatcher
from django.core.mail import send_mail
from django.template import Context, loader, Template,
TemplateDoesNotExist
from django.contrib.comments.models import FreeComment
# send mail on comment
def send_comment_by_mail(instance):
comment = instance
if comment.content_type.model_class() != Entry:
return
entry = Entry.objects.get(id__exact = comment.object_id)
# templates for mail subject and body
try:
subject_tmp = loader.get_template("free_comment_subject")
except TemplateDoesNotExist:
subject_tmp = Template('New comment for entry \
"{{ entry.title }}" by "{{ comment.person_name }}"')
try:
body_tmp = loader.get_template("free_comment_body")
except TemplateDoesNotExist:
body_tmp = Template('{{ comment.comment }}')
# send email to the user
ctx = Context({'entry': entry, 'comment': comment})
subject = subject_tmp.render(ctx).decode('utf-8').strip()
body = body_tmp.render(ctx).decode('utf-8')
entry.author.email_user(subject, body)
# connect signal
dispatcher.connect(send_comment_by_mail,
sender = FreeComment,
signal = signals.post_save)
Posted by ksh on July 1, 2006 | 10 comments | development, django
Removing the Magic
Finally I found time to rework code of step-inside.org to use current (post magic-removal) version of django. I managed to do this in about half a day. There were only two non-straightforward tasks:
- Change database schema and migrate data. Fortunately there is very good overview of changes in Django Wiki
- Initially I have used tagging application from django_stuff library, but now I decided to remove this dependency and implemented my own functionlaity to support tags for blog entries.
After migration I added two new cool features to my blog application: syntax highlighting and sending email for new comments.
I will blog about implementation details in the next posts.
Posted by ksh on June 30, 2006 | 0 comments | django, personal
Java Threads google notebook
Google continues to provide amazing online services. Recently they launched Google Notebook . This service really useful to make various notes, especially during surfing the web.
It also allows to make your notebooks public, i.e. viewable by everybody. I’ve used this feature to record notes about concurrency and thread usage in Java, that I had made while reading Java Threads, 3rd edition book. Here is link to my notebook . I hope that somebody finds it useful.
Posted by ksh on June 7, 2006 | 0 comments | development, java
Using forceId with facelets
Recently JSF project that I am working on was shifted from JSP to facelets.
It was really easy task, but nevertheless several problems arose during migration. One of them – using forceId with some myfaces components. The problem is that facelets uses JSF component classes as beans, but forceId is not a java property of tomahawk components. Instead it is passed as JSF attribute and this is handled somewhere is JSP tag classes that are not used by facelets. Of course this can be solved by writing custom TagHandler (analogous of JSP Tag class), but it would be too much work – write TagHandler for every myfaces component.
Much easier solution exists – use f:attribute like this:
<t:outputText id="myd" value="#{bean.property}">
<f:attribute name="forceId" value="true"/>
</t:outputText>
Posted by ksh on May 22, 2006 | 2 comments | development, java, jsf
Development of Personal Site: Part 4 (Django)
Though at my work I am java developer I am fond of python, and wanted to use python for developing dynamic parts of the site (like blog, poll, flickrbrowser).
At first I decided to find all applications that I need and combine them into single web site with consistent look and feel using paste . To my surprise most applications that I have found were just CGI-based web applications or scripts and I decided that it quite a lot of efforts to consistently combine them together.
I continued my investigation and found PyBlosxom . While this blog engine is quite simple and extensible by plugins it is not easy task to configure it properly. Besides at least four blogs mentioned on its users page switched to WordPress, that is written in php. But I don’t want php. One more important point that resources of my VPS are quite limited and it is not very wise to run php+mysql only for blog and python for other applications that I am going to develop.
Still investigating I found post in GvR’s blog about python web frameworks and somebody mentioned django in comments to this post. I had heard about it before, but thought that there is nothing special with it, just some combination of ORM and template library. But after reading very good opinions about it I decided to give it a try.
I was really amazed by this great framework. This exactly what I need. It allows to combine several applications in single site with little or no effort. Though all applications that you are able to see on this site were written by me almost from scratch (and this is different from my original intention to reuse applications as much as possible) it was so easy to create them and allows me to learn django better.
There are a lot of speculation that python should be promoted more aggressively and I think that django really can help python to become more widely-used language.
I imagine that as it becomes more popular a lot of django applications (like blog, forum, poll, CMS, image gallery, etc) will appear and instead of writing everything from scratch it will be possible to specify list of necessary applications (as eggs), configure them, write some base templates and CSS styles to unify look and feel and receive great dynamic web site.
Posted by ksh on April 14, 2006 | 5 comments | development, django, python, web
Development of Personal Site: Part 3 (Software for server)
If you read my previous posts about development of personal site you probably already guessed that I have installed gentoo linux on my VPS.
Gentoo is my favorite linux distribution over there. I am using it already for 3 years at home, for almost 1 year at work and for 2 months at VPS server :) and not going to change it. Before I have found gentoo I tried RedHat, now I am administrating Debian and RHEL servers at my work, but I’ve never feel enough comfortable with these distributions. I am not sure what are the real reasons for it, probably this is because of lack of knowledge and practical experience with particular distribution or may be I just do not like them and has mental barrier that prevents me to use them efficiently. But anyway I have chosen gentoo and want to describe some details about what software and why I have installed.
Because VPS memory (64Mb RAM + 128Mb swap =198Mb total), CPU and hard drive (3Gb) resources are quite limited at first I doubted that they are enough for source-based linux distribution where you need to compile every single package from sources and also keep a lot of development files (in /usr/include) that are not usually necessary for binary distributions. But it turned out that it is more than enough. Upgrading all packages (including glib and gcc) to the most recent versions and installing all necessary software is a matter of several hours. Additionally I’ve performed some configuration and was able to decrease disk usage. Here are some tips:
- add nodoc, noman, noinfo to your FEATURES in /etc/make.conf (man make.conf for more details)
- make sure that you have configured RSYNC_EXCLUDEFROM (Diverting from the Official Tree). You certainly don’t need ebuilds in such categories like x11-base or kde-base on your server and you can safely remove all such ebuilds from your PORTDIR
- do not allow make to execute several commands simultaneously: MAKEOPTS=”-j1”
While portage tool itself is very convenient it still lacks some helpful functionality. Fortunately there are some tools that fill this gap: gentoolkit and flagedit. I would recommend every gentoo user to install these packages and learn how to use them.
Every site need HTTP server. I have chosen apache, mainly because I want to be able to access my subversion repositories via HTTPS. Another good HTTP server is lighttpd .
Though mail server is not really necessary it is very convenient to have it. I have installed postfix. It is quite simple to configure (it is very good tutorial in gentoo wiki) and has all necessary features that I need out of the box. BTW if you have VPS you can have very cool email address, like yourname@step-inside.org. but I decided that my mailbox at gmail is enough for me and also I don’t want to fight with spam, so postfix is used only for local mail.
Everybody likes statistics. So do I. I have chosen awstats package. I recommend to install Geo-IP package and enable geoip plugin for awstats: you will see what countries your visitors come from. It was necessary to tune apache configuration slightly so awstats can understand its logs: CustomLog logs/access_log combined.
You most probably want to install logrotate , if you don’t want to find out that log files have eaten all your free disk space.
It is very important (and sometimes interesting) to know what your server is doing all those long and boring days and nights when it doesn’t server content of your site. I recommend to use logwatch for this purpose. It will check your log files every day and send summary report to your mail with description what happened. It requires some tuning after installation, particularly I have changed log directory for apache (in /etc/log.d/conf/logfiles/http.conf), and specified that cron and postfix do not use log files and instead rely on syslog service, so logs of these tools should be extracted from /var/log/messages file (in /etc/log.d/conf/services/cron.conf and /etc/log.d/conf/services/postfix.conf). After these changes still some tuning is necessary, but I haven’t figured out what exactly. Probably I will blog about it in future entries.
I was amazed that there were so much breaking attempts: dictionary attacks by SSH happen every day, when I installed apache I immediately started to receive a lot of requests for such URLs like:
/articles/mambo/index2.php?_REQUEST[option ... cho%20YYY;echo| /blog/xmlrpc.php /blogs/xmlsrv/xmlrpc.php /cvs/mambo/index2.php?_REQUEST[option]=com ... cho%20YYY;echo| /drupal/xmlrpc.php /index.php?option=com_content&do_pdf=1&id= ... cho%20YYY;echo| /index2.php?option=com_content&do_pdf=1&id ... cho%20YYY;echo| /mambo/index2.php?_REQUEST[option]=com_con ... cho%20YYY;echo| /phpgroupware/xmlrpc.php /xmlrpc.php
This brings another important issue: security. Gentoo developers pays a lot attention to it. So I have scheduled emerge sync and receive email with warning if my system is affected by any GLSA . Also I have disabled root logins via SSH (Tip: do not forget to add your main user to wheel group before doing it).
Other software packages that I have installed (and you can also find them useful):
Posted by ksh on March 30, 2006 | 0 comments | development, gentoo, linux, web
Development of Personal Site: Part 2 (Domain Name)
In this post I am going to describe process of choosing domain name, registering it and making it to be resolved to static IP address of my VPS server. I ran into some problems when was doing these tasks and want to describe these issues along with their solutions.
No one in the world really “owns” a domain name except the Network Information Centre, or domain name registry. But if you want to have one, you should register it. There are a lot of companies that offer domain name registration (so called Domain Name Registrars) for affordable price (just search for “register domain name” in google). UnixShell (my VPS provider) doesn’t provide such service, they decided to go true Unix way: do one thing and do it well.
Real problem with registering domain names is that the name you want to have can be already owned by someone. Alas, this was the case with name for our site. Originally we want to call it stepinside.org, but ended with step-inside.org (I also thought about calling it sepinsi.de :).
One thing that turned out to be harder then I expected was to associate my domain name with static IP address of my VPS server, but now I know much more details how DNS works :) And I want to share my knowledge with you.
Originally I though that I would be able to login to the site of my registrar and using web interface configure my domain name to be resolved to my static IP address (i. e. create A-record in terms of DNS). Unfortunately they don’t provide such functionality or I am so dump, that haven’t figured out how to do it using provided web interface (but this means that average user also unable to do it).
Fortunately this task can be solved without help of your domain name registrar. Every domain name has so called WHOIS record. It contains such important information as owner of domain name, details about registrar, registration and expiry date and so on. Your registrar is responsible to maintain this record and you should be able to edit at least some details of WHOIS record of your domain name using web interface.
The most important thing for our task is a list of nameservers that are responsible for resolving domain name. You need to specify list of nameservers that are able to say that your domain name is resolved to certain IP address. For more details you can check very good overview of How DNS works .
You have two possibilities for such nameservers:
- run your own nameserver (such as bind or djbdns)
- use one of free DNS services, like EveryDNS.net
I’ve chosen the second one, because it is much easier :)
Posted by ksh on March 24, 2006 | 2 comments | development, web