Friday, 25 May 2012

Develop Linux kernel module using eclipse

Here is how I did on my Ubuntu 12.04.

First I have downloaded and installed Eclipse IDE for C/C++ Linux Developers in /opt/eclipse .
Just download and extract the archive, and simply run /opt/eclipse/eclipse .

The one provided by Ubuntu should work too, but require some more packages, at least eclipse-cdt.

As a module sample, I chose the one from article  A Simple Block Driver for Linux Kernel 2.6.31
Download or Cut&Paste sbd.c and Makefile in directory ~workspace/sdb (I prefer ~/Documents/workspace/sdb).
Be careful if you Cut&Paste, Makefile expect TAB instead of spaces !

Then create a new project in eclipse

And import the sources

Now when sdb.c is open in eclipse, you should see a lot of syntax errors !

To avoid these messages, you must add some paths and symbols to the project :
Right-click on your project and select properties at the bottom, then add the path of your Linux header files:

/usr/src/linux-headers-3.2.0-24-generic/include is where Ubuntu put the headers of my kernel. I found it doing a

# ls /lib/modules/`uname -r`/build
Don't forget the include at the end of both entries.

Then add symbols __KERNEL__ with value 1 and CONFIG_BLOCK without value. Maybe more variables could be required for more complex module.

After this, I still have problem with the macro module_param.
If you find the solution, please tell me !

Thursday, 17 May 2012

Ubuntu 12.04 and NoMachine NX

The biggest problem to use Unity (the default Desktop of Ubuntu 12.04) with NoMachine is that Unity use 3D accelerated hardware.
To use Unity with VNC or NoMachine you need to use unity-2d, a lighter version using Metacity instead of the 3D enabled Compiz

The simplest way to make it works is to select Unix and Custom :

and set this command in Custom - Settings

env DESKTOP_SESSION="ubuntu-2d" GDMSESSION="ubuntu-2d" /etc/X11/Xsession "/usr/bin/gnome-session --session=ubuntu-2d"

This line use Xsession instead of starting gnome-session directly. This is to setup some important environment variables like XDG_*. Unfortunately, Xsession looks to be buggy and need some help. This is why I setup the two variables DESKTOP_SESSION and GDMSESSION.

The probleme with this setup is that NoMachine client don't close smoothly and I need to Terminate the session.

To avoid this I edit file /usr/NX/etc/node.cfg and update line :

CommandStartGnome = "env DESKTOP_SESSION=ubuntu-2d GDMSESSION=ubuntu-2d /etc/X11/Xsession '/usr/bin/gnome-session --session=ubuntu-2d'"

And change my NoMachine client settings back to GNOME

Sometime the launcher bar on the left is not refreshed at startup. These icons are over all windows and then are not easy to refresh. To solve this problem I click logout in the "system" menu and move the windows over these icons. When icons are redrew I close the logout windows.