Thursday, October 20, 2011

Remote Kernel Compilation: Custom Installation Path

make a directory myinstall

#> make modules_install INSTALL_MOD_PATH=myinstall
#> make install INSTALL_PATH=myinstall
#> make headers_install INSTALL_HDR_PATH=myinstall

everything will be neatly under myinstall directory :-)

now make the ramdisk by
mkinitramfs -o initrd.img-3.1.6 -r (myinstall) -v 3.1.6

on the remote machine,
copy myinstall/lib into /lib and fix the build and source symbolic links to actual source code directory. if there is no source directory, then only copy the headers. into /lib/modules/<version>/build/include...

/lib/modules/<version>/kernel contains all the .ko files
/lib/modules/<version>/build and source points to the headers, or you can keep the actual source files here... all it cares is the include directory inside build :-)

copy myinstall/config, map and vmlinuz into /boot and configure grub.

that's how we transfer a kernel from remote machine to target machine. do not forget to copy the .config file from target to remote before building kernel on remote.

Saturday, October 15, 2011

Breakpoints in modules

I am working in modframe

Inside Host, connect gdb via pts to VM. 

Inside VM,
put the module in /root/Desktop/modexperiments/mf
make the module with all debugging info
    add this line in Makefile... EXTRA_CFLAGS += -ggdb3
modframe.ko will be created

insert the module. then it will have a /sys/modules/modframe/sections/.text entry.
track that 0xf8031000
or try this
grep function_name /proc/kallsyms ... track that address

Inside Host,

copy mf directory into /root/Desktop/modexperiments/ ... so that the files are there.

Now we will add breakpoints. 

Inside VM,

echo g > /proc/sysrq-trigger
This will hand transfer to gdb in host

Inside Host,
fire up gdb in host,
  # add-symbol-file modframe.ko 0x########
               -s .data 0x########
               -s .bss   0x########
you can view listing, or put a break point b *0xf8031000

Inside VM,
or remove the modules... that will hit the breakpoint :)
Other interesting utilities
objdump is another utility (use -h flag)

 $ nm modframe.ko -- view symbols 
 $ objdump -t modframe.ko            (all sections)
 $ objdump -t -j data modframe.ko    (data section)
 $ objdump -t -j bss modframe.ko     (BSS section)  

Commands Saturday Oct 15 2011

viewing information
info program, info sttck, info registers, info break

setting a breakpoint
break <function name>
break <line number>

clearing breakpoint
clear <function_name>
delete <breakpoint number>

viewing paramters
print <name>

Friday, October 14, 2011

Compile Kernel in a Remote Machine

compile remote kernel

Tuesday, October 4, 2011

preparing kvm ubuntu

install ubuntu mini in kvm VM.

then install ssh, gcc, vim, libncurses5-dev

then build and install the kernel

Sunday, October 2, 2011

links link links

Saturday, October 1, 2011

loading kernel in gdb

compile kernel with everything about tracing and kernel hacking (DYNAMIC, FTRACE, OPTIMIZE)

then vmlinux file is copied from remote to host

now start gdb/ddd
    > file vmlinux
    > target remote /dev/pts/X

that's it

echo g > /proc/sysrq-trigger
enable/disable sysrq
echo 0 > /proc/sys/kernel/sysrq
echo 1 > /proc/sys/kernel/sysrq 

Finding a symbol
grep alloc_pages /proc/kallsyms -- more symbols because of the loadable modules
or grep alloc_pages /boot/ -- only built-in symbols

kgdb ref: