Friday, September 10, 2010

Process for buildin new kernel

Build the kernel

a. Download kernel

b. Untar it
c. make menuconfig
d. This Command builds the images in the *parent directory*
/usr/bin/fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers

Install the kernel
a. Move the packages to target machine and install

sudo dpkg --purge linux-headers-2.6.35.4-custom
sudo dpkg --purge linux-image-2.6.35.4-custom
sudo rm -f /boot/initrd.img-2.6.35.4-custom*

sudo dpkg -i linux-headers-2.6.35.4-custom_2.6.35.4-custom-10.00.Custom_amd64.deb
sudo dpkg -i linux-image-2.6.35.4-custom_2.6.35.4-custom-10.00.Custom_amd64.deb
sudo update-initramfs -c -k 2.6.35.4-custom

b. Update initramfs
sudo update-initramfs -c -k 2.6.35.4-custom

c. Update grub.conf.
Add initrd file path.
Edit the path of root device in kernel options from /dev/hda1 to /dev/sda1.


Reboot.. Hopefully it should come up with no kernel panics.

Wednesday, February 17, 2010

I would like to start a linux kernel tutorial. The idea of this blog is to provide me with a drive to complete the book. Linux Kernel Development by Robert Love.

You can access the pdf here.


Tuesday, January 5, 2010

ScreenCast in Ubuntu

a. Install gtk-recordmydesktop
Record your first screen cast using this software

b. Install Audacity: To remove noise
Get a wav file to be used with Audacity
ffmpeg -i out.ogv out.wav

c. Merge the edited wav file with original video file(Also convert it to avi)
mencoder -audiofile out.wav -oac mp3lame -ovc xvid -xvidencopts fixed_quant=4 -o out.avi out.ogv

Friday, August 7, 2009

Postgres from python

This snippet contains no validation whatsoever.

import psycopg2

connection = psycopg2.connect('dbname=product user=postgres host=127.0.0.1')
mark = connection.cursor()
query = """INSERT INTO PRODUCT(product_id, product, attribute) VALUES(%d, '%s', '%s')"""
statement = query % (1, "name", "attribute")
mark.execute(statement)
connection.commit()

Thursday, August 6, 2009

GeoIP with Maxmind's Geolite

I was searching for a python tool to determine approximate location from IP address.


You need to download 3 tars:

a. Geolite C library- Python module internally uses this C library
http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz

tar -xvzf GeoIP.tar.gz
cd GeoIP-1.4.6
./configure --libdir=/usr/lib/python2.5/site-packages/
make
make install

b. Python api:
http://geolite.maxmind.com/download/geoip/api/python/GeoIP-Python-1.2.4.tar.gz

tar -xvzf GeoIP-Python-1.2.4.tar.gz
cd GeoIP-Python-1.2.4

# Edit setup.py to adjust the library_dirs and include_dirs
library_dirs = ['/usr/lib/python2.5/site-packages/'],

python setup.py build
sudo python setup.py install

c. Download Data file (This you probably need to update periodically)
http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

Test your setup
--------------------------
(From: http://stackoverflow.com/questions/1163136/how-to-detect-the-country-and-city-of-a-user-accessing-your-site)

I do not completely understand how variables in library are accessed from python.. So I export this variable
export LD_LIBRARY_PATH=/usr/lib/python2.5/site-packages/

import GeoIP
gi = GeoIP.open("GeoLiteCity.dat", GeoIP.GEOIP_INDEX_CACHE | GeoIP.GEOIP_CHECK_CACHE)
print gi.record_by_name("74.125.67.100") # a www.google.com IP

{'city': 'Mountain View', 'region_name': 'California', 'region': 'CA', 'area_code': 650, 'time_zone': 'America/Los_Angeles', 'longitude': -122.05740356445312, 'country_code3': 'USA', 'latitude': 37.419200897216797, 'postal_code': '94043', 'dma_code': 807, 'country_code': 'US', 'country_name': 'United States'}

Monday, July 6, 2009

Simple unit convertor in python

This function uses the google calculator api
http://www.google.com/ig/calculator?hl=en&q=1EUR%3D%3FUSD

import urllib, urllib2
import socket

# Crawl header #
default_header = { 'User-Agent' :
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5) Gecko/2008121622 Ubuntu/8.10 (intrepid) Firefox/3.0.5;'}

def getpage(pageurl, pageargs = None, pageheaderargs = {}):
fail = 0
content = reply_header = None
pageheaders = default_header
pageheaders.update(pageheaderargs)
while True:
print pageurl
retry = 0
try:
params = urllib.urlencode(pageargs) if pageargs else None
req = urllib2.Request(pageurl, params, pageheaders)
page = urllib2.urlopen(req)
content = page.read()
reply_header = str(page.headers).split('\r\n')
page.close()
except urllib2.HTTPError, e:
retry = 1
except IOError, e:
retry = 1
except socket.timeout, e:
retry = 1
except socket.sslerror, e:
retry = 1
if retry:
fail += 1
if fail == 5:
print 'Failed to retrieve' + pageurl + ': ' + str(e)
return (reply_header, content)
else:
continue
break
return (reply_header, content)

def convert(unit1, unit2):
query = '1%s=?%s' % (unit1, unit2)
(header, content) = getpage('http://www.google.com/ig/calculator?hl=en&q=' + query)
reresult = re.search('rhs: \"(.*?) ', content)
result = reresult.expand(r'\1') if reresult else 'Error'
return result if result != '' else 'Error'

Wednesday, June 24, 2009

Python string strip function..

I just realized a super blunder, I have committed all my life

url = 'abcdc.com'
print url.strip('.com')
Expect: abcdc
Resut: abcd

Instead try
url.rsplit('.com', 1)

strip function takes in an array of characters and chops any pattern of characters in the array.. :(