Tag Archives: Linux

Improving Debian 6 (Squeeze) fonts rendering

The default Terminal and desktop fonts rendering of Debian Squeeze are nice but when it comes to intensive web browsing, particularly in high resolution, Debian is not as much comfortable as other operating systems such as Mac OS, Ubuntu and Windows.

The following instructions and commands provide an easy way to improve the overall display rendering with minimal changes to enable bold effects in GNOME sessions for a pleasant Web browsing experience with Google Chrome.

1. Update fonts configuration files.

Switch to root user.

$ su -

Download the new fontconfig XML files.

# wget http://www.osresources.com/files/centos-windows-fonts/fontconfig.tbz

Backup old configuration files then extract new ones into /etc/fonts.

# for i in `ls /etc/fonts/*.conf`; do cp $i $i.bak; done
# tar xvjpf fontconfig.tbz -C /etc/fonts/

Clean up.

# rm fontconfig.tbz

Exit root session.

# exit

Restart your GNOME session.

$ gnome-session-save --logout

2. Download, install and configure Google Chrome.

Switch to root user.

$ su -

Debian Squeeze comes with Chromium Web Browser version 6.x. Download and install the latest version of Google Chrome. Replace i386 by amd64 if your operation system is 64 bits.

# wget https://dl.google.com/linux/direct/google-chrome-stable_current_i386.deb
# dpkg -i google-chrome-stable_current_i386.deb

If you get the following message:

Errors were encountered while processing:

Then install missing dependencies as follows:

# apt-get -f install

Clean up and exit root session.

# rm google-chrome-stable_current_i386.deb
# exit

Run Google Chrome by opening Applications > Internet > Google Chrome or by issuing the following command:

$ google-chrome &

Click on the wrench icon in top right corner and select Preferences. In the Under the Hood tab, set Page zoom to 125%.


Installing VMware Tools on Debian 6 (Squeeze)

VMware Tools are an optional set of drivers and utilities that can greatly improve the speed, efficiency and manageability of the virtual machine’s guest operating system. These tools allow cut and paste, mouse and clock synchronization, folder sharing across environments and several other key benefits.

This tutorial has been tested on Debian Squeeze running on VMware Workstation 8. The following steps should work on all the latest versions of Debian and VMware Workstation/Player.

1. In an X session, launch a Terminal and switch to root user.

$ su -

2. Update your system.

# apt-get update

3. Install kernel headers and tools required to compile and install VMware Tools.

# apt-get install make gcc linux-headers-$(uname -r)

4. Mount the VMware Tools virtual CD.

In VMware Workstation menu, click VM then select Install VMware Tools… menu item. This will put a VMware Tools CD icon on the desktop and a File Browser window should be opened immediately.

If the file browser doesn’t open or it is empty, then in the VMware Workstation menu, click VM, choose Cancel VMware Tools Installation, accept if asked to disconnect the CD-ROM and try again this step.

5. Extract VMware Tools to the tmp directory.

# cd /media/cdrom
# tar -C /tmp -zxvf VMwareTools-*.tar.gz

6. Start the installation.

# cd /tmp/vmware-tools-distrib
# ./vmware-install.pl

Accept the defaults for every question.

7. Clean up.

# cd /tmp
# rm -rf vmware-tools.distrib

8. VMware Tools is now installed and configured. Restart the machine to get all features working.

# reboot

Building embedded ARM systems with Crosstool-NG

This tutorial deals with creating a minimal embedded ARM system from scratch. The approach taken here requires no additional hardware beyond the development host and the source code of the required softwares. QEMU is used to run and debug the ARM system.

This tutorial details the following topics:

    • Building a toolchain for ARM using Crosstool-NG.
    • Building QEMU with ARM system emulation support.
    • Building an ARM Linux kernel.
    • Building and extending a tiny filesystem from scratch, based on BusyBox.
    • Debugging ARM applications inside QEMU.

I intentionally kept the default settings when applicable for simplicity and clarity reasons. Many things can be tweaked; you are encouraged to try alternate ways to become familiar with embedded systems.


When writing this tutorial, I used the following environment:

Created a working folder:

