Archive for February, 2011

Linux kernel development and debugging using Eclipse CDT

Friday, February 11th, 2011

This blog entry is inspired by Takis blog . This entry can be seen as the revised version of Takis blog entry with consideration to latest Eclipse and Linux Kernel versions.


The steps below would work on Debian, Ubuntu and Mint Linux. I have used Linux Mint.

You need latest version of Eclipse IDE for C/C++ Developers (I have used Helios). You can download from http://www.eclipse.org/downloads/

For rest of this guide you’d need several packages that you can install using following command

apt-get install git-core kernel-package fakeroot build-essential libncurses5 libncurses5-dev qemu kvm crash kexec-tools makedumpfile kernel-wedge libelf-dev asciidoc binutils-dev debootstrap genext2fs e2fsprogs

STEP 1: Get the Kernel source using git.

Run following command to clone the kernel source into your home folder:

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git ~/linux-2.6

STEP 2: Create a build directory

Create build directory in /mnt directory as its the best place to keep any mountable file system.

mkdir -p /mnt/build/linux-2.6

STEP 3: Configure kernel

First run make oldconfig, which will read the defaults from an existing .config and rewrite necessary links and files.

cd ~/linux-2.6
yes "" | make oldconfig

Now make changes to default configure to enable debugging options using menuconfig. You can also use xconfig if you’re using X.

make menuconfig O=/mnt/build/linux-2.6

Select “Kernel hacking” menu

Enable “Compile the kernel with debug info”

Enable “Compile the kernel with frame pointers”

STEP 4: Disable automatic build in Eclipse

Open Eclipse with CDT plugin

Kernel code is huge and we wouldn’t want to enable automatic building after every change.  Go to “Window->Preferences” menu, Select “General->Workspace” and deselect “Build automatically” checkbox

STEP 5: Add kernel project in Eclipse

Create a new project. Go to  File->New->Project then select C Project.

Click Next

Enter project name – I have used linux2.6

Uncheck “Use Default Location” and select the linux source directory (~/linux2.6 in my case)

Select “Empty Project” under “Makefile project” as Project Type

Select Linux GCC as Toolchain

Click Next

Keep default values in Select Configurations window

Click Finish

Now eclipse will import the kernel source into the project and index it. This will take a while. Once complete all progress bars will disappear and the UI will look similar to below:

STEP 6: Configure build properties in Eclipse

Right click on Project and click on “Properties” from context menu.

Select “C/C++ Build” in properties window.

Uncheck “Use default build command”

Set build command as – make  O=/mnt/build/linux-2.6

Set build directory as – /mnt/build/linux-2.6

Now the project is ready to build. Go to the menu-bar select “Project->Build all”.

If all goes well then after some time the Linux kernel build will be completed.

STEP 7: Configure debug settings in Eclipse

Right click on Project. Click on “Debug As ..” >> “Debug Configurations”

Double Click on “C/C++ Attach to Application”

Select vmlinux binary (in my case /mnt/build/linux-2.6/vmlinux) in C/C++ Application field on Main tab

Click on Debugger tab

Select GDB Server in Debugger option under main tab

Click on Connection tab

Select TCP in Connection “Type” field

Enter localhost in “Host name or IP address” field

Enter 1234 in “Port Number” field

STEP 8: Prepare a root filesystem for testing kernel

You’d need a root filesystem in order to boot and test the kernel. I prefer not using filesystem of my host machine. Here is a recipe to build a basic 8GB root file system

cd /mnt
sudo debootstrap sid sid

echo -e "rootnroot" | chroot sid passwd
echo -e "auto loniface lo inet loopbacknauto eth0niface eth0 inet dhcp" > sid/etc/network/interfaces
ln -sf vimrc sid/etc/vimrc.tiny
rm -f sid/etc/udev/rules.d/70-persistent-net.rules
echo atul > sid/etc/hostname
echo cgroup /mnt/cgroup cgroup defaults >> sid/etc/fstab
mkdir -p sid/mnt/cgroup

BLOCKS=$(((1024*$(du -m -s sid | awk '{print $1}')*12)/10))
genext2fs -z -d sid -b $BLOCKS -i 1024 sid.ext3
resize2fs sid.ext3 8G
tune2fs -j -c 0 -i 0 sid.ext3
rm -rf sid

Notice I have setup root password as “root”

STEP 9: Run QEMU to launch the kernel build

Use following command to startup QEMU

qemu -no-kvm -s -S  -kernel /mnt/build/linux-2.6/arch/x86/boot/bzImage -hda /mnt/sid.ext3 -append "root=/dev/sda"

In case you’re using 64 bit host the use following command

qemu-system-x86_64 -no-kvm -s -S  -kernel /mnt/build/linux-2.6/arch/x86/boot/bzImage -hda /mnt/sid.ext3 -append "root=/dev/sda"

At this point you’ll see a blank QEMU terminal window. The “-s” option is a shorthand for -gdb tcp::1234, i.e. open a gdbserver on TCP port
1234. The “-S” option stops the CPU to start at startup. Now QEMU is waiting for kernel to start in debug mode
STEP 10: Start Kernel in Debug mode
From the menu bar in Eclipse click on debug icon
Then click on Linux2.6 Default debug configuration to run from the drop down list.
Launching might take a while, you can see the progress a the bottom right progress bar

