All posts by Faheem

lvreduce and lvextent a Linux partition, a quick “howto”!

Scenario : Yeah Disk space issues!! /var and /var/log are seperate partitions and /var/log is getting filled-up with the current logrotation settings which we dont want to change. /var is allocated with 50G and has got lot of free space left in it. So we decided to go-ahead with the decision to re-size the partitions and thereby providing more disk space to /var/log partition.

AIM paraphrased : Reduce the LVM partition for /var and then Expand /var/log

Execute the command lvdisplay to list the sizes of all logical volumes.

/dev/vg01/lv_var is the mouted partition for /var and
/dev/vg01/lv_var_log is the mounted partition for /var/log

The change has got two stages :

Stage 1: Reduce the Logical Volume /dev/vg01/lv_var size to 40G

Unmount /var partition before lvreduce.

Make sure /var of not being used by any process.

[bash][root@server ~]# lsof /var/
[root@server ~]#
[root@server ~]# fuser -m /var/[/bash]

Both the commands should not give us any output. If displayed then Stop  or Kill all associated programs/processes that are accessing /var .

[bash]fuser –m /var[/bash]

will list all the PID’s accessing /var.

Either kill the processes one-by-one or kill them all by executing the below command

[bash]fuser -km /var[/bash]


[bash]umount /var[/bash]

You may get the below error message while unmounting

[bash]umount: /var: device is busy
umount: /var: device is busy[/bash]

Make sure no processes are associated with /var partition

Just to be one the safer side execute the below commands again.

[bash]lsof /var
fuser -m /var[/bash]

and if no results are displayed, forcefully unmount the partition

[bash]umount -f /var[/bash]

Then run :

[bash]e2fsck -f /dev/vg01/lv_var[/bash]


[bash]resize2fs  /dev/vg01/lv_var 40G[/bash]
[bash]lvreduce -L40G /dev/vg01/lv_var[/bash]

Re-mount the partition :

[bash]mount /dev/vg01/lv_var /var[/bash]

Stage 2: Expand the Logical Volume /dev/vg01/lv_var_log size to 10G

To expand an LVM, there is no need to have it unmounted.


[bash]lvextend -L10G /dev/vg01/lv_var_log[/bash]
[bash]e2fsck -f /dev/vg01/lv_var_log[/bash]
[bash]resize2fs  /dev/vg01/lv_var_log[/bash]

lvdisplay and df -h should show the updated disk spaces.



Fix Toshiba battery issue for Linux

Its been a year since I made my last post and have been thinking about what I could write  to start posting again. I have finally found a perfect one. Yepieeee, Its about vexing Toshiba battery conflict with the kernel.  I have got my battery issue fixed after a long wait. First of all let me thank Steve who proposed the perfect resolution for this issue and many thanks to other people who were also part of this seeking for a resolution.

Here was the scenario.

Laptop Made : Toshiba L650 X5310

OS : Ubuntu, Centos, BackTrack Linux

Issue : None of them detects and show my battery status.

I have tried different versions of Ubutnu, distros, Kernels and none of them helped and hence raised a bug report at

Surprisingly the thread got replies/responses from many people who were having the same issue and none had a clue about the fix. But reply no:16 by George Moutsopoulos helped me to find the solution.

Old Results :

