You are here

Linux Hacks

Linux Hacks
Checked: 2 hours 37 min ago
Updated: 2 hours 37 min ago
Update every: 2 hours

Linux is the fast growing state-of-the-art OS. This blog will focus on new kernel features, Review of the best opensource software and news. HOWTO's will also be added from time to time based on interest.
Subscribe to Linux Hacks

Working with Big Patchsets

Linux Hacks - Sun, 30/01/2011 - 12:47pm
In the past, whenever there was a need for me to test or review huge patchsets, I'd generate individual patches by saving the mails containing them. This can get cumbersome, especially if the patchset is huge and if you have to try out multiple versions of the patches. There is however an alternative available. It is to obtain the mbox file pertaining to the entire patchset. The mbox file for kernel patches can be obtained from patchworks. The home page displays a list of projects that are hosted.

Avoid Kmail Editor And Use Vim Editor Instead

Linux Hacks - Wed, 26/05/2010 - 11:13am
Kmail has bad editor when it comes to sending patches inlined. More often the message gets mangled (word wrapped). To overcome this problem Kmail allows the use of external editor.

1. Settings->Configure Mail and Click on Composer
2. Click on "Use External Editor" and specify the editor as "xterm -e vim -f %f"
3. Click Apply.

Open the composer and type in mail id and subject and click on the body. When you start typing a new editor window opens up which is vim. Type in your message and type ":wq". Thats it.

Convert VCD T0 AVI (Xvid)

Linux Hacks - Thu, 22/04/2010 - 5:27am
A simple way to convert old vcds to avi(xvid) and not lose too much video quality is by using the tool mencoder.

Download and Install mencoder:
#sudo apt-get install mencoder

Start Conversion:
#mencoder vcd://2 -o movie.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=2000

Rip mp3 from cue/flac!

Linux Hacks - Tue, 20/04/2010 - 1:13pm
Here is a simple way to rip mp3 from flac files. There are few softwares that need to be installed for to work.

Download and Install Sound Converter For Linux. It can be downloaded from here.

Once Installed you can start up the application from the multimedia panel in the start menu.

Install additional packages
#sudo apt-get install flac mp3splt

Real-Time Linux Kernel Scheduler

Linux Hacks - Fri, 18/09/2009 - 5:38am
My article explaining the Real-Time Linux kernel scheduler is finally available for general reading on the Linux Journal site. You can read it here. Any feedback on the article are most welcome !

Dumping kernel page tables

Linux Hacks - Mon, 03/08/2009 - 5:32pm
Sometimes when debugging kernel issues, you might come across kernel addresses that you would find very difficult to map to a particular section in the kernel, ie, vmalloc, vmemmap, low/high kernel mapping, kernel text, etc. On x86, Arjan van de Ven has written an interface that provides a dump of the kernel page tables which gives information on the various memory areas in the kernel.

# cat /debug/kernel_page_tables
---[ User Space ]---
0x0000000000000000-0xffff800000000000 16777088T pgd
---[ Kernel Space ]---

Using gdb for debugging kernel modules

Linux Hacks - Fri, 24/07/2009 - 5:45am
This is a very simple and maybe trivial post.. and nothing novel ! But something that has helped me a lot in debugging issues with my kernel modules and kernel panics in general. So, when you get a panic originating in a kernel module, you normally get it in the following format:

