Archive for category Linux

Reducing TIME_WAIT sockets in Nginx and Apache

Edit /etc/sysctl.conf and add

# Enables fast recycling of TIME_WAIT sockets.
# (Use with caution according to the kernel documentation!)
net.ipv4.tcp_tw_recycle = 1

# Allow reuse of sockets in TIME_WAIT state for new connections
# only when it is safe from the network stack’s perspective.
net.ipv4.tcp_tw_reuse = 1

After this run in terminal

sysctl -p

 

PS: DO NOT USE THIS IF YOUR CLIENTS ARE BEHIND A NAT (Thanks Jero).

,

1 Comment

Bind error (network unreachable) resolving

This problem usually occurs when bind is unable to query using a IPV6 network.

 

Apr 3 12:01:58 localhost named[5457]: error (network unreachable) resolving ‘static.ak.facebook.com.edgesuite.net/A/IN’: 2600:1401:2::2#53
Apr 3 12:01:58 localhost named[5457]: error (network unreachable) resolving ‘w.soundcloud.com/A/IN’: 2001:500:90:1::20#53

To avoid this:

-use an IPv6 network

or

-disable IPv6 in Bind

 

Disabling IPV6 in Bind:

/etc/default/bind9

# run resolvconf?
RESOLVCONF=yes

# startup options for the server
OPTIONS=”-4 -u bind”

Leave a comment

Reboot Linux box after a kernel panic

To reboot 10 seconds after a kernel panic

vi /etc/sysctl.conf
kernel.panic = 10

or

echo 10 > /proc/sys/kernel/panic

Leave a comment

Compile OpenCV

Install packages:

sudo apt-get install build-essential libgtk2.0-dev libjpeg62-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev

Download FFmpeg:

cd /usr/local/src

wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xvfj ffmpeg-snapshot.tar.bz2
cd ffmpeg
./configure --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libxvid --enable-x11grab --enable-swscale --enable-shared
make
make install
ldconfig

cd /usr/local/src

wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2/
tar xvfj OpenCV-2.3.1a.tar.bz2
cd OpenCV-2.3.1
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON .
make
make install

1 Comment

Using scratchbox2 and Ubuntu 11.10


Local machine environment:
- Ubuntu 11.10 64bits

Emulated environment:
- Debian Squeeze armel

Install in local machine:

sudo apt-get install scratchbox2 fakeroot
sudo apt-get install qemu-user qemu
sudo apt-get install gcc-arm-linux-gnueabi
sudo apt-get install cpp-4.4-arm-linux-gnueabi gcc-4.4-arm-linux-gnueabi gcc-4.4-arm-linux-gnueabi-base
sudo apt-get install cpp-4.5-arm-linux-gnueabi g++-4.5-arm-linux-gnueabi gcc-4.5-arm-linux-gnueabi

Init scratchbox configuration:

fakeroot debootstrap --variant=scratchbox --foreign --arch armel squeeze /path/root_fs http://ftp.br.debian.org/debian
sb2-init -n -c /usr/bin/qemu-arm MACHINE_NAME "arm-linux-gnueabi-gcc"

Install into emulated system:

apt-get install g++ rpm zlib1g-dev m4 bison libncurses5-dev gettext build-essential intltool libxml2-dev libtool

Compile outside the box:

cd source
sb2 ./configure
sb2 make -jN
sb2 make install DESTDIR=/path/root_fs

To change the crosscompiler toolchain install the script /usr/local/bin/switch_arm-linux-gnueabi.sh:

#!/bin/bash

if [ -z $1 ]; then
echo -e "\n Error: you need to define the arm-linux-gnueabi version"
echo -e " Usage: switch_arm-linux-gnueabi.sh \n"
exit
fi

if [ ! -f /usr/bin/arm-linux-gnueabi-cpp-$1 ]; then
echo -e "\n Error: arm-linux-gnueabi version $1 do not exist\n"
exit
fi

# Unlink symbolic links
sudo unlink /usr/bin/arm-linux-gnueabi-cpp
sudo unlink /usr/bin/arm-linux-gnueabi-gcc
sudo unlink /usr/bin/arm-linux-gnueabi-gcov

#Define new links for arm-linux-gnueabi
sudo ln -s /usr/bin/arm-linux-gnueabi-cpp-$1 /usr/bin/arm-linux-gnueabi-cpp
sudo ln -s /usr/bin/arm-linux-gnueabi-gcc-$1 /usr/bin/arm-linux-gnueabi-gcc
sudo ln -s /usr/bin/arm-linux-gnueabi-gcov-$1 /usr/bin/arm-linux-gnueabi-gcov
#EOF

1 Comment

Fixing problem The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY

gpg –keyserver pgpkeys.mit.edu –recv-key KEY
gpg -a –export KEY | sudo apt-key add –

Example:

gpg –keyserver pgpkeys.mit.edu –recv-key B5B7720097BB3B58
gpg -a –export B5B7720097BB3B58 | sudo apt-key add –

Leave a comment

Emulate ARM in Qemu

#Download Kernel and initrd

wget http://ftp.debian.org/debian/dists/testing/main/installer-armel/current/images/versatile/netboot/vmlinuz-2.6.32-5-versatile
wget http://ftp.debian.org/debian/dists/testing/main/installer-armel/current/images/versatile/netboot/initrd.gz

#Create disk

qemu-img create -f raw debian.img 5G

#Start qemu
qemu-system-arm -m 256 -M versatilepb -kernel vmlinuz-2.6.32-5-versatile -initrd initrd.gz -hda debian.img -append “root=/dev/rasudo kpartx -av debian.img

#Mount filesystem after install and copy kernel and initrd
sudo mount /dev/mapper/loop1p1 ./mnt/ -o loopm”
sudo kpartx -av debian.img
sudo mount /dev/mapper/loop1p1 ./mnt/ -o loop

#Start qemu again
qemu-system-arm -m 256 -M versatilepb -kernel vmlinuz-2.6.32-5-versatile -initrd initrd.img -hda debian.img -append “root=/dev/sda1”

More reliable information at http://richizo.wordpress.com/2010/11/15/installing-debian-arm-under-qemu

Leave a comment

Generating “random” passwords

dd if=/dev/random bs=2 count=6 | base64 –

Leave a comment

Fixing or replacing notebook’s keyboard / keys

Great reference and guides

http://www.laptopkey.com/

Leave a comment

Creating kernel header/include files

Sometimes when cross-compiling a kernel, the host machine requires the header files to compile programs locally.

To create them, go to your kernel source and:

make headers_install INSTALL_HDR_PATH=/destination

For example:

mkdir /tmp/header
make headers_install ARCH=arm INSTALL_HDR_PATH=/tmp/header

More information is available at your_kernel_source/Documentation/make/headers_install.txt

2 Comments