$ mkdir -p ~/dev-embedded/ctool-ng

Building Crosstool-NG

Crosstool-NG allows building cross-compiling toolchains for multiple target architectures. This versatile tool provides a menuconfig configuration interface, which makes it quite easy to use. Crosstool-NG comes with a set of ready-made configuration files for various typical setups and supports glibc, uclibc and eglibc.

Install needed packages:

$ sudo apt-get install build-essential libncurses5-dev
$ sudo apt-get install automake libtool bison flex texinfo
$ sudo apt-get install gawk curl cvs subversion gcj-jdk
$ sudo apt-get install libexpat1-dev python-dev

Download, configure and install Crosstool-NG locally using —local option (Note that is possible to install it globally):

$ cd ~/dev-embedded/ctool-ng
$ wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.13.2.tar.bz2
$ tar xjf crosstool-ng-1.13.2.tar.bz2
$ cd crosstool-ng-1.13.2
$ ./configure --local
$ make
$ make install

Crosstool-NG comes with a set of ready-made configuration files for various typical setups called samples. They can be listed by running:

$ ./ct-ng list-samples

Use the ARM EABI cross compiler for use on linux. Configure and produce this toolchain by issuing:

$ ./ct-ng arm-unknown-linux-gnueabi

Refine your configuration by running the menuconfig interface:

$ ./ct-ng menuconfig

At this point it is up to you to select what options you want. You can explore the available options by traveling through the menus and looking at the help for some of the options.

I recommend the following minimal change:

In Path and misc options, set Number of parallel jobs to 2 times the number of CPU cores in your workstation. This causes a faster building of your toolchain.

Disable Fortran and Java programming languages, if you are not going to use them:
In C compiler options, uncheck Fortran and Java.

Build Crosstool-NG:

$ ./ct-ng build

The operation Retrieving needed toolchain components’ tarballs starts. The ./build.log file is useful to track issues. If you get a problem related to fetching a tarball then try downloading the same version from another location or mirror into ./.build/tarballs folder and rerun the ./ct-ng build command.

Compilation takes a long time, be patient.

For the subsequent steps in this tutorial, you need to add path of executables you just installed to your PATH environment variable by issuing the following command:

$ export PATH=$PATH:$HOME/x-tools/arm-unknown-linux-gnueabi/bin

If you want to make it session wide then add the previous command to ~/.bashrc or ~/.pam_environment.

Now, you can verify that your ARM toolchain works by typing:

$ arm-unknown-linux-gnueabi-gcc -v

Building an ARM Linux kernel

This ARM kernel, built with a predefined configuration for the versatile platform board, will be used in the QEMU virtual machine.

Download and configure the kernel:

$ cd ~/dev-embedded/ctool-ng
$ wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.tar.bz2
$ tar xjf linux-3.2.tar.bz2
$ cd linux-3.2
$ make ARCH=arm versatile_defconfig
$ make ARCH=arm menuconfig

The last command brings up the kernel configuration menu, go to the Kernel Features section, check Use the ARM EABI to compile the kernel then exit (Make sure to save your changes).

Compile the kernel:

$ make ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi- all

Once it’s done building, the compressed kernel image is located at ./arch/arm/boot/zImage.

Building QEMU

QEMU is a high performance full system simulator supporting both emulation and virtualization. QEMU supports emulating several CPU architectures that are different from the host running the simulation. QEMU is used as the core device model by both Xen and KVM.

Install needed packages:

$ sudo apt-get install zlib1g-dev libsdl-dev

Download, configure and build QEMU from source:

$ cd ~/dev-embedded/ctool-ng
$ wget http://download.savannah.gnu.org/releases/qemu/qemu-0.14.1.tar.gz
$ tar xzf qemu-0.14.1.tar.gz
$ cd qemu-0.14.1
$ ./configure --enable-sdl --disable-kvm --enable-debug --target-list=arm-softmmu
$ make

The executable located at ./qemu-0.14.1/arm-softmmu/qemu-system-arm is the full system emulator for the ARM architecture.

Building GNU Hello

The very simple GNU Hello program, a minimal example of a GNU package that prints Hello, world‘ when you run it, will be debugged in the QEMU virtual machine.