BUG: unable to handle kernel NULL pointer dereference at 0000000000000050
IP: [<ffffffff8023262c>] mmput+0x11/0xb0
PGD 22bcf6067 PUD 211839067 PMD 0
Oops: 0002 [#1] SMP
last sysfs file: /sys/block/sdb/size

Looking at thread state inside gdb

Linux Hacks - Thu, 16/07/2009 - 5:21pm
While helping a friend debug a multi-threaded application hang on linux, using gdb. She was facing difficulty in pointing out exactly which were the threads that were in blocked state. Getting thread info only tells us what the thread ids are and the routine they are executing.

(gdb) info threads
12 Thread 4398053392560 (LWP 7234) 0x0000000010005740 in xxxx ()
11 Thread 4398054441136 (LWP 7235) 0x0000000010005740 in xxxx ()
10 Thread 4398055489712 (LWP 7237) 0x0000000010005748 in xxxx ()
9 Thread 4398063878320 (LWP 8263) 0x0000000010000768 in yyy ()

Build your kernel faster

Linux Hacks - Wed, 15/07/2009 - 4:06am
Normally when building custom kernels for our laptops or desktops, we tend to make use of the kernel config file used by the particular distro. However the distro config files tend to be huge, having loads of modules turned on, ven those which might not even be needed on our particular laptop or desktop. This is the case since the distro kernels need to cater to a large configurations of systems. . This leads to the kernel taking ages to compile !

Fake NUMA nodes in Linux

Linux Hacks - Tue, 07/07/2009 - 5:32am
While NUMA systems are becoming commonplace, many a times we do not have access to such systems when either writng new code, understanding NUMA architecture, conducting experiments or debugging existing code. For such cases, the Linux kernel provides a very neat feature called 'fake numa nodes'. One can create fake numa nodes on a non-NUMA machine by simply passing a commandline parameter to the kernel. Below are the steps for x86 systems:

Free up that memory

Linux Hacks - Mon, 22/06/2009 - 2:23pm
Recently came across this cool interface in the Linux kernel. Typically, the memory might be over-provisioned on the system. Instead of wasting the memory, the kernel normally utilizes a lot of it for page cache, dentry cache and inodes. These caches speed I/O operations and improves performance. However, there are cases when large amount of memory might actually be needed by the apps. While most of the cache pages could be easily reclaimed, there is obviously some overhead involved (the pages could be dirty and might have to written back to the disk, thus incurring disk write latency).

Importing .ics into Lotus Notes 8

Linux Hacks - Mon, 22/06/2009 - 2:22pm
A number of times I get calender invites for meetings on my non-Lotus notes email IDs. The calender invites are normally in the .ics format. Once can easily import it into Lotus Notes. Here is how:
  1. Compose a mail inside notes
  2. Attach the .ics file to it
  3. Right click the attachment, and click on "View"
  4. The calender view would open, with the meeting details. Now accept/decline the invite, save and exit
Voila, the entry gets saved to your calender. Ofcourse, there might be other ways to achieve this in notes :-)

Useful staps to track task movement across CPUs

Linux Hacks - Mon, 22/06/2009 - 2:22pm
Quite sometime back, I was faced with a situation where I needed to track instances when a particular task was being migrated away from a cpu. It was in the context of a real-time system, where a real-time task was facing huge context switch delays. Obvious suspect being the scheduler, I used systemtap to infer a few things, besides other debugging:
  • To find if the task was being migrated away to some other cpu, used the following trivial stap script:
