biendich kernel

Download Biendich Kernel

Post on 12-Oct-2015

11 views

Category:

Documents

0 download

Embed Size (px)

DESCRIPTION

Bien dich Kernel

TRANSCRIPT

  • Bin dch nhn LinuxTc gi: Hong Ngc Diu

  • 1

    Mc lc

    1 Tng quan v nhn Linux trn phngdin bin dch li 3

    1.1 Nhn Linux v vic bin dch li nhn 31.2 Tm tt cc bc bin dch (dnh cho nhng ai thiu kin nhn) 3

    2 Ti sao cn bin dch li nhn Linux? 5

    3 Cu trc v quy c s hiu phin bnca nhn Linux 6

    4 i hi ti thiu trong vic bin dch linhn Linux 6

    4.1 i hi cho nhn Linux 2.4.x 74.2 i hi cho nhn Linux 2.6.x 8

    5 Xc nh cu hnh (hardware) ca my 9

    6 Cc bc chun b 96.1 To mt a mm khi ng cho nhn ang dng 96.2 Ti m ngun 106.3 Kim tra thc tnh ca m ngun 116.4 X nn m ngun 126.5 Dng "config" no th thch hp? 14

    7 Chnh cu hnh bin dch nhn Linux 147.1 Thnh phn ca cu hnh bin dch nhn Linux 147.1.1 Thnh phn cu hnh bin dch nhn Linux phin bn 2.4.x 147.1.2 Thnh phn cu hnh nhn Linux cho lot nhn 2.6.x 177.2 iu chnh cu hnh bin dch nhn Linux 187.2.1 Cc cng c xc lp cu hnh 197.2.2 Mt s im cn ch trong giai on hnh thnh cu hnh

    bin dch nhn 20

    8 Cc bc bin dch 228.1 Bc to dependency, dn dp v to nhn 228.2 Bc to modules v ci modules 248.3 Tch ri m ngun v h s output trn lot nhn 2.6.x 258.3.1 "make help", mt tin ch mi trn lot nhn 2.6.x 26

  • 2

    8.3.2 Tch ri m ngun v output files 27

    9 Ci t nhn 279.1 Ci t vi "make install" 289.1.1 i vi GRUB 289.1.2 i vi LILO 299.2 Cc bc ci t bng tay 319.2.1 To initrd 319.2.2 Copy nhn v System.map 329.2.3 Chnh cu hnh ca bootloader config 33

    10 Khi ng li my v chnh l nu gptrc trc 35

    10.1 B treo khi khi ng vo linux 3510.2 B treo trong qu trnh nhn c load 36

    11 V v bin dch nhn 3711.1 Cc im quan trng trc khi v 3711.2 Ti, x v v 38

  • 3

    1 Tng quan v nhn Linux trn phng din bin dchli

    1.1 Nhn Linux v vic bin dch li nhn

    Nhn Linux l mt "nhn hin i" c tnh module rt cao. T kernel phin bn 2.6.x tri, c rt nhiu chc nng v m rng. Vi tinh thn "bin dch nhn", mt yu t chnhyu v quan trng nht cn ghi nhn l tnh phn b (modularity) ca nhn Linux.

    i vi ngi dng bnh thng, modularity cho php chn la cch bin dch cc driversca nhn theo dng modules hay theo dng bin dch trc tip vo nhn. Thng thng,khi xc lp cu hnh cho nhn c ba chn la: Y, M v N.

    C nhng "driver" khng th bin dch nh mt module v n phi c load and linktrc tip ngay khi nhn khi ng. Cng c nhng "driver" cho php chn nh mtmodule v c ti trong khi v sau khi nhn c khi ng. im chnh yu cn nmbt trong gii hn ch "Bin dch nhn Linux" l hiu r ti sao phi chn M (chomodule), Y (cho bin dch trc tip) v N (khng dng) cc drivers ny.

    Bin dch trc tip vo kernel c ngha l cc "drivers" ny d c c dng haykhng vn c ti ln khi nhn khi ng v tt nhin n s chim mt phn bnh. Li im chnh ca chn la ny l mt khi "drivers" c bin dch vonhn th khng cn phi quan ngi n tnh trung thc ca nhn v cc driver na.Cc h thng lm vic i hi tnh bo mt cao khng dng modules m bin dchthng vo nhnkernel trnh trng hp cc modules khng tin cy "b" ci vonhn lc no trong qu trnh hot ng ca my. Li im k tip ca chn lany l tnh hiu xutxut (rt nh), khi cn driver th c sn v khng cn ng tina.

    Bin dch nh cc modules cho nhn c ngha l ch khi no cn dng cc "drivers"ny mi c ng ti. Li im ca chn la ny ni bt kha cnh x dng b nhv ti nguyn trn my. Vi la chn ny, bn c th to nn mt nhn rt nh v ddng di chuyn cho nhiu mc ch khc nhau. Li im k tip l kh nng bindch li ch mt hoc mt s modules no (cn cp nht chng hn). Tt nhin thc hin chuyn ny th phi tho mn tt c nhng i hi v tnh ph thuc cho hthng.

    1.2 Tm tt cc bc bin dch (dnh cho nhng ai thiu kinnhn)

    Bin dch nhn Linux rt n gin nu nh hiu r cc quy trnh v cc bc thchin. Sau y l cc lnh cn thit, gi nh bn c trn b cc cng c cn thit bin dch:

  • 4

    Chuyn vo th mc /usr/src, ni thng thng cha m ngun bin dch nhn:

    $ cd /usr/src

    l phin bn kernel cn bin dch, v d y ti m ngun c nn dng bz2)

    $ wget http://www.kernel.org/pub/linux/kern...>.tar.bz2 (

    Xc thc ch k v thc tnh ca m ngun:

    $ gpg --verify .tar.bz2.sign .tar.bz2

    X nn gi cha m ngun:

    $ bzip2 -dc .tar.bz2 | tar xvf -

    Nu mun dng giao din ha iu chnh cc chn la cho cu hnh nhn th dnglnh:

    $ make xconfig

    Tp hp lnh dng to cc file ph thuc v cc file bao gm (include), tip theo ldn dp cc objects khng cn thit v bin dch nhn dng nn:

    $ make dep clean bzImage

    Bin dch cc modules c chn la bng lnh:

    $ make modules

    Chchuyn sang ch super user cho lnh tip theo:

    $ su

    Ci cc modules vo th mc /lib/modules/ vi quyn ca superuser:

    # make modules_install

    Ci t nhn v cc file cn thit vo th mc /boot:

    # make install

    Bc th 10 c th thay th bng mt lot thao tc bng tay (chi tit phn 9.2) nu nhbn phn phi1 Linux khng c sn mt s cng c thuc gi mkinitrd (ch c trongbn RedHat v cc bn da trn RedHat).

    distribution1

  • 5

    Lu : i vi lot nhn 2.6.x, bn c th dng cc bc nh trn. Tuy nhin bc"make dep" khng cn thit na. Bi vit ny bao gm cho c phin bn 2.4.x v 2.6.xnn c mt s chi tit khng cn thit cho kernel 2.6.x. Tuy vy, nhng chi tit ny skhng nh hng n s thnh cng ca quy trnh bin dch nhn.

    2 Ti sao cn bin dch li nhn Linux?

    i vi ngi dng quen vi nhng h iu hnh "ng" th khi nim bin dch linhn l mt khi nim ht sc l lm. iu ny cng d hiu v kernel ca cc h iuhnh "ng" hin nhin l "ng" v ngi dng bnh thng khng th c c hi tipcn vi m ngun ca nhn c th bin dch li nhn nu mun. Trong khi , mngun ca nhn Linux hon ton "m" v y l iu kin rt thun li cho vn bindch li nhn. Cu hi c t ra l ti sao li cn phi bin dch li nhn Linux ?

    Cu tr li ngn: khng cn nu nh khng cn v cn nu nh cn :)

    Cu tr li di: c v s l do khin cho ngi dng cn phi bin dch li nhn Linux.Sau y l mt s trng hp thng gp nht:

    a. ti bin dch kernel cha li ca nhn. Nu cc li ny thuc v li ca nhn thphi v ngun ca nhn v bin dch li n sa cha cc li c cng b.

    b. bin dch li nhn nng cao hiu nng ca nhn. Theo mc nh, cc bn phnphi Linux thng km mt phin bn nhn c bin dch vi hu ht nhng thnhphn c sn c th p ng rng ri cu hnh phn cng (c th hin din trn ccmy). y l im li tng qut lc khi im. Tuy nhin, sau khi ci thnh cngv nm chc my c nhng thit b g (sound card, graphic card, network cards, SCSIcard..... ) v bit r cn nhng thnh phn no cho cu hnh ca my th khng cl do g phi bao gm trn b cc th khng cn thit v khng dng. i vi nhn2.4.x, mc nng cao hiu nng khng r rt (ngoi tr dng phng php test load o). Tuy nhin, t phin bn 2.6.x tr i, vic bin dch li v iu chnh "driver"cho nhn to hiu xut r rt, nht l trong vic iu chnh "thi biu" (scheduling)ca cc cng tc m h thng phi m nhim.

    c. bin dch li nhn loi b nhng "drivers" khng c dng v c th gy "hiulm" cho nhn, to ra trng hp my c nhng triu chng hot ng thiu n nhv hay gy li.

    d. bin dch li nhn th nghim mt chc nng hoc mt module mnh va to ra.Trng hp ny khng nhiu nh cc trng hp trn nhng cng nm trong cc ldo ph bin.

  • 6

    3 Cu trc v quy c s hiu phin bn ca nhnLinux

    Phin bn ca nhn Linux c quy c rt n gin v d nh. Vn ny cn nm rtrc khi chn mt phin bn no ca nhn Linux v v bin dch.

    Phin bn ca nhn Linux bao gm ba nhm s tch ra bi cc du chm. V d: 2.4.26

    S th nht: 2 l s hiu phin bn chnh

    S th nh: 4 l ch nh cho tnh trng phin bn. Nu s ny l s chn, n ch nh chophin bn n nh (stable), c th dng cho mi trng production. Nu s ny l s l,n ch nh cho phin bn khng n nh, n thng dng trong mi trng ang phttrin (development). Cc kernel thuc dng ny thng c nhiu li v khng n nh.Nu dng cc phin bn ny tm li v thng bo cho nhm pht trin nhn Linux thy l iu rt tt. Khng nn dng phin bn pht trin cho mi trng production.

    S th ba: 26 l ch nh cho s hiu pht hnh ca mt phin bn nhn Linux. Mtphin bn n nh ca mt nhn Linux c th c nhiu s hiu pht hnh khc nhau.

    y l cc quy c chung cho dng nhn Linux "vanilla" c ngha l ng dng chocc phin bn nhn t http://www.kernel.org, cc phin bn nhn c iuchnh bi mi bn phn phi c nhng im d bit. C nhiu bn Linux x dng s hiucon2 cho phin bn nhn h iu chnh. V d RedHat c nhng cp nht ph cho cckernel nh: 2.4.20-8 chng hn. iu cn nm y l ch nn x dng phin bn nnh (stable) ca nhn Linux (s chn gia) cho mi trng production v dng phinbn th nghim3 ca nhn Linux (s l) cho mi trng th nghim v pht trin.

    4 i hi ti thiu trong vic bin dch li nhn Linux

    Trc khi bt tay vo vic bin dch li nhn Linux, iu cn thit l phi c ch chatrn a. t nht l phi ch cha cho m ngun (trc v sau khi x nn), ch cha ci kernel v cc modules mi sau khi bin dch.

    i hi quan trng khc l phi c mt b cng c cn thit v ng phin bn. Khngth bin dch c nhn nu khng tho mn yu cu ny. Phin bn cho b cng c vimi phin bn nhn khc nhau. Nn nh, nhm pht trin nhn yu cu bn phi c ngphin bn ca cc cng c m bo vic bin dch nhn thnh cng.

    extra-version2

    development3

  • 7

    4.1 i hi cho nhn Linux 2.4.x

    Cng c Phin bn ti thiu Cch xc nh phin bn

    Gnu C 2.91.66 gcc --version

    Gnu make 3.77 make version

    binutils 2.9.1.0.25 ld -v

    util-linux 2.10o fdformat --version

    modutils 2.4.2 insmod -V

    e2fsprogs 1.19 tune2fs

    reiserfsprogs 3.x.0b reiserfsck 2>&1| grep reiserfsprogs

    pcmcia-cs 3.1.21 cardmgr -V

    PPP 2.4.0 pppd --version

    isdn4k-utils 3.1pre1 isdnctrl 2>&1| grep version

    Tham kho thm chi tit cc cng c ny v a ch ti cc cng c cho ng (tnht phi cng phin bn cung cp trn hoc mi hn) trong h s Documenta-tion/changes ca m ngun nhn m bn ang d tnh bin dch.

  • 8

    4.2 i hi cho nhn Linux 2.6.x

    Cng c Phin bn ti thiu Cch xc nh phin bn

    Gnu C 2.95.3 gcc --version

    Gnu make 3.78 make --version

    binutils 2.12 ld -v

    util-linux 2.10o fdformat --version

    module-init-tools 0.9.10 depmod -V

    e2fsprogs 1.29 tune2fs

    jfsutils 1.1.3 fsck.jfs -V

    reiserfsprogs 3.6.3 reiserfsck -V 2>&1| grep reiserfsprogs

    xfsprogs 2.1.0 xfs_db -V

    pcmcia-cs 3.1.21 cardmgr -V

    quota-tools 3.09 quota -V

    PPP 2.4.0 pppd --version

    isdn4k-utils 3.1pre1 isdnctrl 2>&1| grep version

    nfs-utils 1.0.5 showmount version

    procps 3.1.13 ps --version

    oprofile 0.5.3 oprofiled --version

Recommended

View more >