Download, configure and build GNU Hello:

$ cd ~/dev-embedded/ctool-ng
$ wget http://ftp.gnu.org/gnu/hello/hello-2.7.tar.gz
$ tar xzf hello-2.7.tar.gz
$ cd hello-2.7
$ CC=arm-unknown-linux-gnueabi-gcc ./configure --host=arm-unknown-linux-gnueabi
$ make

The ARM-executable is located at ./hello-2.7/src/hello.

Building BusyBox

BusyBox combines tiny versions of many common UNIX utilities into a single small executable, including a shell and an init process. BusyBox is used extensively to build embedded systems of many types and is customizable so that only the needed utilities are built.

Download, configure and build BusyBox from source:

$ cd ~/dev-embedded/ctool-ng
$ wget http://busybox.net/downloads/busybox-1.19.3.tar.bz2
$ tar xjf busybox-1.19.3.tar.bz2
$ cd busybox-1.19.3
$ make ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi- defconfig
$ make ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi- install

A folder, containing a minimal root filesystem, called _install is created.

Customizing the filesystem

In order to debug the GNU Hello program, a customization of our minimal filesystem created in the previous section is required. First, copy the following:

  • gdbserver built with arm-unknown-linux-gnueabi.
  • GNU hello executable compiled previously.

Copy required executables:

$ cd ~/dev-embedded/ctool-ng
$ cd busybox-1.19.3/_install
$ CROSSTOOLNG_DIR=$HOME/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/
$ cp $CROSSTOOLNG_DIR/debug-root/usr/bin/gdbserver usr/bin/
$ cp ../../hello-2.7/src/hello usr/bin/

The minimal filesystem still lacks some shared libraries to run busybox, gdbserver and hello programs. These missing libraries can be enumerated using arm-unknown-linux-gnueabi-readelf (created when building the ARM toolchain) as following:

$ arm-unknown-linux-gnueabi-readelf ./usr/bin/hello -a |grep lib
$ arm-unknown-linux-gnueabi-readelf ./usr/bin/gdbserver -a |grep lib
$ arm-unknown-linux-gnueabi-readelf ../busybox -a |grep lib

After analyzing these commands output, you likely just needed to add the following libraries:

$ mkdir -p lib
$ cp $CROSSTOOLNG_DIR/sysroot/lib/ld-linux.so.3 lib/
$ cp $CROSSTOOLNG_DIR/sysroot/lib/libgcc_s.so.1 lib/
$ cp $CROSSTOOLNG_DIR/sysroot/lib/libm.so.6 lib/
$ cp $CROSSTOOLNG_DIR/sysroot/lib/libc.so.6 lib/
$ cp $CROSSTOOLNG_DIR/sysroot/lib/libdl.so.2 lib/

To add networking capabilities to the guest ARM system side and optionally use the same keyboard layout as your host machine, you need to create additional folders in the filesystem:

$ mkdir -p proc sys dev etc etc/init.d

Optionally, create a BusyBox-compatible keymap, in the filesystem, from the currently loaded keymap of your host:

$ sudo busybox dumpkmap > etc/host.kmap

The default initialization script that BusyBox searches for is /etc/init.d/rcS. Instead of using inittab, this is the preferred method to initialize an embedded system based on BusyBox. Create the rcS script as follows:

$ cat > ./etc/init.d/rcS << EOF

# Mount the /proc and /sys filesystems
mount -t proc none /proc
mount -t sysfs none /sys

# Populate /dev
/sbin/mdev -s

# Enable the localhost interface
ifconfig lo up

# Manually configure the eth0 interface. Note that QEMU has a built-in 
# DHCP server that assigns addresses to the hosts starting from
ifconfig eth0 netmask
route add default gw

# Comment this line if changing your keyboard layout is not needed
loadkmap < /etc/host.kmap

Add executable permission to the rcS script:

$ chmod +x etc/init.d/rcS

Create a compressed filesystem image:

$ find . | cpio -o --format=newc | gzip > ../../rootfs.img.gz

Running and debugging ARM applications

QEMU has all required components prepared (a compressed kernel image and a customized compressed filesystem image) and is ready to run the embedded ARM system.