/* Filename: migrate.stp

Using large pages

Linux Hacks - Mon, 22/06/2009 - 2:21pm
Linux has had support for large pages (also called huge pages) for a long time now. The size of large pages supported depends on the platform. For example, on Intel it has mostly been 2MB. Large pages offer the advantage of having fewer entries in the TLB and thus fewer cache misses. However, it could lead to more wastage of memory and fragmentation. Many applications typically use large pages for certain designation functions. For example, if supported and required number available, JVM heap is composed of large pages.

Simplifying GCC

Linux Hacks - Sat, 30/05/2009 - 6:25pm
GCC is the GNU Compiler Collection which provides C, C++ etc compilers. These compilers are used by default in all *nixes .

Here i provide simple command line options which can prove to be quite useful.

  1. The simplest way to use GCC to compile a C source file is

    $ gcc -o test test1.c test2.c

    gcc is the C compiler, test1.c and test2.c are the input C source files and -o lets us specify the name of the output file. Here it is "test". Without the -o option, "a.out" is the default executable that gets created.

Fix Thinkpad Function Keys/Hot Keys in kde 4.2 (Jaunty) - patch to display brightness levels.

Linux Hacks - Tue, 19/05/2009 - 9:13am
A small patch for the script to display the brightness level of your Thinkpad display with the brightness Increase/Decrease keys.

--- 2009-05-08 11:51:28.000000000 +0530                       
+++     2009-05-19 12:43:58.000000000 +0530               
@@ -1,6 +1,7 @@                                                           
 #!/usr/bin/env python                                                    

Fix Thinkpad Function Keys/Hot Keys in kde 4.2 (Jaunty)

Linux Hacks - Fri, 08/05/2009 - 10:50am
Function keys doent work by default in kde 4.2. Those who migrate from gnome to kde 4 find it difficult to adjust without the 'fn' keys. The problem is with powerdevil. The new applet does not have options to configure the acpi events. This will exits till powerdevil is fixed. As of now, we can use a python script to handle these events. Make sure python-2.6, python-dbus and python-xlib are installed in your system.

Create Desktop Shortcuts Using Cmd Line On KDE 4.2

Linux Hacks - Thu, 30/04/2009 - 8:46am
Here is a quick way to create desktop shortcuts for kde 4.2.
/usr/share/applications/ and /usr/share/applications/kde4 contains all the shortcut files (*.desktop).

Just copy what ever you want to ~/Desktop. Thats it!

fsck.ext3 Unable to resolve UUID error

Linux Hacks - Wed, 29/04/2009 - 4:08am
I installed Kubuntu 9.04 recently and within a day i ran into a peculiar problem. When i boot my system an error message "fsck.ext3 Unable to resolve UUID=". This error generally happens when there is some information mismatch between what is specified in /etc/fstab and what information the OS gives to fsck utility. In this case, its quite easy to solve the problem.

Enter the root password to enter the Maintenance mode when asked during boot.

(Control - D to continue):

List the partition table of your system.

#fdisk -l

Change/Resassign Interface Name In Linux

Linux Hacks - Tue, 28/04/2009 - 11:06am
Depending on the linux distro, the interface name given to network cards differ.

Sametime on Koepete

Linux Hacks - Mon, 16/03/2009 - 1:21pm
Last year cheezo had blogged about getting pidgin to support sametime protocol. It was great, but as KDE guy i missed it on Kopete. Its only recently i got myself to try it & viola it worked with just a little effort. I have the latest versions of these packages on my KDE 4.2.1 intrepid box (yes i live the bleeding edge tech, but any version of KDE 4.1.x which supports kdenetwork - 4:4.1.80-0ubuntu1 should do the job).

- kopete 4:4.2.1-0ubuntu1~intrepid1

Why linux keeps connected routes when link goes down?

Linux Hacks - Tue, 24/02/2009 - 10:14am
I came across this interesting discussion on a particular behavior of linux. This issues was brought up by a system administrator who was facing an interesting situation. When the link of an interface goes down possibly due to hardware failure or cable pull out, the ip address and routes associated with that interface is retained until someone explicitly deletes it. This behavior is built into linux for more than 10 years and the reason for this was stated by David Miller.

Theory Behind Hiding Zipped File Under Jpg Image

Linux Hacks - Wed, 04/02/2009 - 3:58am
The post Hiding Zipped File Under Jpg Image showed the steps to achieve data hiding in jpg. Since Ego was questioning the theory behind this, i decided to get my hands dirty and find the answer. To understand this, we need to understand the data structures of jpg image and zip files.
Lets bisect the jpg image first.
Jpg Header Format:

Start of Image (SOI) marker -- two bytes (FFD8)
JFIF marker (FFE0)

* length -- two bytes

Hiding Zipped Files Under Jpg Images

Linux Hacks - Tue, 03/02/2009 - 5:09am
Sometimes we come across situations when we have to hide certain files. There are many methods in which this can be accomplished. This is one of the many ways to do so. This applies to only zip file contents.

Step 1: Zip the file/folder to be hidden

#zip xyz.ppt

Lets assume that abc.jpg is the image we are using for the camouflage.
Step 2: Hide the zipped contents

#cat abc.jpg > new.jpg

Sample Code To Learn Netlink Infrastructure

Linux Hacks - Thu, 29/01/2009 - 2:21am
I always wanted to write an article explaining how netlink infrastructure works in the kernel and how we can make the best use of it. I dont have the time now, so in future it will happen. As of now i wanted to share a sample code that will help users get the system ip information to the user space.

#include <errno.h>
#include <error.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>


Subscribe to Linux Hacks