Hints

Watching System Calls

A suggested hint (thanks Neal):

Here's an example of using strace to see the system calls in Unix.  The   
utility is also know as truss under other versions of Unix.
  
#include <stdio.h>
  
int main (void)
{ 
  int age = 0;
  
  printf("Hello!\nEnter Your Age:");
  
  scanf("%d", &age);
  
  fprintf(stderr, "%d?! You are old!\n", age);
  
  return(1);
  
} 

(esus)#gcc hello.c -o hello

(esus)#strace ./hello 2> mytrace.txt

the mytrace.txt file will contain a listing of the Unix system calls that 
happened.

Tracking Down System Calls

From Stuart Howard:

Here is another method to look for system calls in a program.  Josh mentioned this method to me.  


cc -static <filename>	--this forces library calls inline(do a man on cc 
                          or gcc and it describes the static option)

objdump -dS <object-filename>

--objdump  displays  information  about  one  or more object
       files.  The options control what particular information to
       display.  This information is mostly useful to programmers
       who are working on the compilation tools,  as  opposed  to
       programmers  who  just  want  their program to compile and
       work.

       -d
       --disassemble
           Display   the  assembler  mnemonics  for  the  machine
           instructions from objfile.  This option only disassem­
           bles  those  sections  which  are  expected to contain
           instructions.
       -S
       --source
           Display source code intermixed  with  disassembly,  if
           possible.  Implies -d.


Your object dump results will be upwards of 90,000 lines of text.  You can 
output the results to a file with the ">" operator:  <objdump call> > file

Hints on Rebuilding and Installing the Linux Kernel (Ming)

To build a new kernel from scratch:

1. make mrproper
Cleans the whole source directory.

2. make config (or make xconfig...)
Generates .config and other configuration header files.

3. make depend
Builds source dependencies and generates .depend in all sub directories 
that contain kernel source.

4. make bzImage (or make zImage, make... depending on your desired 
compression level)
Compiles kernel, outputs bzImage (or zImage...) at arch/i386/boot/.

These 4 steps are only necessary when you make kernel for the first time. 
Later, after you make minor modifications, you can simply do the 4th step 
only. Also, it is a good idea to backup your old .config file before you 
do the mrproper.



To install the newly built kernel:

If you are confident that the new kernel will work, just run "make install" and the make program will automatically do the following 
chores for you:

Copy arch/i385/boot/bzImage (the kernel) to /boot and other kernel modules 
to /lib/modules;
Modify some other files in /boot directory, like module-info and 
System-map;
Update your /etc/lilo.conf to point to your new kernel;
Run lilo to install the new kernel in your boot menu.

Now you can simply reboot, your machine will boot with your new kernel.

But your new kernel may not work, it would be good if you can still fall back to your old kernel in that case. To achieve this, you might want to 
do the following 4 steps to be cautious:

1. cp /etc/lilo.conf /etc/lilo.conf.bak

2. make install
This will overwrite /etc/lilo.conf.

3. merge /etc/lilo.conf.bak into /etc/lilo.conf
So that you have one entry each for your new and old kernel in the boot menu. Consult 'man lilo.conf' for details.

4. lilo
This will actually put the two kernel entries specified in your lilo.conf into boot menu.

After you have done these steps and once you understand what "make 
install" does for you, in later build-and-install cycles, you may 
choose to copy the kernel image to /boot and run lilo only, without 
messing with lilo.conf again.

If you have further doubts, read the README file in the kernel source 
directory as well as the manpage for lilo.conf.

Ming 

More Hints on Rebuilding and Installing the Linux Kernel (Neal)

Thanks Ming!

On Fri, 1 Nov 2002, Minghui Jiang wrote:

> To build a new kernel from scratch:
> 
> 1. make mrproper
> Cleans the whole source directory.
> 
> 2. make config (or make xconfig...)
> Generates .config and other configuration header files.

  I would highly recommend using the existing .config file from your 
distribution which sould come installed with the kernel-source package 
from your installation CD.

  2A. cp .config .config.bak
  2B. make oldconfig

This will ensure that your new kernel will function EXACTLY like the one 
installed with the system.

  'make config' is no trivial thing.  If your selections (there are 
hundreds) differ from the stock kernel it may not boot, init may fail and 
devices may not work at all.

  Once you've done it a few times you can experiment with changing your 
kernel config.  It's highly instructive to use 'make xconfig' and browse 
around at all the options for what you want to include in your kernel.

>But your new kernel may not work, it would be good if you can still 
>fall back to your old kernel in that case. To achieve this, you might 
>want to do the following 4 steps to be cautious:
>
>1. cp /etc/lilo.conf /etc/lilo.conf.bak

   I would also recommend that you make a backup copy of your stock kernel 
in /boot.  It will be called something like vmlinuz-xxxxx.

   Do this BEFORE running 'make install'.

Thanks.

-- 
Neal Richter
Ph.D. Candidate, Computer Science, Montana State University

RPMfind

Here's the link to rpmfind.net

http://www.rpmfind.net
(Neal)