Run the platform with the following command:

$ cd ~/dev-embedded/ctool-ng
$ ./qemu-0.14.1/arm-softmmu/qemu-system-arm -M versatilepb -m 128M -kernel ./linux-3.2/arch/arm/boot/zImage -initrd ./rootfs.img.gz -append "root=/dev/ram rdinit=/sbin/init" -redir tcp:65000::65000

The redir option will redirect any TCP communication from port 65000 of host system to port 65000 of the guest ARM system. This arbitrarily unused port number is chosen for testing purposes.

The ARM system will boot in a QEMU window then displays the message Please press Enter to activate this console. Press enter and you should be presented with an interactive shell. Start the debugging server as follows:

$ gdbserver --multi localhost:65000

Open a new terminal window, and install the ddd debugger:

$ sudo apt-get install ddd

Edit a configuration file, for example exec-commands.dbg, using the following commands:

$ cd ~/dev-embedded/ctool-ng
$ cat > ./exec-commands.dbg << EOF 
set solib-absolute-prefix nonexistantpath
set solib-search-path $HOME/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/
file ./hello-2.7/src/hello
target extended-remote localhost:65000
set remote exec-file /usr/bin/hello
break main

Run the ddd debugger as follows:

$ export PATH=$PATH:$HOME/x-tools/arm-unknown-linux-gnueabi/bin
$ ddd --debugger arm-unknown-linux-gnueabi-gdb -x exec-commands.dbg

You should see a breakpoint in the main function in hello.c file.

Dual boot Windows 7 Starter and Ubuntu

Recent netbooks come pre-installed with Windows 7 starter and support booting from USB/Removable storage devices. This tutorial describes the additional steps to dual boot with Ubuntu (10.04 or higher) and to tweak Grub2 configuration.


The minimum requirements are:

    • BIOS support for booting from any removable devices.
    • USB flash drive with at least 2 Go of storage space.
    • Internet connexion.

In the next sections, I assure that your BIOS boot order is configured to try Removable Devices first (You need to enter the BIOS setup utility, locate and navigate to the Boot Order options then make and save changes).

Hard disk setup

Pre-installed Windows 7 Starter often occupies the entire disk space. That means you are not allowed to make any new partition to install Ubuntu without changing partitions layout. Although, Windows includes a built-in functionality in Disk Management to shrink and expand partitions, I present another method based on open-source tools that can be used for general disk partitioning purposes:

1. Download and install LinuxLive USB Creator.
2. Download the GParted Live iso file.
3. Create a Bootable Flash Drive: Run LinuxLive USB Creator to install the GParted Live on an USB flash drive.
4. Reboot your netbook using the newly created bootable media.
5. Partition your drive by making enough free space for the future Ubuntu installation (You can also create a Data partition for your needs).

Ubuntu installation

The installation requires the following steps:

1. Log on to Windows 7 Starter again, insert the USB flash drive then open Download Ubuntu.
2. Follow the instructions in Burn your CD or create a bootable USB stick section to create an Ubuntu USB flash drive based installer.
3. Reboot your netbook using the newly created bootable media.
4. Install Ubuntu in the free space previously created. At the end of the installation process, let it install GRUB boot loader to the MBR of the disk.

Grub2 tweaks

The purpose is to change the way titles are displayed on the Grub2 menu and to remove unwanted entries.

1. Backup original files.

