Kasım 22, 2008, 01:04:24 ÖÖ *
Merhaba, Ziyaretçi. Lütfen giriş yapın veya üye olun.

Kullanıcı adınızı, parolanızı ve aktif kalma süresini giriniz
 
   Ana Sayfa   Yardım Ara Giriş Yap Kayıt  
Sayfa: [1]
  Yazdır  
Gönderen Konu: Linux Kernel Installation  (Okunma Sayısı 2513 defa)
Fesih
Yönetici
*****
Mesaj Sayısı: 414


Üyelik Bilgileri
« : Haziran 22, 2007, 11:33:11 ÖÖ »

 Linux is many users' introduction to a truly powerful,configurable operating system. In the past, a Unix-like operatingsystem was out of reach for most. If it wasn't the operatingsystem's 4-digit price tag, it was the hardware. Even the nowfree-for-personal-use SCO Unixware requires a system withSCSI drives, and most of us are using IDE to keep costs down. Along withthe power that Linux bringscomes the need to perform a task users have not had to do onsimpler operating systems: configure the kernel to your hardwareand operations.

Previous installation kernels from 1.2.x and before suggestedthat you rebuild; however, with the new 2.0.x kernel, rebuilding has almostbecome a necessity. The kernel that comes with the installation packages fromRed Hat, Caldera, Debianand most others, is a generic, ``almost everything is included''kernel. While rebuilding a kernel may seem like a daunting taskand living with the installed kernel may not be too bad, rebuilding is agood introduction to your system.


Why Roll Your Own?

The standard installation kernels are an attempt to makeas many systems aspossible usable for the task of installing a workable Linux system. Assuch,the kernel is bloated and has a lot of unnecessary code in it forthe average machine. It also does not have some code a lot of userswant.

Then, of course, there's always the need to upgradethe kernel because you've bought new hardware, etc. Upgrading withina series is usually very straightforward. When it comes toupgrading, say from 1.2.something to 2.0.something, now the task isbeyond the scope of this article and requires some savvy.Better to get a new distribution CD and start fresh--this is also truefor upgrading to the experimental 2.1.x kernels.


Kernel Version Numbering

All Linux kernel versionnumbers contain three numbers separated by periods (dots). Thefirst number is the kernel version. We are now on the third kernel version,2. Some of you may be running a version 1 kernel, and I am aware ofat least one running version 0 kernel.

The second numberis the kernel major number. Major numbers which are even numbers(0 is considered an even number) are said to be stable. That is, thesekernels should not have any crippling bugs, as they have been fairlyheavily tested.While some contain small bugs, they can usually be upgraded forhardware compatibility or to armor the kernel against systemcrackers. For example, kernel2.0.30, shunned by some in favor of 2.0.29 because of reported bugs,contains several patches including one to protect against SYN denialof service attacks.The kernels with odd major numbers are developmental kernels. Thesehave not been tested and often as not will break any software packagesyou may be running. Occasionally, one works well enough that it willbe adopted by users needingthe latest and greatest support before the next stable release.This is theexception rather than the rule, and it requires substantial changesto a system.

The last number is the minor number and isincreased by one for each release. If you see kernel version 2.0.8,you know it's a kernel 2.0, stable kernel, and it is the ninth release(we begin counting with 0).


Assumptions

I hate tomake any assumptions; they always seem to come back to bite me. So Ineed to mention a few things so that we're working off the same sheet ofmusic. In order to compile a kernel, you'll need a few things. First,I'll assume you've installed a distribution with a 2.0.x kernel,all the basepackages and perhaps a few more. You'll also need to have installedgcc version2.7 and all the supporting gcc libraries. You'll also need thelibc-dev library and the binutils and bin86 packages (normallyinstalled as part of a standard distribution install). If you downloadthe source or copy it from a CD, you'll also need the tar and gunzippackages. Also, you'll need lots of disk real estate.Plan on 7MB to download, another 20MB to unpack this monster and a few moreto compile it.

Needless to say, many of the things we will discussrequire you to be logged in as root. If you've downloaded the kernelas a non-privileged user and you have write permission to the /usr/srcsubdirectory, you can still do much of this task without becoming root.For the newcomers to Linux, I highly recommend you do as muchas possible as a non-privileged user and become root (type:su - face) only for those jobs that require it.One day, you'll be glad you acquired this habit. Remember, there aretwo kinds of systems administrators, those who have totally wrecked a runningsetup inadvertently while logged in as root, and those who will.


Obtaining/Upgrading the Source

