GNU/Linux, and all other operating systems, are based around a kernel which controls hardware access and maximizes CPU and RAM efficiency by controlling when and how much programs get to use. The difference between Linux and most other operating systems (closed source ones at least BSD and other open source OS’s you can do this with) is that you can compile the kernel to meet your needs.Step 1. Basics of the kernel.
I will most likely never have to use an old serial modem or something, so i would not
compile in the drivers for it. Also, Linux supports modules, which
are drivers that don’t load until you tell them to. Modules can be
useful for things that you don’t use much, like I don’t use ReiserFS
personally but if my friend who does needs me to retrieve data from a
hard drive, I don’t want to have to recompile my kernel to help,
instead i just type modprobe reiserfs . Compiling a kernel in
Linux is fairly easy, if you know basically what you are doing, that
is what this article hopes to explain.
If
you have a working system and just want a kernel to improve
performance, get you up to date, or for bragging rights, go down to
Step 3
If
you f00barred your system and need to install a new kernel from a
live cd, keep on reading.
Step 2. Chrooting from
Knoppix
Okay,
this step is very easy it involves opening a konsole and typing as
root
mount /dev/
mount /dev/
chroot /mnt/linux
Well,
that basically concludes that step. Basically you just mount all
your required linux partitions. (Yes you have to know what those are,
if you feel like you are going to b0rk your install soon and still
have normal access to the computer just print out your /etc/fstab)
Then, you simply chroot into it.
Step 3. Configuring and
Compiling the Kernel
Configuring
the kernel is the hardest part of this. Before going into this know
your hardware. That said download the sources for the latest kernel
version from www.kernel.org or
if you are using Gentoo (if you are you should have read the manual
but anyway…) emerge the version of kernel sources you want (such as
gentoo-dev-sources gentoo-gaming-sources or whatever). Once they are
downloaded decompress and untar them to /usr/source and then create a
linux symlink.
tar -xvjf
cd /usr/src
rm linux
ln -s
cd linux
Now
you are in your kernel source directory, and now its time for the
magic to happen type
make menuconfig
This
will launch a rather nice interface for configuring the kernel. I
will tell you what every system *needs* to function. First
off you are going to want to go under file systems and select all the
ones you use and under psuedo-filesystems select all of them (NOTE:
DO NOT set any of the ones that you use constantly to modules, this
will make it so that the computer cannot boot). Now go into
processor type and features and select the applicable options. Now
its time to explore the device drivers, these are rather important,
go crazy here, make sure you include support for your network cards,
block devices, sound cards, whatever. Now for the most part it
should be done, look through the other categories though to make sure
everything is happy. Once you are satisfied with your config, save
and exit. Now it is time to actually compile the beast, depending on
your system this could take a while, call the pizza guy if you must.
Type
make && make
modules_install
Now
wait for it. While you are waiting lets go over the next step,
actually installing the kernel. What you have to do is copy the
bzImage into your /boot directory, but you do not have to call it
bzImage, you can call it Bob or John or Alice or whatever, I usually
just call it gentoo. Okay, the code to install is
cp
arch/i386/boot/bzImage /boot/
cp System.map
/boot/System.map
cp .config
/boot/.config
Once
that is done, all you have left to do is edit /etc/lilo.conf (or
grub.conf but i don’t know much about grub, there is some good
information online about it) For LILO simply update lilo.conf (Mine
looks like this because I do some fancy things with it)
boot=/dev/sda #
Install LILO in the MBR
prompt # Give the
user the chance to select another section
timeout=500 # Wait 5
(five) seconds before booting the
default=gentoo # When
the timeout has passed, boot the “gentoo” section
install=/boot/boot-bmp.b
# means you will use grafical version
bitmap=/boot/handy_128.bmp
# background path
bmp-colors=38,68,53,112,38,25
# text color
bmp-table=114p,347p,2,7
# label position on the screen p=pixel
bmp-timer=470p,336p,25,0,11
# timer position on the screen p=pixel
#This is where you
put
kernel information for linux
image=/boot/gentoo
#image name (what you named the bzImage)
label=gentoo # Name
we give to this section
read-only # Start
with a read-only root. Do not alter!
root=/dev/sda7 #
Location of the root filesystem
# The next two lines
are only if you dualboot with a Windows system.
# In this case,
Windows is hosted on /dev/hda6.
other=/dev/sda1
label=windows
Once that is edited to include the latest information. Simply run as
root
lilo
then everything should be happy if you did everything right. Now boot
into your normal system and see if it works, if it kernel panics try
again. This takes a bit of practice but once you understand it, it
becomes easy.
About the Author
I am SchleyFox and I use Gentoo GNU/Linux. I go to www.usalug.org to get
linux help and so should you.
If you would like to see your thoughts or experiences with technology published, please consider writing an article for OSNews.
quote: The difference between Linux and most other operating systems (closed source ones at least BSD and other open source OS’s you can do this with) is that you can compile the kernel to meet your needs.
I mean of all the operating systems in the world aren’t most (as defined in >50%) opensource? maybe the closed source dominate the percentage of users but surely not the percentage on variations of operating systems.
Actually the difference between windows (and a few other closed source OS) and most operating systems is that you can’t compile the kernel to meet your needs.
from most windows users point of view there is one operating system: windows
from most linux users point of view there are two operating systems: windows and linux (oh yes and some left over garbage not worth mentioning)
A poem:
Tunnel vision, tunnel vision I thought I got rid of it
When I started using linux and dropped that windows sh!t
Only to find out, I was a little wrong
Now I’m using linux, my tunnel’s twice as long
All jokingly and in good fun , but like all jokes, it’s a little true.
and I guess AIX, Solaris, HP-UX, etc, are garbage left over?
Basically good advice, but a couple of comments:
Maybe i’m just being a stupid n00b, but why does step 2 contain 2 almost identical mount commands?
Also, before cping the kernel to /boot, you should be sure and mount your /boot partition (assuming it’s on a seperate partition). The most frequent screw up i make installing new kernels is forgetting to do that before cping the kernel to /boot.
If you like to compile kernels, it’s also a good idea to always have at least one known good kernel in /boot and grub/lilo. If your new kernel won’t boot, it’s a lot easier to fix it by booting the good one than messing with a live cd.
A nice HOWTO, but I quess there are already many documents on the internet about how to install a new kernel.
However, I like the idea of using a boot-CD in case your current kernel is no longer working. But if you got your distro on cd-rom, you can just copy the default kernel back?
Anyway, one should not need to boot from CD. After compiling a new kernel, just don;t delete the old one and make sure you can still boot using the old kernel.
for example , but also opensource like *BSD and a lot of others
An intro such as in this article is a bit like this intro on sports:
The difference between basketball and and most other ballsports (rugby-like ones at least baseball and other hitting sports have them) is that a basketball is completely round.
I guess as usual it depends on your point of view, and what part of the world is in it…
I miss GRUB. Not everybode uses LILO as it’s not as good as GRUB.
I love that poem! Did you write that?
Did the author finish the article? What is all this about?
mount /dev/ -rw /mnt/linux
mount /dev/ -rw /mnt/linux/
chroot /mnt/linux
I can’t see that being any use, instead try something like this:
mount /dev/hda3 /mnt/linux
chroot /mnt/linux /bin/bash
(replace hda3 with the partition that is your root filesystem. – You may need to mount other filesystems depending upon how you have configured your partitions
Not knowing Knoppix, I’m assuming that /mnt/linux already exists. If not create a directory somewhere on the ramdisk, and mount your root filesystem their instead.
Might I suggest that anyone who actually needs to know how to do this, ignores this document and instead downloads a Gentoo LiveCD and follows their *excellent* documentation instead.
Sorry Eugenia, but if I’m perfectly honest, I think this article falls well below the usual OSNews standard.
And the next step is wrong
tar -xvjf .bz2 -C /usr/src
cd /usr/src
rm linux
ln -s linux
cd linux
How about this instead
cd /usr/src
tar -xjf linux-2.6.5.tar.bz2
rm linux
ln -s linux-2.6.5 linux
cd linux
Replace linux-2.6.5 with the version of the kernel you are using.
if boot=/dev/hda, and I have Windows on /dev/hda and Linux on /dev/sda, how will LILO know that /boot/bzImage is actually on /dev/sda?
Anyone?
Before running make menuconfig, might I also suggest copying the old .config into the new /usr/src/linux directory (e.g. cp /usr/src/linux-2.6.5/.config /usr/src/linux) and running
make oldconfig
Your kernel will be configured the same as your old one, but you will be asked which of the new features you want. 9 times out of 10, you can then skip make menuconfig
yes I wrote the poem as a quick joke
glad you enjoyed it
The difference between Linux and most other operating systems (closed source ones at least BSD and other open source OS’s you can do this with) is that you can compile the kernel to meet your needs.
Please use a comma or two.
“f boot=/dev/hda, and I have Windows on /dev/hda and Linux on /dev/sda, how will LILO know that /boot/bzImage is actually on /dev/sda? ”
I have never found a way to do it with lilo, and it was my primary reason to go to grub. Never wanted to come back. There may be a way to do it with lilo, though.
I looked that source of the web page and found the reason there are multiple comments about this incomplete article. It appears that the author doesn’t understand the concept of using brackets directly (which browsers interpret as HTML tags) vs. using the lt and gt representations. For example, it SHOULD read:
mount /dev/<your /partition name here> -rw /mnt/linux
The author just made a serious HTML no-no … it certainly would help this article to correct this.
I’ve been compiling my own kernel for a while, I still have questions.
What is System V IPC? The help for it says it’s considered a “good thing”, but what is it really? And is it really needed?
What is BSD Process Accounting? Why would I need it? Again the help suggests that you use it, but why? I’ve compiled my kernel with and without it and I don’t see how it changes the system one iota.
What is Auditing Support? The help information is too generic. I compile my kernel without it because having it in the kernel doesn’t seem to matter.
What is the HPET timer? The help file says it’s a new internal timer and that without the option, the kernel will use a “legacy” timer. The word legacy really jumps out at me, so I include it. But again – without it in the kernel, I see no difference in performance or my ability to boot, run programs, or whatever.
Preemption sounds like a good thing in theory. But I don’t see how it helps. I include it … but when playing with my system without preemption, I haven’t seen a difference.
I have other questions … but those are the main ones.
Ah the joys of a well thought out distribution method (well mostly). DragonFly (like a few Linux distributions and the odd FreeBSD derivitive) is distributed as Live CD images which contain the complete base system, with a full set of manual pages. In the not too distant future they will likely also come with a port of the excelent FreeBSD Handbook, and probably some implementation of X.
It’s my opinion that all OSes should be distributed like this, at least as a default as it gives you a complete set of useful tools to not only test and install the OS, but to undo whatever calamity has struck whatever machine you happen to be working on.
For a correct kernel rebuilding procedure search google. If you can’t find anything go to:
http://www.digitalhermit.com/linux/Kernel-Build-HOWTO.html
The safest way to make sure you don’t “f00barred your system”
(who writes this crap anyway!?) ALWAYS leave and do not OVERWRITE your default kernel (and relevant lilo entries).
make mrproper (first time, and then only to reset values)
make menuconfig (or xconfig)
make dep
make clean
make bzImage
make modules
make modules_install
make install
lilo <- don’t forget it
“make install” moves all the newly created files to the correct places, and also updates lilo with a new entry to reflect the newly created kernel. If you use grub I think you have to add the entry manually.
Adding -jx (where x>3) flag to “make” greatly improves compilation times on HT and/or SMP systems. On my 2×3.4 Xeon (oc), 2G, I don’t have enough time to boil an egg durring the entire compilation process.
For a correct kernel rebuilding procedure search google.
make mrproper (first time, and then only to reset values)
make menuconfig (or xconfig)
make dep
make clean
make bzImage
make modules
make modules_install
make install
lilo <- don’t forget it
Yuck! That’s a lot of steps! It’s SO much simpler in FreeBSD/DragonFly*.
make buildkernel
make installkernel
Sheesh. Linux users and the things they put up with!
* Yes, I’m aware that in DF you now pretty much need to do a make buildworld before doing the make buildkernel, unless you do a ‘make nativekernel.’ The price of progress i guess.
“make && make modules_install”
I make sure my boot partition is mounted, then run:
make
make modules_install
make install
With 2.6 kernels, make install places everything needed into /boot. There is no need to edit grub.conf, since the vmlinuz symlink is automatically updated with “make install.”
With 2.6 kernels, make install places everything needed into /boot.
I should start doing that. I still do it manually so there is a stock kernel, old kernel, and new kernel to choose from (or fall back on).
As far as chrooting, why not append “linux root=/dev/hda1” on boot to save a step or two. (Assuming hda1 is the root.)
Google can point you to answers to your questions. In general, if you enable some feature that isn’t used by any program that you run, then you won’t notice any change.
When Unix was first developed, AT&T was forbidden by an antitrust agreement from extending its telephone monopoly into the computer business. Telephone money could not be used to fund non-telephone businesses. By making Unix available for others to use under reasonable terms, it avoided the monopoly control issues. The University of California at Berkeley quickly extended Unix in many ways, adding networking and other features, including sockets as an IPC mechanism.
The breakup of AT&T into the Baby Bells freed the remaining AT&T core to go into the computer business. Rather than using the BSD extensions to early Unix, AT&T reinvented the wheel, and did it differently. This AT&T commercial Unix branch eventually became System V.
For every feature that wasn’t in the research editions of Unix, there is usually a BSD way to do it and a SysV way to do it. SysV uses semaphores, message queues, and shared memory to do IPC, where BSD uses sockets. Scientific and engineering users had jumped on BSD early, so many programs were written to use BSD features. AT&T was more successful pushing System V to business users, who came to Unix later.
Sun switched from a BSD base to a System V base, but included a BSD compatibility layer, since all of their customers were running software written for BSD. Most BSD implementations added System V compatibility, as well. Linux is largely POSIX, which tends to follow BSD, but offers SysV as an option.
You need SysV IPC if you run a program that needs it. Complaints about shared memory are a common symptom. Including it makes the kernel larger, which is not a problem for most users. It is a problem for embedded systems, which is why SysV IPC is an option.
Including it makes the kernel larger, which is not a problem for most users.
Call me a neat freak or … minimalist I guess. I just like to cut out absolutely everything I can that’s not doing something beneficial for my system. I prefer minimal window managers because they do what I need without that “heavy” feeling to them. And distros like Gentoo that let me tweak to my heart’s content. But some things in the kernel elude me. I don’t want to over minimize because that can kill performance.
I thought Linux was so stable and brilliant that such things never needed to be done…
Hi.
I am not compiling my kernel on regular basis, but as far as I understand Thorvalds letter, you should leave your system-provided kernel at /usr/src/linux and compile your new kernel anywhere else.
This is for system compatibility, the system compiled expects to find header files with a certain version in /usr/src/linux, and if a new version is found instead of the expected the system may be confused, and you may end up with a “f00barred” system.
This with compiling new kernels in /usr/src/linux is an old habit from before the time of 2.4 version of kernels.
The two nearly identical mount commands were supposed to be to mount the / partition and then to mount all other neccesary partitions but it could have been late or it could have been one of those html nonos i did. Frankly it was late and I was typing it up in Openoffice and did not feel like converting it by hand and I also wanted to see whether openoffice could do it. I was getting tired so I just looked over it to make sure it generally looked *ok*, this is also my first article and i thought I understood the guidelines. Honestly the < > things i should have caught (and if i was doing as I normally do and not use a wysiwag of any kind it would not have happened) I am sorry if that inconvenienced you. About grammar, that is not what I am most skilled at. About there being a lot of guides to configuring a kernel, Back about 6 months when I was n00b (i was not on gentoo then) I finally worked up the guts to try and do a kernel compile, I searched all over for good guides, but none of them met my needs. I finally found a guide that met my needs when I had already moved onto gentoo, The Gentoo Handbook (which most people would not think of unless they were trying gentoo).
Thank you for your feedback and advice (although it seems like I am making excuses I will rectify all problems in future articles)
Ben Hughes
Making changes isn’t optimization. Changing compiler flags isn’t optimization. Disabling options isn’t optimization.
Optimization depends on measuring the effects of change. If you don’t measure, then don’t bother. Stay with the defaults.
I’ve compiled the Debian version of the 2.6.8 kernel, with defaults, on an Athlon XP. Here are the uncompressed kernel sizes with and without SysV IPC:
3434900 vmlinux_SysV_IPC
3412106 vmlinux_No_SysV_IPC
Disabling SysV IPC saves 22794 bytes. Actual memory usage when running may be larger, due to allocation of buffers and such. If I cared, I’d reboot and measure it. But I highly doubt that the difference would be significant on a system with 1GiB of RAM.
If I were trying to squeeze a rescue kernel onto a floppy, then it might be worth seeing what I could leave out. For routine use, the standard kernel has already been optimized. You will see better results if you focus on other areas, such as applications or graphic card improvements.
A. the really easy one (pick a prebuilt kernel to install):
apt-cache search kernel-image
(decide which one you want)
apt-get install name_of_desired_kernel
nano /boot/grub/menu.lst (edit list appropriately for new kernel)
B. OK, I know, this is supposed to be about compiling and installing one’s own kernel:
apt-cache search kernel-source
apt-get install kernel-source-2.6.8 (or whatever one you want)
cd /usr/src
tar -xjf kernel-source-2.6.8
cd kernel-source-2.6.8
make menuconfig
make-kpkg kernel_image
(if using modules, make that:
make-kpkg kernel_image modules_image)
cd ..
dpkg -i kernel-image-2.6.8*deb
(or:
dpkg -i kernel-image-2.6.8*deb modules-image-2.6.8*deb)
nano /boot/grub/menu.lst
Basically, with Debian, you need one command to download the source for the new kernel, one command to untar it, one to configure it, and one to install it and the modules, plus some trivial editing of the grub config file. It is really a simple process.
p.s. – the above is off the top of my head, and while I am confident it is generally correct, there may be some typos. I am not at my Debian machine. Of course, the above assumes you have gcc and make-kpkg installed. You also need libncurses5-dev, and maybe some oher things. If you are upgrading from 2.4 to 2.6 there are some significant changes in required packages, in particular a newer modutils is needed or modules won’t load. Also, if you build the same version kernel more than once, make sure you install the one you think you are installing with dpkg. The file globs I used above can lead to unintended results if you aren’t careful. Be careful, read other documentation, and don’t blame me if your system won’t boot the new kernel. However, as long as you keep your old kernel as well as a matching entry in grub, you should be able to keep using your old one.
I have to say that this article is perfect for somewhat infidels such as myself…..i am a new linux user, so common info like this is perfect for me…..thanks schleyfox.
On the trend of suggesting articles, this article written specificaly to show Fedora Core users how to compile a kernel into an RPM package is great.
http://www.fedoraforum.org/forum/article.php?a=4
Congrats to the writer it helped me alot and it is so well written.
KDE
System V IPC … etc
Just go to http://www.google.com Search. You will find it all. I just gave it a try to verify the results.