$ sudo cp /etc/grub.d/10_linux /etc/grub.d/10_linux.bak
$ sudo cp /etc/grub.d/30_os-prober /etc/grub.d/30_os-prober.bak
$ sudo chmod -x /etc/grub.d/*.bak

2. Remove memtest entry.

$ sudo chmod -x /etc/grub.d/20_memtest86+

3. Customize entries.

The /etc/grub.d/40_custom file is used to place custom entries. It also does not get overwritten by Grub updates.

Remove from the file /boot/grub/grub.cfg the lines enclosed by the following delimiters and add them to /etc/grub.d/40_custom (our Windows and Ubuntu installations will likely not change). Rename the title following each menuentry keyword or remove its associated section to reflect your installation.

### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###

Disable automatic detection of installed operating systems.

$ sudo chmod -x /etc/grub.d/30_os-prober

4. Change the Boot Order and Default Timeout.

These parameters can be changed by altering the values of GRUB_DEFAULT and GRUB_TIMEOUT in the /etc/default/grub file.

5. Update the grub and reboot to see the new changes.

$ sudo update-grub && sudo reboot

PostgreSQL driver for Windows and Linux

Due to license incompatibilities with the GPL, the QPSQL plugin needed to connect to a PostgreSQL database is not provided with open source versions of Qt.

This tutorial is about setting up a compete Qt development environment with PostgreSQL support for Windows 7 and Ubuntu 11.10 (Oneiric Ocelot). It also describes all steps necessary to build the QPSQL plugin for Windows using Qt SDK with MinGW.

Windows 7

1. Download Qt SDK for Windows at http://qt.nokia.com/downloads and install it.

The current version is Qt_SDK_Win_offline_v1_1_4_en.exe and its default installation folder is C:\QtSDK.

2. Download the source code associated to your Qt SDK version at http://qt.nokia.com/downloads.

Qt SDK version 1.1.4 uses qt-everywhere-opensource-src-4.7.4.zip. Unzip its content into C:\Qt\4.7.4 folder for instance.

3. For Windows 7 x64 (64-bit) you need to download a 32-bit version since it is not possible, at the moment, to compile the 64-bit version of PostgreSQL plugin.

Download PostgreSQL at http://www.postgresql.org and install it.

The current version is postgresql-9.1.1-1-windows.exe. The default PostgreSQL installation folder is C:\Program Files (x86)\PostgreSQL\9.1 (short path is C:\Progra~2\PostgreSQL\9.1) for Windows 7 x64 (64-bit) and C:\Program Files\PostgreSQL\9.1 (short path is C:\Progra~1\PostgreSQL\9.1) for Windows 7 x86 (32-bit).

4. Open Start > All Programs > Qt SDK > Desktop > Qt 4.7.4 for Desktop (MinGW).

5. Run these commands to build the QPSQL plugin (change according to your environment and make sure you use short path type):

set QTSDK_SQLDRIVERS_PATH=C:\QtSDK\Desktop\Qt\4.7.4\mingw\plugins\sqldrivers
set QT_SRC_PATH=C:\Qt\4.7.4
set POSTGRES32=C:\Progra~2\PostgreSQL\9.1

cd %QT_SRC_PATH%\src\plugins\sqldrivers\psql

qmake "INCLUDEPATH+=%POSTGRES32%\include" "LIBS+=%POSTGRES32%\lib\libpq.lib" psql.pro

mingw32-make debug
mingw32-make release

copy release\libqsqlpsql4.a %QTSDK_SQLDRIVERS_PATH%
copy release\qsqlpsql4.dll %QTSDK_SQLDRIVERS_PATH%
copy debug\libqsqlpsqld4.a %QTSDK_SQLDRIVERS_PATH%
copy debug\qsqlpsqld4.dll %QTSDK_SQLDRIVERS_PATH%

These commands build a Release (qsqlpsql4.dll, libqsqlpsql4.a) and a Debug (qsqlpsqld4.dll, libqsqlpsqld4.a) versions of the QPSQL plugin. These 4 files are then copied into Qt SDK’s SQL drivers folder.

7. The QPSQL plugin uses additional DLLs located in bin folder under the PostgreSQL installation folder. You have to copy these DDLs to the same directory as your application binary.


Ubuntu 11.10 (Oneiric Ocelot)

1. Install Qt Creator.

$ sudo apt-get install qtcreator

2. Install PostgreSQL.

$ sudo apt-get install postgresql

3. Optionally, you can install pgAdmin III, a handy GUI for PostgreSQL administration.

$ sudo apt-get install pgadmin3

4. Install PostgreSQL plugin for Qt 4.

$ sudo apt-get install libqt4-sql-psql


Follow the following steps to check that everything is functional.

1. Create an empty Qt console application project.

2. Make sure you have QtSql Module in your project configuration file (.pro file) by adding this line:

QT += sql

3. Update the source code as follows:

#include <QtSql>

int main(int argc, char *argv[])
    QCoreApplication a(argc, argv);

    QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    qDebug() << "Has a valid QPSQL driver: " << (db.isValid() ? "YES" : "NO");

    return a.exec();

4. Compile and run the application (Under Windows, do not forget to copy the required DLLs from the bin folder located in the PostgreSQL installation folder). You should see:

Has a valid QPSQL driver: YES

Building a typical C/C++ Linux project

This tutorial is about building a typical C/C++ Linux project, an application linked against one static library and one shared library, using three different compilation methods: Makefiles, Autotools and CMake. A complete source code is available for download.

This tutorial is meant as a short technical guide for beginners looking for ready-to-use basic samples that they can easily study, understand and extend.

Source code

The typical C/C++ project is composed of an application, a shared library and a static library respectively coded in helloworld, helloshared and hellostatic folders.

The three compilation methods are illustrated as the following figure:

Each folder (the name is self-explanatory) refers to a compilation method and contains two scripts hello_clean_all.sh and hello_build_all.sh that can be called to, respectively, clean and build each project from scratch. The main.cc, helloshared.h, helloshared.cc, hellostatic.h, hellostatic.h source and header files are identical in all folders. Theses projects also show how to set RPATH to load a shared library (an alternative to the LD_LIBRARY_PATH environment setting, built in directories, updating /etc/ld.so.conf …).

I used Ubuntu 11.04 (Natty) as a development platform. I assume that you are familiar with installing packages. You need to install:

$ sudo apt-get install build-essential
$ sudo apt-get install automake
$ sudo apt-get install libtool
$ sudo apt-get install cmake

Makefile based project

A makefile is a text file that consists of a set of targets, dependencies and rules. Dependecies are statements to make a target (a target is usually an executable, a library or object file name). Rules are commands needed to construct the target. The contents are basically arranged as:

target: dependencies
[tab] commands

A Makefile based project is built using the make command. This command keeps track of which portions of the entire program have been changed and compiles only those parts which have changed by comparing the last-modification times.

A minimal Makefile based project requires only one file: The Makefile (a programmer-defined file).

Building and installing a Makefile based project is usually done as follows:

$ make
$ make install

Writing and debugging complex makefiles can be difficult due to their syntax. Many C/C++ projects still rely on makefiles for their automated builds. Consequently, reading and writing them is a valuable skill.

Autotools based project

Autotools make it easy for developers to create portable softwares across many Unix/Linux operating systems. They mainly refer to a collection of three tools: Autoconf, Automake, and Libtool.

Autoconf is used to generate a configure script.
Automake creates portable Makefiles that will be processed by the make utility.
Libtool manages the creation of static and dynamic libraries platform-independently.

A minimal Autotools based project requires only two files:

– Makefile.am: a programmer-defined file and an input file to automake. It specifies build requirements.
– configure.in: an input file to autoconf. It contains macro invocations and ordinary shell code that autoconf uses to build a configure script.

Building and installing an Autotols based project is usually done as follows:

$ ./configure
$ make
$ make install

The Autotools are sometimes hard to debug due to the interdependencies between M4 macros, automake and make constructs. Moreover, automake is very slow when dealing with large projects.

CMake based project

CMake is an open-source and a cross-platform tool that generates native build environments (Makefiles for UNIX/Linux, Visual Studio projects for Windows and Xcode for Apple). It also has minimal dependencies, requiring only C++ on the build system.

A minimal CMake based project requires only one file: The CMakeLists.txt (a programmer-defined file that contains the project settings and describes the flow control of the build process).

Building and installing a CMake based project is usually done as follows:

$ cmake ./

CMake is more intuitive than writing a standard Makefile or using Autotools. It also significantly reduces the complexity of cross-platform software development and maintenance processes. For all these reasons, this tool is highly recommended.


Complete source code at typical_cc++_linux_project (save the file locally as typical_cc++_linux_project.tar.gz).

Several items covered in this document would require their own tutorials. A good starting point is to start studying the hello_clean_all.sh and hello_build_all.sh scripts because they show all the required steps to compile each project type.