Kernel sources forLinux are available from a large number of ftp sites andon almost every Linux distribution CD-ROM. For starters, you cango to ftp.funet.fi,the primary site for the Linux kernel. This site has alist of mirror sites from which you can download the kernel. Choosingthe site nearest you helps decrease overall Internet traffic.

Once you've obtained the source, put it in the /usr/src directory.Create a subdirectory to hold the source files once they are unpacked usingtar. I recommend naming the directoriessomething like linux-2.0.30 or kernel-2.0.30, substituting yourversion numbers. Create a link to this subdirectory called linux using thefollowing command:

ln -sf linux-2.0.30 linux
I included the -f in thelink command because if you already have a kernel source in /usr/src,it will contain this link too, and we want to forceit to look in our subdirectory.(On some versions of ln (notably version 3.13), the force option(-f)does not work. You'll have to first remove the link then establishit again. This works correctly by version 3.16.)The only time you may have a problem is if linux is asubdirectory name, not a link. If you have this problem, you'llhave to rename the subdirectory before continuing:

mv linux linux-2.0.8
Now issue the command:

tar xzvf linux-kernel-source.tar.gz
I have a habit of always including w (wait forconfirmation) in the tar option string, then whenI see that the .tar.gz or .tgz file is going to unpack into itsown subdirectory, I ctrl-C out and reissuethe command without the w.This way I can prevent corrupted archives from unpacking into the currentdirectory.

Once you have the kernel unpacked, if you have anypatches you wish to apply, now is a good time. Let's say you don'twish to run kernel 2.0.30, but you do want the tcp-syn-cookies. Copythe patch (called tcp-syn-cookies-patch-1) into the /usr/srcdirectory and issue the command:

patch < tcp-syn-cookies-patch-1
This commandapplies the patch to the kernel. Look for files withan .rej extension in in the /usr/src directory.These files didn't patch properly. They may be unimportant, butperuse them anyway. If you installed a Red Hat system with some but not all ofthe kernel source (SPARC, PowerPC, etc.), you'll see some of these files.As long as they're not for your architecture, you're okay.

Preparation

As a final note, before we change (cd) into thekernel source directory and start building ournew kernel, let's check some links that are needed. In your/usr/includedirectory, make sure you have the following soft links:

asm - /usr/src/linux/include/asm
linux - /usr/src/linux/include/linux
scsi - /usr/src/linux/include/scsi
Now, you see another reason tostandardize the location of the kernel. If you don't put the latestkernel you wish to install in /usr/src/linux(via a link), the above links will not reach their intended target(dangling links), and the kernel may fail to compile.

How to proceed

Once everything else is set up, change directories into /usr/src/linux.Although you may want to stop off and peruse some of the documentation in theDocumentation directory, particularly if you have any special hardwareneeds. Also, several of the CD-ROM drivers need to be built withcustomized settings. While they usually work as is, these driversmay give warning messages when loaded. If this doesn't botheryou and they work as they should, don't worry. Otherwise, read theappropriate .txt, .h (header) files and .c (c code) files. Forthe most part, I have found them to be well commented and easy toconfigure. Ifyou don't feel brave, you don't have to do it. Just remember youcan always restore the original file by unpacking the gzipped tar file (orreinstalling the .rpm files) again.


Beginning to Compile

The first command I recommend you issue is:

make mrproper
While this commandis not necessary when the kernel source is in pristine condition,it is a good habit to cultivate. This command ensures that old object files arenot littering the source tree and are not used or in the way.

Configuring the Kernel

Now, you're ready to configurethe kernel. Before starting, you'll need to understand a littleabout modules. Think of a module as something you can plug into thekernel for a special purpose. If you have a small network at homeand sometimes want to use it (but not always), maybe you'll want tocompileyour Ethernet card as a module. To use the module, the machine mustbe running and have access to the /lib/modulesThis means that the drive (IDE, SCSI, etc., but could be anethernet card in the case of nfs), the file system (normally ext2 but could benfs) and the kernel type (hopefully elf) must be compiled in and cannot bemodules. Modules aren't available until the kernel is loaded, the drive (ornetwork) accessed, and the file system mounted.These files must be compiled into the kernel orit will not be able to mount the root partition. If you're mountingthe root partition over the network, you'll need the network filesystem module, and your Ethernet card compiled.

Why usemodules? Modules make the kernel smaller. This reduces theamount of protected space never given up by the kernel. Modules load andunload and that memory can be reallocated. If you use a module morethan about90% of the time the machine is up, compile it. Using a module inthis case can be wasteful of memory, because while the module takes up thesame amount of memory as if it were compiled, the kernel needsa little more code to havea hook for the module. Remember, the kernel runs in protectedspace,but the modules don't. That said, I don't often follow my ownadvice. Icompile in: ext2, IDE and elf support only. While I use an Ethernetcard almost allthe time, I compile everything else as modules: a.out, java, floppy,iso9660, msdos, minix, vfat, smb, nfs, smc-ultra (Ethernet card),serial, printer, sound, ppp, etc.Many of these only run for a few minutes at a time here and there.

The next step is to configure thekernel. Here we have three choices--while all do the same thing,I recommend using one of the graphical methods. The old way was tosimply type: make config. This begins a long series ofquestions. However, if you make a mistake, your only option is to pressctrl-C and begin again. You also can't goback in the sequence, and some questionsdepend on previous answers. If for some reason you absolutelycan't use either of the graphical methods, be my guest.

I recommend using either make menuconfig ormake xconfig. In order to use menuconfig,you must have installed the ncurses-dev and thetk4-dev libraries. If you didn't install them and you don't want touse the nextmethod, I highly recommend that you install them now. You can alwaysuninstall them later.

To run make xconfig, you must install and configure X.Since X is such a memory hog, I install, configure andstartx only for this portion of the process, going back to a consolewhile the kernel compiles so it can have all the memory it needs. Thexconfig menu is, in my opinion, the best and easiest way toconfigure the kernel. Under menuconfig, if you disable an option, anysubordinate options are not shown. Under xconfig, if you disable anoption, subordinate options still show, they are just greyed out. Ilike this because I can see what's been added since the last kernel.I may want to enable an option to get one of the new sub-options in orderto to experiment with it.

I'm going to take somespace here to describe the sections in the kernel configuration and tellyou some of the things I've discovered--mostly the hard way.

The first section is the code-maturity-level option. The onlyquestion is whether you want to use developmental drivers and code. Youmay not have a choice if you have some bleeding edge hardware. Ifyou choose ``no'', the experimental code is greyed out or notshown. If you use this kernel for commercial production purposes,you'll probably want to choose ``no''.

The second section concernsmodules. If you want modules, choose ``yes'' for questions 1and 3. If you want to use proprietary modules that come with certaindistributions, such as Caldera's OpenLinux for their Netware support, alsoanswer ``yes'' to the second question since you won't be able to recompilethe module.

The third section is general setup. Do compile thekernel as ELF and compile support for ELF binaries. Not compilingthe proper support is a definite ``gotcha''.You'll get more efficient code compiling the kernel for the machine'sspecific architecture (Pentium or 486), but a 386 kernel will run in any 32-bitIntel compatible clone; a Pentium kernel won't.An emergency boot disk for a large number of computers (as well asdistribution install disks) is best compiled as a 386. However, a 386 willnot run a kernel compiled for a Pentium.

Next comes blockdevices--nothing special here. If your root device is on an IDE drive,just make sure you compile it.

Then comes networking. Forcomputers not connected to a network, you won't need much here unlessyou plan to use one computer to dial-out while others connect throughit. In this case, you'll need to read up on such things as masquerading andfollow the suggested guidelines.

SCSI support is next, thoughwhy it doesn't directly follow block devices I don't know. If yourrootpartition is on a SCSI device, don't choose modules for SCSI support.

SCSI low-level drivers follow general SCSI support. Again,modules only for devices that don't contain the root partition.

The next section takes us back to networking again. Expectto do a lot of looking for your particular card here as well as someother support such as ppp, slip, etc. If you use nfs tomount your root device, compile in Ethernet support.

Forthose lucky enough to be needing ISDN support, the ISDN subsection willneed to be completed.

Older CD-ROMs may require support from the nextsection. If you're using a SCSI or IDE CD-ROM, you can skipthis one.

Next comes file systems. Again, compilewhat you need, in most cases ext2 and use modules for the rest.

Character devices are chosen next. Non-serial mice, likethe PS/2 mouse are supported. Look on the bottom of your mouse. Manytwo-button mice are PS/2 type,even though they look and connect like serial mice. You'll almostcertainly want serial support (generic) as a minimum. Generic printer supportis alsolisted here.

The penultimate section is often the most troubling:sound. Choose carefully from the list and read the available help.Make sure you've chosen the correct I/O base and IRQsfor your card. The MPU I/O base for a SoundBlaster card is listed as0. This is normally 330 and your sound module will complainif this value is incorrect. Don't worry. One of the nice things aboutmodules is you can recompile and reinstall the modules as long as thekernel was compiled with the hook. (Aren't modules great?).

The final section contains one question that should probably beanswered as ``no, kernel hacking''.

Save your configuration and exit.

I have, on several occasions,had trouble editing the numbers in menuconfigor xconfig to values I knew were correct. For whatever reason, Icouldn't change thenumber or config wouldn't accept the number, telling me itwas invalid. For example, changing the SoundBlaster IRQ from theconfig default of 7 to 5, and the MPU base I/O from 0 to 300. Ifyou experience this problem, but everything else went well, don'tdespair. The file you just wrote when you did a ``Save'' and``Exit'' is aneditable text file. You may use your text editor of choice: Emacs, vi,CrispLite, joe, etc. Your configuration file is in the /usr/src/linuxdirectory andis called .config. Theleading dot causes the file to be hidden during a normal directory listing(ls), but itshows up when the -a option is specified.Just edit the numbers in this file thatyou had trouble with in the configuration process. Next, typemake depto propagate your configurations from the .config file tothe proper subdirectoriesand to complete the setup. Finally, type make cleanto prepare for the final kernel build.


Building the Kernel

We're now ready to beginbuilding the kernel. There are several options for accomplishing this task:

  •    make zImage: makes the basic,compressed kernel and leaves it in the /usr/src/linux/arch/i386/bootdirectory as zImage.  
  •    make zlilo: Copiesthe zImage to the root directory (unless you edited the top-levelMakefile) and runs LILO. If you choose to use this option,you'll have to ensure that /etc/lilo.conf is preconfigured.  
  •    make zdisk: Writes zImage to afloppy disk in /dev/fd0(the first floppy drive--the a: drive in DOS). You'll need the diskin the drive beforeyou start. You can accomplish the same thing by runningmake zImage and copying theimage to a floppy diskcp /usr/src/linux/arch/i386/boot/zImage /dev/fd0Note that you'll need to use a high-densitydisk. The low density 720k disks will reportedly not boot the kernel.  
  •    make boot: Works justthe same as the zImage option.  
  •    make bzImage: Used for big kernelsand operates the same as zImage. You will know if you need thisoption, because make will fail with a message thatthe image is too big.  
  •    make bzdisk: Used for big kernelsand operates the same as zdisk. You will know if you need thisoption, because make will fail with a message thatthe image is too big.
Other make options are available,but are specialized, and are not covered here. Also, if you needspecialized support, such as for a RAM disk or SMP,read the appropriate documentation and edit the Makefile in/usr/src/linux (also called the top-level Makefile) accordingly.Since all the options I discussed above are basically the sameas the zImage option, the rest of this article deals withmake zImage--it isthe easiest way to build the kernel.

For those of you who wish to speed up the process and won't be doingother things (such as configuring other applications), I suggest youlook at the man pagefor make and try out the -j option (perhaps with a limit like 5) and also the -l option.

If you chose modules during the configuration process,you'll want to issue the commands:

make modules
make modules_install
to put the modulesin their default location of  /lib/modules/2.0.x/,x being the kernel minor number. If you already have thissubdirectory and it has subdirectories such asblock, net, scsi, cdrom, etc., you may want to remove2.0.x and everything below it unless you have some proprietary modulesinstalled, in which case don't remove it. When the modulesare installed, the subdirectories are created andpopulated.

You could just as easily have combined the last threecommands:

make zImage; make modules; make modules_install
then returned after all the disk churningfinished. The ; (semicolon) character separates sequential commands on one line andperforms each command in order so that you don't have to wait around justto issue the next command.

Once your kernel is built and yourmodules installed, we have a few more items to take care of. First, copyyour kernel to the root (or /boot/ or /etc/, if you wish):

cp /usr/src/linux/arch/i386/boot/zImage /zImage
You should also copy the /usr/src/linux/System.mapfile to the same directory as the kernel image. Thenchange (cd) to the /etc directoryto configure LILO. This is a very important step. If we don't installa pointerto the new kernel, it won't boot. Normally, an install kernelis called vmlinuz. Old-time Unix users willrecognize the construction of this name. The trailing ``z'' means theimage is compressed. The ``v'' and ``m'' also have significance andmean ``virtual'' and ``sticky'' respectively andpertain to memory and disk management. I suggest you leave thevmlinuz kernel in place, since you know it works.

Edit the /etc/lilo.conf fileto add your new kernel. Use the lines from theimage=/vmlinuz line to the nextimage= line or the end. Duplicate what you see, thenchange the first line to image=/zImage(assuming your kernel is in the root directory) and choose adifferent name for the label=.The first image in the file is the default, others will have to bespecified on the command line in order to boot them. Save the file andtype:

lilo
You will now see the kernel labels, and the firstone will have an asterisk.If you don't see the label that you gave your new kernel or LILOterminates withan error, you'll need to redo your work in /etc/lilo.conf(see LILO man pages).

We're almost ready to reboot. At this point, if you know yoursystem will only require one reboot to run properly, you might wantto issue the command:

depmod -a 2.0.x
where x is the minor number of the kernel you just built. This command creates the dependenciesfile some modules need. You'll also want to make sure you don't bootdirectly into xdm. For Red Hat type systems,this means ensuring the /etc/inittab filedoesn't have a default run level of 5, or that you remember to passLILO therun level at boot time. For Debian systems, you can just type:

mv /etc/init.d/xdm /etc/init.d/xdm.orig
for now and move it back later.

Normal Rebooting the New Kernel

Reboot your machine using:

shutdown -r now
While typing reboot or pressing thectrl+alt+del key combination usuallyworks, I don't recommend either one.Under some circumstances, the file systems won't be properlyunmounted and could corrupt open files. At the LILOprompt, if you need to boot the old kernel or pass some parameters forbootup and you don't see the boot: prompt, you can trypressing either theshift or ctrl key, and theboot: prompt should appear. Once you haveit, press tab to see the available kernel labels. Type the label andoptionally enter any parameters for bootup. Normally, however, the defaultkernel should boot automatically after the timeout interval specified inthe /etc/lilo.conf file. During bootup,you may see a few error messages containing: SIOCADDR or thelike. These usually indicate that a module (normally a network module)didn't load.We'll handle this shortly. If you got the error, ``VFS, cannot mountroot'', you didn't compile the proper disk or file-system support intothe kernel.

Troubleshooting

Due to the differentways in which each distribution handles daemon startupfrom /etc/inittab, it is difficult in this article to cover all thepossiblereasons your bootup may not have gone smoothly and thereasons why.However, I can tell you where to start looking.

First, run depmod -ato ensure you have an up-to-date, module dependency file (it willbecreated in the appropriate subdirectory). If youget a string of errors about unresolved dependencies, old modulesare present in the modules subdirectories, and you didn't configurethe kernel with ``Module Versions''enabled. This is not a fatal error. Themodules you compiled and installed are good. Check the/etc/conf.modules file and make sure that any lines pointing to/lib/modules are complete:

/lib/modules/`uname -r`/xx
(Note: the grave quote on each side of uname -ris located abovethe Tab key in the upper left corner of the keyboard on aU.S. keyboard).

Make sure kerneld is running and that it isloaded early in the bootup process. If it is, thenthe system doesn't need to explicitly load modules, kerneld willhandle it. Be careful about calling kerneld too early in the firstrc script. kerneld will stop the bootup process forcing a hard rebootvia the reset button or power switch, if it is called before the systemknows its host name. If this happens to you, you can reboot passing LILOthe -b argument which prevents init from executing any rc scripts.Next, look in /etc/rc.d/ at therc, rc.sysinit and rc.modules files. One or more may point to a directorysuch as /etc/modules/`uname -r`/`uname -v`where a list of bootup modules are located. You can just copy the oldfile over to the new directory;

mkdir /etc/modules/`uname -r` ;
cp /etc/modules/2.0.xx/g#1 Thu 3 Sep 1997.\
   default /etc/modules/`uname -r`/\
   `uname -v`.default""
Your system will almost certainly have a differentdate for the modules file. Your system also may or may not use thedefault extension. Pay close attention to the use of grave quotesand double quotes in the above example, since both are needed in the properplaces. Once you have found the keys to your system, you should beable to reboot into a properly functioning system. Ifyou experience further problems, the best place to get quick, expert adviceis on a mailing list dedicated to your particular distribution. Thosesuccessfully running a particular distribution usually delight inassisting novices with problems they may encounter. Why? Becausethey hit the same brick walls when they were novices and receivedhelp with many problems. Lurk a few days on a list, andif your question isn't asked by someone else, askit yourself. Check the mail-list archives first, if any are present.These archives contain answers to frequently asked questions (FAQ).

Conclusion

While building a kernel tailored to yoursystem may seem a daunting challenge for new administrators, the timespent is worth it. Your system will run more efficiently, and moreimportantly, you will have the satisfaction of building it yourself.

The few areaswhere you may encounter trouble are in remembering to rerun LILO afterinstalling the new kernel, but you didn't overwrite your old one (ordid you?), so you can always revert to one that worked from thelilo: prompt. Distributionspecific problems during bootup may also be encounteredduring thefirst reboot but are usually easily resolved. Help is normallyonly an e-mailaway for those distributions that don't come with technical support.
Logged
Sayfa: [1]
  Yazdır  
 

Ahtapot 2
Bu Sayfa 0.578 Saniyede 17 Sorgu ile Oluşturuldu

Kasım 21, 2008, 08:37:51 ÖS