• Post Reply Bookmark Topic Watch Topic
  • New Topic

Linux Kernel Compilation  RSS feed

 
Rojer Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a Intel RedHat Linux 7.2 computer.
I am new to kernel programming.
I want to compile Linux kernel sourcecode.
How can i do this without screwing up my computer.
Can i copy all the source (i see the it in /usr/src/linux) to some dir like /trial/linux_src/
and then attempt to compile it. Will this have any unwanted affect on my system.
It is absolutely important that nothing wrong happens to my system. I cannot afford to crash it.
Thanks
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12156
256
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Welcome to JavaRanch
Could you please change your displayed name to match the JavaRanch naming conventions. You can change it here.
You can copy <code>/usr/src/linux</code> to another directory if you really want to, however it should not be necessary. The <code>/usr/src/linux</code> directory structure will suit your requirements. What you do in that directory will not affect your running system.
Your running system uses a kernel from the <code>/boot</code> directory. You will probably find it named something like <code>/boot/vmlinuz.<version></code>. Your running system also uses modules which are loaded into the kernel when required. These are in the <code>/lib/modules/<version></code> directory.
If you compile a new kernel in the /usr/src/linux directory, the kernel will be stored in the <code>/usr/src/linux/arch/i386/boot</code> directory until you decide to move it.
You can have more than one bootable kernel in your <code>/boot</code> directory, as long as they have different names.
By default RedHat ensures that the kernel you compile will have a different internal name than the supplied kernel, so that any modules you compile for your kernel will not conflict with the supplied modules.
Regards, Andrew
[ June 21, 2003: Message edited by: Andrew Monkhouse ]
 
Tim Holloway
Saloon Keeper
Posts: 18793
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Recompiling your kernel won't affect things unless you give the new kernel the same name as the old one. Even then, it's not fatal, since if you're maintaining the master kernel via RPMS, you can boot from the CD, chroot to the directory whos name you'll see on recovery boot (it's something like /mnt/sysxxxxx) and then RPM refresh the kernel and boot packages. It's easier than it sound as long as you know what files you need to work with.
But let's hope you don't need to do that. Like Andre said, you can keep multiple kernels and place them in menus in /etc/lilo.conf or /etc/grub.conf, depending on which boot system you prefer.
Here's my checklist:
1. "cd" to the Linux source directory for the version of Linux you want to create.
2. make mrproper
3. make xconfig -- OR make menuconfig if not running X (there are several other configs as well, but these two are the most user-friendly)
4. Set the kernel options as desired. When first starting, it's better not to turn off things that may cause the new kernel not to boot. But be sure that any special hardware or networking features you need are turned on! Save the config you've just made (it's stored as a hidden file ).
5. Edit the main makefile and set EXTRAVERSION to some identifier. "TEST" is a good one for start. Or "Mykernel" or whatever.
6. make dep
7. make clean
8. make bzImage (builds the kernel)
9. make modules
10. make modules-install
11. make install
12. If you're using LILO, edit /etc/lilo.conf to add your new kernel to the list of bootable kernels.
13. If you're using LILO, run /sbin/lilo to cause the new kernel to become bootable. Even if you already had the new kernel's name in lilo.conf and skipped step 12!
14. /sbin/shutdown -r now
When the system reboots, you should see your new kernel in the boot menu. Go for it! Good luck!
--
Some additional notes. When you make mrproper, it zaps the hidden file named ".config" where all your hard-won config options were stored. So save a copy before doing a make mrproper! Normally once you have the basic kernel and are just tweaking, you'd start at step 3.
FYI, there are some stock configs in the configs subdirectory when using RedHat-supplied source. Also a copy of the actual config file used to build the distribution kernel is stored in /boot, so if you ever wanted to repeat what Red Hat did at the "factory", you could just copy that file into the source/.config file and start at step 5. To tweak their kernel, do as above, but run step 4 to do the tweaking, of course.
 
Rojer Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ! That was useful !
Whats the best place to start learning about linux source code itself....etc.. especially considering i am relatively new to C programming too...
My objectives are :
Learn C, Linux OS
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am taking a "Linux Systems Programming" class this summer and we are writing various programs using system calls... we do not have an official book, but i have been using "Linux Programming" from WROX. i have a very old version and it is great. they have a 2nd edition now that is about twice as big.
Beginning Linux Programming, 2nd Edition
 
Tim Holloway
Saloon Keeper
Posts: 18793
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rojer Smith:

Whats the best place to start learning about linux source code itself.

Read it! You'll be following the same path I did back way long ago. Although I was reading the source code for the PR1ME computer OS and it was in FORTRAN.
There's some good online documentation of what the Linux kernel is doing and how it does it out on the 'Net.
I recommend asking yourself a question about the kernel such as "How does task dispatching work" or "What actually happen when you open a disk file?". Then dig into the kernel source and follow it along. (hint: grep -i --recursive is your friend!).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!