Once the application is ready to launch it will prompt you to open the debugging perspective. Click on Yes.

Now the Eclipse perspective will change form development to Debug

Click “Run > Step over” or press the “F6″ key to execute the kernel code line by line and examine what’s happening.
Or click “Run > Resume” or press the “F8″ key to execute the kernel code without breaks.

You can find several articles on CDT at http://www.eclipse.org/cdt/documentation.php

Here is the updated URL to Taki’s blog – http://issaris.org/blog/2007/12/14/debugging-the-linux-kernel-using-eclipsecdt-and-qemu/

PostgreSQL Databases Backup & Restore with pg_dump command

Friday, February 11th, 2011

Make sure you should conncete to your server via ssh command line.
Login as super user type the following command.

[root@linux10 ~]#su – postgres

Get list of database(s) to backup.

[postgres@linux10 ~$]#psql -l

List of databases

Name | Owner | Encoding | Collation | Ctype | Access privileges


postgres | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 |

mine | mine | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 |

template0| postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres


template1 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres

: postgres=CTc/postgres

(4 rows)




Make a backup using pg_dump, pg_dump is a utility for backing up a PostgreSQL database. It dumps only one database at a time.

Dump a mine database:-

[postgres@linux10 ~$]#pg_dump mine > /opt/mine.out

To restore a mine database:-

[postgres@linux10 ~$]#psql -d mine -f mine.out

Or, If you have new server first create database then apply command:-

[postgres@linux10 ~$]#createdb mine
[postgres@linux10 ~$]#psql mine
[postgres@linux10 ~$]#psql -d mine -f mine.out

Second option is use to pg_dumpall command.It dumps (backs up) each database, and preserves cluster-wide data such as users and groups. You can use it as follows:-

[postgres@linux10 ~$]#pg_dumpall > /opt/all.db.out

To restore backup use the following command:

[postgres@linux10 ~$]#psql -f all.db.out postgres

Subversion Installation on Ubuntu 10.04

Tuesday, February 8th, 2011

Make sure you should login as root:–

[root@linux10 ~]#apt-get install apache2
[root@linux10 ~]#apt-get install subversion libapache2-svn

The next command is configure the user access for subversion.

[root@linux10 ~]#htpasswd -c /etc/subversion/passwd username

Where username is a new user. All subsequent users are created by doing the following

[root@linux10 ~]#htpasswd /etc/subversion/passwd username

It is important to note if you have the ‘-c’ command it WILL overwrite the existing user file. So run this command only first time.
Now you need to decide where you want to put your repositories. I suggest you put them all under one root path, for example /srv/svn/yourproject. For each repository you want create a new folder in the svn root folder and then run the following command to turn it into a repository.

[root@linux10 ~]#mkdir /srv/svn/
[root@linux10 ~]#mkdir /srv/svn/yourproject/
[root@linux10 ~]#svnadmin create /srv/svn/yourproject

We are going to use apache to serve the repositories so we need to make the svn root folder and all subsequent child files and folders accessable by apache. This is done by using the following command

[root@linux10 ~]#chown -R www-data:www-data /srv/svn/yourproject

The final part to getting repositories to be accessed from a web address add the following code to your sites apache config file located in /etc/apache2/mods-enabled/dav_svn.conf

[root@linux10 ~]#vi /etc/apache2/mods-enabled/dav_svn.conf

DAV svn
SVNPath /srv/svn/yourproject
AuthType Basic
AuthName “yourproject Repository”
AuthUserFile /etc/subversion/passwd
Require valid-user

The last thing to do is restart apache after saving the file

[root@linux10 ~]#/etc/init.d/apache2 restart

After browsing your project, If you have promte for user name and password that means you have done successfully.

Show Chinese characters on JSP pages using property files in web application

Friday, February 4th, 2011

Below is procedure to show Chinese characters on JSP pages using property files in web application.

  1. Create new property file for Chinese language of extension _zh.properties like ABC_zh.properties.
  2. Open the newly created property file in UTF-8 enabled editor like notepad or Edit+.
  3. Put the relevant key values in Chinese language. Like. customer.number=客户号码
  4. After setting all key values in property file, save file as encoding as UTF-8.
  5. Use tool native2ascii from JDK bin directory to convert Chinese characters to Unicode using following command by ensuring the encoding to UTF-8.
  6. Convert native to ASCII using following command:
    $JAVA_JOMEbin>native2ascii.exe -encoding UTF-8 ABC_zh.properties ABC_zh_1.properties
  7. Copy newly created ABC_zh_1.properties to original location of property files and renamed to ABC_zh.properties
  8. Add the following line in starting the weblogic server like


  9. Add following java options:
    set JAVA_OPTIONS=%JAVA_OPTIONS% %JAVA_PROPERTIES% -Dwlw.iterativeDev=%iterativeDevFlag% -Dwlw.testConsole=%testConsoleFlag% - Dwlw.logErrorsToConsole=%logErrorsToConsoleFlag% -Dfile.encoding=UTF-8
  10. Add the content type as UTF-8 in displaying JSP pages by adding following line at start of JSP file.
  11. Thats It !!!
  • © 2004-2015 Special Work & Technology Limited