I want to add these file into my kernel such way that when kernel start this hello.o file execute and run
What you are trying to achieve shouldn't be made through kernel edition. Executing a program at boot time can be handled in much simpler ways, without need for kernel programming experience. You can:
Execute it when your shell starts:
Write /path/to/hello/executable
at the end of /etc/profile
, ~/.profile
or ~/.bashrc
. Those files are sourced every time you start a shell (more specifically, bash). This also means that your executable will run every time you open a terminal.
Use the init.d system: Compile your code and add an init script to the init system. You'll find all the information you may need on this page, or here for Ubuntu specifics.
Here a quick example of an init script for your hello executable:
#!/bin/sh
### BEGIN INIT INFO
# Provides: hello
# Default-Start: 1 2 3 4 5
# Short-Description: Prints Hello World somewhere.
# Description: Some more description...
### END INIT INFO
case "$1" in
start)
/path/to/hello/executable
;;
stop|restart|force-reload)
;;
*)
;;
esac
exit 0
Now you can execute hello using :
service hello start
Assuming that the init script is named hello
, and is executable. To make it run at boot time, use:
update-rc.d hello defaults
The kernel relies more on libraries than executables actually. You may also want to have a look at The Kernel Module Development Guide, which can introduce you to the basics of kernel modules. Again, this is a horrible overkill for what you're trying to do.