28 January 2010

linux 2.6.32 installation on Fedora Core 12

Download Linux 2.6.32 source code from here.
Download the config file for 2.6.32 from here.
vi /sbin/installkernel
>> /sbin/new-kernel-pkg --dracut ...
cd /usr/src/kernels
tar xjvf linux-2.6.32.tar.bz2
mv config.32.2 .config
make oldconfig
make
make modules_install
make install


Reference:
Fedora Core 11 Intallation
Linux 2.6.31 Installation
Linux 2.6.32 Installation

27 January 2010

make a mininal linux kernel from Fedora Core 12

Details about Fedora Core 11 installation click here.
1. allocate 12GB of HDD space
(don't select "Allocalte all disk space now")
2. Allocate 400MB of RAM
(required for graphical mode installation)
3. Install FC12 on VMware
4. Review and modify partitioning layout
(select "Create custom layout")
5. Delete VolGroup, sda1 and sda2 partitions
6. Create 800MB swap space
7. Create EXT4 file system and mount pount "/"
8. Un-select everything in software selection
9. Select the default repository
("Installation Repo")
10. Select "customize now" for software selection
11. Again un-select everything in software selection
12. A total of 200 packages will get installed.
mkdir /mnt/cdrom
vi /etc/fstab
>> /dev/cdrom /mnt/cdrom iso9660 defaults 0 0
mount /dev/cdrom
cd /mnt/cdrom/Pakages
rpm -ivh deltarpm* python-deltarpm* libxml2-python*
rpm -ivh createrepo*
cd /mnt
createrepo .
cd /etc/yum.repos.d/
vi fedora.repo >> enabled=0
vi fedora-updates.repo
>> baseurl=file:///mnt
>> #baseurl
>> #mirrorurl
>> enabled=1
>> gpgcheck=0
yum install ftp make which vim gcc ctags ncur*
yum install dhclient bzip2 man man-pages kernel-devel
yum install ntsysv gpm openssh* strace ...
vi /etc/syscofig/network-scripts/ifcfg-eth0
>> DEVICE=eth0
>> ONBOOT=yes
>> BOOTPROTO=dhcp
vi ~/.bashrc
>> alias vi='/usr/bin/vim'
vi /sbin/installkernel
>> /sbin/new-kernel-pkg --dracut ...

For the installation of kernel 2.6.32 refer here.
Other:
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora

Reference:
http://www.brandonhutchinson.com/cpio_command.html

23 January 2010

gcc internals - 2

.globl _start

.section .rodata
LC0: .string "hello world!!!\n"

.section .text
_start:
mov $LC0, %ecx
mov $15, %edx
mov $1, %ebx
mov $4, %eax
int $0x80

mov $42, %ebx
mov $1, %eax
int $0x80
as tiny.s -o tiny.o
gcc -Wall -s -nostdlib tiny.o -o tiny; (448 bytes)
ld -s tiny.o -o tiny; (320 bytes)
./tiny ; echo $?

#define VADDR 0x08048000

.globl _start

.section .text
ehdr:
.byte 0x7F
.ascii "ELF"
.byte 1,1,1,0,0,0,0,0,0,0,0,0 #16 (ELF magic header)
.short 2 #2 (type)
.short 3 #2 (machine)
.long 1 #4 (version)
.long start + VADDR #4 (entry)
.long phdr #4 (phdr offset)
.long 0 #4 ()
.long 0 #4 ()
.short ehdrsize #2 (ehdr size)
.short phdrsize #2 (phdr size)
.short 1 #2 (phdr no.)
.short 0
.short 0
.short 0
.equ ehdrsize, phdr - ehdr

phdr:
.long 1 #4 (type)
.long 0 #4 ()
.long VADDR #4 (virtual addr)
.long VADDR #4 (physic addr)
.long filesize #4 (file size)
.long filesize #4 (mem size)
.long 5 #4 ()
.long 0x1000 #4 ()
.equ phdrsize, start - phdr

start:
mov $LC0+VADDR, %ecx
mov $15, %edx
mov $1, %ebx
mov $4, %eax
int $0x80

mov $42, %ebx
mov $1, %eax
int $0x80

LC0:
.ascii "hello world!!!\n"
.equ filesize, end - ehdr

end:
cpp tiny.s > tiny.i
as tiny.i -o tiny.o
objcopy -O binary tiny.o tiny
chmod +x tiny


Referance:
http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
http://svn.gna.org/svn/grub4dos/branches/test/stage2/bootlacestart.S
http://timelessname.com/elfbin

gcc internals

gcc -v
gcc --print-search-dirs
gcc -print-prog-name=cc1
ld --verbose
objdump -h hello
objdump -d -j .text hello
readelf -S hello
objcopy -R .comment hello hello_new

objdump -t humble
nm humble

GCC Options:
-E (pre-process)
-S (assemble)
-c (compile)

.text    executable code
.data initialized global/local static variable.
.bss non initialized static global/local variable.

cat > hello.c << EOF
#include <stdio.h>
int main()
{
printf("hello world!!!\n");
_exit(0);
}
EOF
cat > hello.lds << EOF
SEARCH_DIR("/usr/lib"); SEARCH_DIR("/lib");
SECTIONS
{
. = 0x08048000 + SIZEOF_HEADERS;
.text : { *(.text) }
.rodata : { *(.rodata) }
.data : { *(.data) }
.got : { *(.got.plt) }
.bss : { *(.bss) }
}
EOF

gcc -E hello.c > hello.i
gcc -S hello.i
gcc -c hello.s
gcc hello.o -o hello
cpp hello.c > hello.i
`gcc -print-prog-name=cc1` hello.i
as hello.s -o hello.o
ld -dynamic-linker /lib/ld-linux.so.2 -Thello.lds -o hello hello.o -lc


Referance:
http://www.tenouk.com/ModuleW.html

12 January 2010

Linux, Sendmail and Gmail.com

i have tested this on Fedora code 7 only

Add these lines just before MAILER in the file "/etc/mail/sendmail.mc"
dnl
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl
LOCAL_DOMAIN(`cookie.uucp')dnl
define(`SMART_HOST',`smtp.gmail.com')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')
define(`ESMTP_MAILER_ARGS', `TCP $h 587')
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`CERT_DIR', `MAIL_SETTINGS_DIR`'certs')dnl
define(`confCACERT_PATH', `CERT_DIR')dnl
define(`confCACERT', `CERT_DIR/CAcert.pem')dnl
define(`confSERVER_CERT', `CERT_DIR/mycert.pem')dnl
define(`confSERVER_KEY', `CERT_DIR/mykey.pem')dnl
define(`confCLIENT_CERT', `CERT_DIR/mycert.pem')dnl
define(`confCLIENT_KEY', `CERT_DIR/mykey.pem')dnl
FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl
MASQUERADE_AS(`comcast.net') dnl
FEATURE(genericstable, `hash -o /etc/mail/genericstable') dnl
GENERICS_DOMAIN_FILE(`/etc/mail/genericsdomain')dnl
MAILER(local)dnl
dnl

mkdir /etc/mail/auth
touch /etc/mail/auth/client-info
chmod 700 /etc/mail/auth
chmod 600 /etc/mail/auth/client-info

update "/etc/mail/auth/client-info" with
AuthInfo:smtp.gmail.com "U:smmsp" "I:USER_ID" "P:PASSWD" "M:PLAIN"
AuthInfo:smtp.gmail.com:587 "U:smmsp" "I:USER_ID" "P:PASSWD" "M:PLAIN"

cd /etc/mail/auth
makemap -r hash client-info.db < client-info
make -C /etc/mail
echo "cookie!cookie!asterisk humble@testing.com" >/etc/mail/genericsdomain
service restart sendmail

echo "test mail contents" > ~/1
mail -s "Test Mail" MyMail@Domail.com < ~/1

mailq

Referance:
http://www.linuxha.com/other/sendmail/gmail.html
http://www.notesbit.com/index.php/scripts-unix/linux-sendmail-automation-and-comcast-net-how-to-setup

10 January 2010

new

1. NAT
2. PROXY
3. Port Forwarding
4. and iptables

iptables mystery - 2

Find "iptables mystery" first part here.

There are three tables (queues):
1. mangle table - which is responsible for the alteration of "qos" bits in the TCP header.
2. filter queue - which is responsible for packet filtering.
2.a. Input chain: Filters packets destined for the firewall.
2.b. Output chain: Filters packets originating from the firewall.
2.c. Forward chain: Filters packets to servers protected by the firewall.
3. nat queue - which is responsible for network address translation.
3.a. Pre-routing chain: NATs packets when the destination address of the packet needs to be changed.
3.b. Post-routing chain: NATs packets when the source address of the packet needs to be changed
#!/bin/sh
#nat.sh

# flush and delete all non-buildin chains
nat-flush.sh

# eth0 is connected to the internet
# eth1 is connected to a private LAN
# Set up IP FORWARDing and Masquerading
iptables -t filter -A FORWARD -i eth1 -o eth0 -j ACCEPT
iptables -t filter -A FORWARD -i eth0 -o eth1 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

echo 1 > /proc/sys/net/ipv4/ip_forward
#!/bin/sh
#nat-flush.sh

echo "Stopping firewall and allowing everyone..."

# flush all chains (INPUT, OUTPUT, FILTER, ...)
iptables -t filter -F
iptables -t nat -F
iptables -t mangle -F

# delete all non-buildin chains in the table
iptables -t filter -X
iptables -t nat -X
iptables -t mangle -X

iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -Z //Zero packet and byte counters in all chains.
iptables -L -v //List all rules in in the chains.

//Reject ping with reply "Host Unreachable"
1. chkconfig rsyslog on
2. service rsyslog restart
3. iptables -t filter -A INPUT -p icmp -j LOG
4. iptables -t filter -A INPUT -p icmp -j REJECT \
--reject-with icmp-host-unreachable
5. tail -f /var/log/messages

6. chkconfig iptables on
7. service iptables save // /etc/sysconfig/iptables


Reference:
Firewalls_Using_iptables
Linux Tutorial Iptables Network Gateway

06 January 2010

learning perl - 3

#!/usr/bin/perl
# ./test3.perl

if ($#ARGV < 0) {
print "usage ./test1.perl \n";
exit 0;
}

my %ages;
my $name = $ARGV[0];

%ages = (
humble => 27,
honey => 21,
joseph => 55,
philo => 50,
none => 100
);

if (not exists $ages{$name}) {
die "invalid name \"$name\"\n";
}

die "invalid name \"$name\"\n" if ($name eq "none");
$name ne "none" or die "invalid name \"$name\"\n";

print "age of $name is $ages{$name}.\n";

if ( 3 < 5 ) {
print "3 is less than 5\n";
} else {
print "5 is less than 3\n";
}

if ( "three" lt "five") {
print "\"three\" is less then \"five\"\n";
} else {
print "\"five\" is less then \"three\"\n";
}

output: ./test3.perl humble

age of humble is 27.
3 is less than 5
"five" is less then "three"

learning perl - 2

#!/usr/bin/perl
#./test2.perl

use warnings;
use strict;
my $i = 0;

foreach my $i (10..20) {
print "$i ";
}
print "\n";

$i = 9;
while ($i++ < 20) {
print "$i ";
}
print "\n";

$i = 10;
do {
print "$i ";
} while ($i++ < 20);
print "\n";

$i = 9;
until ($i++ == 20) {
print "$i ";
}
print "\n";


$i = 9;
while(1) {
last if $i++ == 21;
next if $i == 20;
print "$i ";
}
print "\n";

my @array = (10..20);
foreach (@array) {
print "$_ ";
$_ *= 2;
}
print "\n@array\n";


my $total = 0;
$total += $_ for @array;
print "total: $total\n";

output: ./test2.perl
10 11 12 13 14 15 16 17 18 19 20
10 11 12 13 14 15 16 17 18 19 20
10 11 12 13 14 15 16 17 18 19 20
10 11 12 13 14 15 16 17 18 19 20
10 11 12 13 14 15 16 17 18 19 21
10 11 12 13 14 15 16 17 18 19 20
20 22 24 26 28 30 32 34 36 38 40
total: 330

learning perl - 1

#!/usr/bin/perl
#./test1.perl

use warnings;
use strict;

if ($#ARGV < 0) {
print "usage ./test1.perl <0..11>\n";
exit 0;
}

my $month = $ARGV[0];
my $m;

my @q1 = qw(Jan Feb Mar);
my @q2 = qw(Apr May Jun);
my @q3 = qw(Jul Aug Sep);
my @q4 = qw(Oct Nov Dec);


my @smonth = (@q1, @q2, @q3, @q4);


print "@smonth[$month,5,7..9]\n";
print "$smonth[$month]\n";
print "array size: $#smonth\n";


### print the array
print @smonth,"\n";
print "@smonth\n";

### swap month 0 and 1
@smonth[0,1] = @smonth[1,0];
for $m (@smonth) { print "$m "; }
print "\n";

my @sortedmonth = sort @smonth;
print "@sortedmonth\n";
###
print reverse(@smonth),"\n";

print "@smonth[1..3]\n";

Output: ./test1.perl 3

Mar Jun Aug Sep Oct
Mar
array size: 11
JanFebMarAprMayJunJulAugSepOctNovDec
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
Feb Jan Mar Apr May Jun Jul Aug Sep Oct Nov Dec
Apr Aug Dec Feb Jan Jul Jun Mar May Nov Oct Sep
DecNovOctSepAugJulJunMayAprMarJanFeb
Jan Mar Apr


Reference:
http://www.perl.org/books/beginning-perl