[bash]efheem@tuxjockey:~$ cat /proc/acpi/battery/BAT1/*
present:                 no
present:                 no
present:                 no
efheem@tuxjockey:~$ dmesg | grep batt
[    1.370268] ACPI: Battery Slot [BAT1] (battery absent)[/bash]

The cause of issue is because Toshiba included two sets of boot data that tell the OS what hardware exists in the machine. Windows reads the correct one whereas Linux doesn’t. We will need to build our own kernel to make this happen. We will need to extract the DSDT (Differentiated System Description Table) from the machine, the ASL modified, and a new AML DSDT can be compiled. The sections below show the way to tell Linux to use this modified DSDT instead of the version that came with the BIOS.

Get the original DSDL of machine:

[bash]# cat /sys/firmware/acpi/tables/DSDT > DSDT.dat[/bash]

Disassemble it

[bash]# iasl -d DSDT.dat[/bash]

Make the changes:

[bash]# vi DSDT.dsl[/bash]

search for line : OperationRegion (EMEM, SystemMemory, 0×FF808001, 0×FF)
and replace it with : OperationRegion (EMEM, EmbeddedControl, 0×00, 0×FF)
save the file.

Build it:

[bash]# iasl -tc DSDT.dsl[/bash]

This will create a file DSDT.hex (This file is used for kernel recompilation)

I received the below two errors during this compilation

N:B :- You can actually ignore these errors, this works even having these error unfixed. But if interested you can work out to get those fixed.  Else directly goto ‘Kernel Recompilation’ section.


[bash]DSDT.dsl  2656:                     0×00000000,         // Length
Error    4122 -                              ^ Invalid combination of Length and Min/Max fixed flags

DSDT.dsl  2663:                     0×00000000,         // Length
Error    4122 -                              ^ Invalid combination of Length and Min/Max fixed flags[/bash]


Fix : (If you didnt receive any error please skip this part )

open DSDT.dsl file and go to the line where iasl indicated the error. In my case I go to lines 2656 and 2663.

iasl is complaining about the “Length” line “0×00000000″. This is wrong. Look at the “Range Minimum” and “Range Maximum”. Open up your Kcalc or whatever you Gnome people use and change it to Numeral System Mode. Make sure HEX is selected and now we subtract the minimun range from the maximun range and then we add 1. Since the minimum range is 0 (And you can’t subtract 0) I will input  FEAFFFFF and then add 1 which gives me FEB00000  (Don’t get confused, I’m simply omitting “0x”, the calculator doesn’t need this). I change 0×00000000 to 0xFEB00000 by Length. So now it looks like this:

0×00000000,         // Granularity
0×00000000,         // Range Minimum
0xFEAFFFFF,         // Range Maximum
0×00000000,         // Translation Offset
0xFEB00000,         // Length

Line 2663 changed to

0×00000000,    // Granularity
0xFED40000,         // Range Minimum
0xFED44FFF,         // Range Maximum
0×00000000,         // Translation Offset
0×00005000,         // Length

compile again.

Kernel Recompilation :

Install necessary packages:

[bash]apt-get install fakeroot kernel-wedge build-essential makedumpfile kernel-package libncurses5 libncurses5-dev[/bash]
[bash]apt-get build-dep –no-install-recommends linux-image-$(uname -r)[/bash]
[bash]mkdir /root/source

cd /root/source

apt-get source linux-image-$(uname -r)[/bash]

NB: My uname -r was

[bash]cd linux-2.6.38[/bash]

(replace this with your kernel version)

copy kernel config file from your current kernel:

[bash]cp -vi /boot/config-`uname -r` .config[/bash]

now copy the DSDT.hex file to the include folder inside kernel source

[bash]cp DSDT.hex /root/source/linux-2.6.38/include[/bash]

open .config file we have just copied

[bash]vi /root/source/linux-2.6.38/.config[/bash]

Make the below changes


save and quit.

My pwd : /root/source/linux-2.6.38

start compiling the Kernel:

[bash]make menuconfig[/bash]

load the .config file, save the menu file and exit.

We are about to start the compile process . A little trick you can do is to set the CONCURRENCY_LEVEL variable to speed up the compile of the kernel. The number should be the number of processors you have plus one. So in my case I have a Intel Core i5 processor so I will add one with the 4 available.

[bash]cat /proc/cpuinfo | grep -i processor
processor    : 0
processor    : 1
processor    : 2
processor    : 3[/bash]

I have got 4 processors, so concurrency will be 4+1

[bash]# export CONCURRENCY_LEVEL=5[/bash]

Start Building :

Here I named my custom kernel as tuxsage, replace it with the one you wish.

[bash]# make-kpkg clean[/bash]
[bash]# fakeroot make-kpkg –initrd –append-to-version=-tuxsage kernel-image kernel-headers[/bash]

(This will take some time)

Once this is completed you will find the built kernel one directory up from your present directory

[bash]# cd /root/source
# dpkg -i linux-image-2.6.38.(This part will be whatever name you gave it).deb
# dpkg -i linux-headers-2.6.38.(This part will be whatever name you gave it).deb[/bash]

Make initramfs:

[bash]# update-initramfs -c -k 2.6.38+tuxsage (replace tuxsage with correct name)[/bash]

Update Grub :


Reboot to the New Kernel :)

UPDATE : If you are using latest Ubuntu (11.10) with kernel 3.0.0-12-generic then you can get my custom compiled kernel with battery fix downloaded directly from which you can install and use. Have a look at ReadMe.txt for install instructions.

N:B : This post was made very soon after I got this fixed and you may find typos and other errors. Will proofread and fix those soon if any :-)

References :

How to enable DKIM in cPanel server.

DomainKeys Identified Mail (DKIM) lets an organization take responsibility for a message while it is in transit and one can use this to prevent from getting blacklisted by the free email providers like Yahoo, MSN and Google. DKIM can increase the mail authenticity.

cPanel does not have an interface to enable DKIM like we have for SPF and Domain Keys. cPanel is still working on it for getting it implemented. However we can enable it manually by following the below steps.

Check if exim is compiled with DKIM support enabled.

[bash]root@server # /usr/sbin/exim -dd 2>&1 | grep Experimental_DKIM[/bash]

[bash]Support for: crypteq iconv() IPv6 PAM Perl OpenSSL Content_Scanning Old_Demime Experimental_SPF Experimental_SRS
Experimental_DomainKeys Experimental_DKIM[/bash]

Generate the SSL keys
[bash]cd /usr/local/cpanel/etc/exim[/bash]

[bash]openssl genrsa -out dkim.key 1024[/bash]

[bash]openssl rsa -in dkim.key -out dkim.public -pubout -outform PEM[/bash]

You will find two keys, dkim.key & dkim.public

Open dkim.public and copy the contents excluding the –Begin– and –End– section. This is your DKIM key.  Now open exim configuration file and append the below entries under the section ‘remote_smtp’

Sample file: vi /etc/exim.conf


driver = smtp
dkim_private_key=/usr/local/cpanel/etc/exim/dkim.key #path to the dkim.key key.
interface = ${if exists {/etc/mailips}{${lookup{$sender_address_domain}lsearch*{/etc/mailips}{$value}{}}}{}}
helo_data = ${if exists {/etc/mailhelo}{${lookup{$sender_address_domain}lsearch*{/etc/mailhelo}{$value}{$primary_hostname}}}


Now on WHM, open DNS editor for the particular domain and add the TXT entry with DKIM key like below.




Here p=the_key_you_have_copied_from_dkim.public

Restart exim and named services.

[bash]/scripts/restartsrv exim[/bash]

[bash]/scripts/restartsrv named[/bash]

To check whether DKIM is setup properly, send a mail to , if setup properly, you will get a reply like below ,else a failure message.


Subject:    AutoReply from


Date:    Sun, May 23, 2010 1:27 am




Or you can also test from

Exim: remove mails in queue from a particular sender.E

“spams”, its one of the major issue that a sys admin has to deal with throughout his job.  First you need to find the user who is generating it. You can get it from the mail headers.  Once you find the user, disable the script that was responsible for spams, but it may have already kept thousands(may be lacks) of mails in the exim queue waiting for its chance to get delivered.  To delete these mails one by one is impossible.  In a cPanel server having exim mail,  you can use the following command to delete mails in the current queue generated by that particular user only.

SSH into the server

exiqgrep -i -f | xargs exim -Mrm

-i print messages id
-f from address
-Mrm remove mails

Remove mails to a particular sender in the queue :-

exiqgrep -i -t | xargs exim -Mrm

-t to address

OpenVZ network down SIOCADDRT: Network is unreachable

Have you ever come across in a situation where the VPS is running, but network is unreachable?  OpenVZ VPS may be up and running, but network service will be down resulting downtime for websites hosted in it. If you try to restart the network, you will get the below error:
[root@pers ~]# /etc/init.d/network restart
Shutting down interface venet0:                            [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface venet0:  SIOCADDRT: Network is unreachable
SIOCADDRT: Network is unreachable
To fix this, SSH into the main node server and enter into the VPS and  then execute the below comand.
/etc/sysconfig/network-scripts/ifup-routes venet0:0

How to configure NAT with iptables on a VPS.

NAT ( network-address-translation ) with iptables  helps us in how to select the packets we want to mangle. We can easily configure NAT on a OpenVZ VPS by following the below steps.

Lets first consider a VPS in which NAT is not enabled. Trying to POSTROUTE from VPS throws you errors.

iptables -t nat -A POSTROUTING -s -o venet0 -j SNAT –to

or iptables -t nat -nvL

iptables v1.3.5: can’t initialize iptables table `nat’: Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

To Enable NAT :

* Login to Node server.

Check vzcinfiguration file to find whether NAT is enabled or not.

grep -i iptables /etc/vz/vz.conf

You will get

## IPv4 iptables kernel modules
IPTABLES=”ipt_REJECT ipt_tos ipt_limit ipt_multiport iptable_filter iptable_mangle ipt_TCPMSS ipt_tcpmss ipt_ttl ipt_length”

Add NAT to the configuration file.

vi /etc/vz/vz.conf

insert ‘iptable_nat’ on to the iptables modules.

## IPv4 iptables kernel modules

IPTABLES=”iptable_nat ipt_REJECT ipt_tos ipt_limit ipt_multiport iptable_filter iptable_mangle ipt_TCPMSS ipt_tcpmss ipt_ttl ipt_length”

Check NAT is loaded or not,

lsmod | grep nat

[root@node ~]# lsmod | grep nat
iptable_nat            43404  3
ip_nat                 53520  2 iptable_nat,vzrst
ip_conntrack          101396  6 iptable_nat,vzrst,ip_nat,vzcpt
nfnetlink              40392  2 ip_nat,ip_conntrack
ip_tables              57440  3 iptable_nat,iptable_mangle,iptable_filter
x_tables               52744  11 iptable_nat,xt_tcpudp,xt_length,ipt_ttl,xt_tcpmss,ipt_TCPMSS,xt_multiport,xt_limit,ipt_tos,ipt_REJECT,ip_tables


* Now save the paraments for the VPS to which NAT has to be enabled.

from node :

vzctl set VZID –iptables “iptable_nat iptable_filter iptable_mangle ip_conntrack ipt_conntrack ipt_REDIRECT ipt_REJECT ipt_multiport ipt_helper ipt_LOG ipt_state” –save

VZID is VPS ID, replace it with the correct one.

* Restart VPS

vzctl restart VZID

* Enter into the VPS

vzctl enter VZID

* Check for NAT

iptables -t nat -nvL

[root@vz ~]# iptables -t nat -nvL
Chain PREROUTING (policy ACCEPT 2 packets, 88 bytes)
pkts bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 1 packets, 72 bytes)
pkts bytes target     prot opt in     out     source               destination
0     0 SNAT       all  –  *      venet0           to:
0     0 SNAT       all  –  *      venet0           to:
0     0 SNAT       all  –  *      venet0           to:

Chain OUTPUT (policy ACCEPT 1 packets, 72 bytes)
pkts bytes target     prot opt in     out     source               destination

*Test whether you are able to postroute the packets on VPS.

iptables -t nat -A POSTROUTING -s -o venet0 -j SNAT –to

It should work.

Find Linux OS is 32 or 64bit.

There are several situations where you need to confirm whether your Linux OS installed  is 32bit or 64bit. People normally use uname -a to find it. But the following command will tell you exactly the machine   architecture.

getconf LONG_BIT

getconf utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, Section 12.2, Utility  Syntax.


[root@localhost ~]# getconf LONG_BIT
[root@localhost ~]#

My machine is 32bit.

songbird! iTunes for Ubuntu

Songbird is a opensource music player that utilizes the cross platform frameworks and will runs in Linux, Apple, Solaris & Windows.

You can get it downloaded for free from here

Linux System Requirements :

glibc 2.3.4 or later
XOrg 1.0 or later
gtk+2.10 or later
fontconfig (also known as xft)
1.5 GHz Pentium 4 or comparable
At least 512 MB of physical RAM
At least 100 MB of available space on your hard drive
16 bit sound card (Recommended: 32-bit Sound Card)
Speakers or headphones

Download the package and extract it.

tar -xzf Songbird_1.4.3-1438_linux-i686.tar.gz (replace with appropriate version)

cd Songbird


Accept the Terms & Conditions and the installation begins.






Songbird has a cool user interface with lots of control options. It can sync with major music edition cell phones. Add a song or build a playlist, and Songbird automatically syncs it to your phone or MP3 player, so you’re never without your favorite music.

How to transfer a cPanel account to DirectAdmin.

The file structure and back-ups for both control panels are entirely different and its quite difficult to restore the files transfered from one to another control panel manually. There is a script available which can convert a cPanel back-up to the format that of a DirectAdmin. The convert process is quite simple.

Download the conversion script from here .

*You can download it using the terminal :

wget -c

*Create two directories import and export :

mkdir import export

*untar the script

tar -xzf da.cpanel.import.9.4.tar.gz

You will get two files and defaults.conf. is conversion script and defaults.conf is the configuration file.

*Copy the cPanel back-up into the import directory.

*Edit defaults.conf to match the DA server IP and nameservers.

*Execute the script to get the back-up converted.


*Back-up could be found inside export directory and you may get it restored.