Biendich Kernel

Download Biendich Kernel

Post on 12-Oct-2015

9 views

Category:

Documents

0 download

Embed Size (px)

DESCRIPTION

Bien dich Kernel

TRANSCRIPT

<ul><li><p>Bin dch nhn LinuxTc gi: Hong Ngc Diu</p></li><li><p> 1 </p><p>Mc lc</p><p>1 Tng quan v nhn Linux trn phngdin bin dch li 3</p><p>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</p><p>2 Ti sao cn bin dch li nhn Linux? 5</p><p>3 Cu trc v quy c s hiu phin bnca nhn Linux 6</p><p>4 i hi ti thiu trong vic bin dch linhn Linux 6</p><p>4.1 i hi cho nhn Linux 2.4.x 74.2 i hi cho nhn Linux 2.6.x 8</p><p>5 Xc nh cu hnh (hardware) ca my 9</p><p>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</p><p>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</p><p>bin dch nhn 20</p><p>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</p></li><li><p> 2 </p><p>8.3.2 Tch ri m ngun v output files 27</p><p>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</p><p>10 Khi ng li my v chnh l nu gptrc trc 35</p><p>10.1 B treo khi khi ng vo linux 3510.2 B treo trong qu trnh nhn c load 36</p><p>11 V v bin dch nhn 3711.1 Cc im quan trng trc khi v 3711.2 Ti, x v v 38</p></li><li><p> 3 </p><p>1 Tng quan v nhn Linux trn phng din bin dchli</p><p>1.1 Nhn Linux v vic bin dch li nhn</p><p>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.</p><p>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.</p><p>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.</p><p> 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.</p><p> 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.</p><p>1.2 Tm tt cc bc bin dch (dnh cho nhng ai thiu kinnhn)</p><p>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:</p></li><li><p> 4 </p><p>Chuyn vo th mc /usr/src, ni thng thng cha m ngun bin dch nhn:</p><p>$ cd /usr/src</p><p> l phin bn kernel cn bin dch, v d y ti m ngun c nn dng bz2)</p><p>$ wget http://www.kernel.org/pub/linux/kern...&gt;.tar.bz2 (</p><p>Xc thc ch k v thc tnh ca m ngun:</p><p>$ gpg --verify .tar.bz2.sign .tar.bz2</p><p>X nn gi cha m ngun:</p><p>$ bzip2 -dc .tar.bz2 | tar xvf -</p><p>Nu mun dng giao din ha iu chnh cc chn la cho cu hnh nhn th dnglnh:</p><p>$ make xconfig</p><p>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:</p><p>$ make dep clean bzImage</p><p>Bin dch cc modules c chn la bng lnh:</p><p>$ make modules</p><p>Chchuyn sang ch super user cho lnh tip theo:</p><p>$ su</p><p>Ci cc modules vo th mc /lib/modules/ vi quyn ca superuser:</p><p># make modules_install</p><p>Ci t nhn v cc file cn thit vo th mc /boot:</p><p># make install</p><p>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).</p><p>distribution1</p></li><li><p> 5 </p><p>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.</p><p>2 Ti sao cn bin dch li nhn Linux?</p><p>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 ?</p><p>Cu tr li ngn: khng cn nu nh khng cn v cn nu nh cn :)</p><p>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:</p><p>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.</p><p>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.</p><p>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.</p><p>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.</p></li><li><p> 6 </p><p>3 Cu trc v quy c s hiu phin bn ca nhnLinux</p><p>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.</p><p>Phin bn ca nhn Linux bao gm ba nhm s tch ra bi cc du chm. V d: 2.4.26</p><p>S th nht: 2 l s hiu phin bn chnh</p><p>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.</p><p>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.</p><p>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.</p><p>4 i hi ti thiu trong vic bin dch li nhn Linux</p><p>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.</p><p>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.</p><p>extra-version2</p><p>development3</p></li><li><p> 7 </p><p>4.1 i hi cho nhn Linux 2.4.x</p><p>Cng c Phin bn ti thiu Cch xc nh phin bn</p><p>Gnu C 2.91.66 gcc --version</p><p>Gnu make 3.77 make version</p><p>binutils 2.9.1.0.25 ld -v</p><p>util-linux 2.10o fdformat --version</p><p>modutils 2.4.2 insmod -V</p><p>e2fsprogs 1.19 tune2fs</p><p>reiserfsprogs 3.x.0b reiserfsck 2&gt;&amp;1| grep reiserfsprogs</p><p>pcmcia-cs 3.1.21 cardmgr -V</p><p>PPP 2.4.0 pppd --version</p><p>isdn4k-utils 3.1pre1 isdnctrl 2&gt;&amp;1| grep version</p><p>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.</p></li><li><p> 8 </p><p>4.2 i hi cho nhn Linux 2.6.x</p><p>Cng c Phin bn ti thiu Cch xc nh phin bn</p><p>Gnu C 2.95.3 gcc --version</p><p>Gnu make 3.78 make --version</p><p>binutils 2.12 ld -v</p><p>util-linux 2.10o fdformat --version</p><p>module-init-tools 0.9.10 depmod -V</p><p>e2fsprogs 1.29 tune2fs</p><p>jfsutils 1.1.3 fsck.jfs -V</p><p>reiserfsprogs 3.6.3 reiserfsck -V 2&gt;&amp;1| grep reiserfsprogs</p><p>xfsprogs 2.1.0 xfs_db -V</p><p>pcmcia-cs 3.1.21 cardmgr -V</p><p>quota-tools 3.09 quota -V</p><p>PPP 2.4.0 pppd --version</p><p>isdn4k-utils 3.1pre1 isdnctrl 2&gt;&amp;1| grep version</p><p>nfs-utils 1.0.5 showmount version</p><p>procps 3.1.13 ps --version</p><p>oprofile 0.5.3 oprofiled --version</p><p>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 bn ang d tnh bin dch.</p><p>Nu phin bn ca cc cng c trn my c hn cc phin bn a ra trn, bn cnphi ti phin bn mi ( bin dch) t website ca bn phn phi no bn ang dng.Bn cng c th chn cch ti m ngun ca tng cng c v bin dch li. Cch nymt thi gian hn rt nhiu v ch thch hp cho nhng ai quen thuc vi vn bindch m ngun trn Linux. Li im ca cch ny l bn to cho mnh mt b cng crt "sch" v bin dch theo , thch hp vi mi trng ca my (v va ).</p><p>i vi phn cng IA64, bn cn phin bn GCC cho 64bit, nn tham kho chi tit http://gcc.gnu.org/install/specific.html (nu bn may mn cmt con IA64 th)</p></li><li><p> 9 </p><p>5 Xc nh cu hnh (hardware) ca my</p><p>Phn ln ngi dng bnh thng t khi quan tm n cu hnh ca my ngoi tr c nhucu c th. Ngay c nhng ai dng Linux lu v khng cn phi bin dch li nhn,cng t khi quan tm n cu hnh phn cng ca my. D c bit nhiu hay t v cuhnh phn cng ca my mnh dng, bn vn phi thu thp thng tin chnh xc ca cuhnh trc khi bt tay vo vic iu chnh cu hnh cho vic bin dch nhn.</p><p>Gi nh mi chnh l n nh v lm vic tt p (do trnh ci t t d tm (detect)trong khi ci Linux hay do bn phi iu chnh li), bn cn bin dch li nhn Linux vcn thu thp thng tin v cu hnh ca my, hai lnh sau cung cp cc chi tit phn cngc trn my:</p><p># /sbin/lspci</p><p>Lnh ny lit k trn b cc "card" ang trc tip lm vic trn my, phin bn phncng v kiu4 ca chng.</p><p># cat /proc/cpuinfo</p><p> xem chi tit b x l trung tm (CPU) ca my l loi g. Nu bn Linux m bndng khng c /proc filesystem th bn c th dng lnh dmesg thu thp thng tinv phn cng trn my ca mnh. Ngoi ra, lnh lsmod cng t nhiu gip bn xc nhcc modules ang c dng trn my v tn ca cc modules ny.</p><p>Nhng thng tin thu thp c y ht sc quan trng trong giai on iu chnh cuhnh cho vic bin dch nhn. N gip bn xc nh cc chn la ng cho cu hnh my,trnh i nhng tr ngi c th rt mt thi gian sau ny.</p><p>6 Cc bc chun b</p><p>6.1 To mt a mm khi ng cho nhn ang dng</p><p>y l mt bc cn thit phng s c g khin bn khng th khi ng vo hthng Linux sau khi ci nhn mi. Trng hp ny him khi xy ra trong qu trnh bindch nhn v ci nhn mi nu bn thc hin v iu chnh ng. Nhng s c vi trnhkhi ng5 t thy xy ra v trnh khi ng c thit lp hon chnh trc khi cpnht nhn. Phn ln giai on iu chnh li cu hnh ca LILO hoc GRUB khng chnhxc to tr ngi. Vn ny s c cp sau. Trc mt chng ta cn to mt a mmkhi ng.</p><p>model4</p><p>bootloader, LILO hoc GRUB5</p></li><li><p> 10 </p><p>C rt nhiu cch to mt a mm khi ng ly t nhn hin ang chy trn my.Thay v trnh by nhiu cch khc nhau cho vic to a mm khi ng, y ti ch cp n phng thc n gin nht. Cch d nht c l l dng mkbootdisk. y lmt cng c c ci mc nh trn cc bn RedHat v hu ht cc bn phn phi datrn RedHat. Nu cng c ny khng hin din trn my, bn c th ti m ngun v vbin dch. Chy lnh:</p><p># mkbootdisk --device /dev/fd0 uname -r</p><p>trong uname -r l lnh ly phin bn nhn hin dng trn my. Nu khngmun phin bn ny, bn c th g vo phin bn no theo (tt nhin l phin bnkernel ny phi hin hu trn h thng).</p><p>/dev/fd0 l "device" ch cho a mm th nht trn my (tng t nh drive A: trnDOS). Bn phi chn ng "device" th mi c d liu vit vo a mm mnh mun to.</p><p>Quy trnh ny ch mt khong vi pht. Sau khi to a mm khi ng trn, bn nndng n th khi ng vo Linux trc khi thc hin cc bc k tip. Nn nh phichnh BIOS cho php my khi ng t A:</p><p> trang http://www.yolinux.com/TUTORIALS/LinuxTutorialRecoveryAndBootDisk.htmlc cc hng dn to a cp cu rt hay. Bn nn tham kho thm nu trn my mnhdng khng c sn cng c mkbootdisk.</p><p>6.2 Ti m ngun</p><p>M ngun ca nhn Linux (c phin bn n nh ln ang pht trin) c rt nhiu nitrn Internet. Nn vo trang trung tm ca nhn Linux http://www.kernel.org v tham kho danh sch "mirrors" tm ni "gn" ch mnh c ng nht ti v.Ni "gn" khng nht thit l "gn" theo phng din a l m nn chn "gn" nht datrn "ping time". Chu kh ly vi a ch trn mirror v ping nhng a ch ny chnly ni c ping time ngn nht m ti v. Bng cch s gip bn mt thi gian v tincho vn chia x bng thng.</p><p>C nhiu cch ti m ngun. Bn c th dng trnh duyt (browser) ti qua giao thchttp hoc dng mt trnh ftp no ti qua giao thc ftp. Bn cng c th dng wget.C l y l cch tin nht v nhanh nht nu bit r a ch v ng dn n gi mnhmun ti. V d:</p><p>$ wget http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.26.tar.bz2</p><p>trong trng hp ny, gi c th cn ti l linux-2.4.26.tar.bz2.</p><p>M ngun n nh ca Linux kernel c nn hai dng khc nhau: dng c ui l .gz(dng GNUzip nn) v dng c ui .bz2 (dng bzip2 nn). Thng thng c haitin ch nn/x nn trn u c sn trong cc bn Linux thng dng. Nu khng c sn</p></li><li><p> 11 </p><p>trn my th tm trong trong CD ca bn Linux (tham kho thm ti liu ca distributionmnh dng cho cch ci thm phn mm vo my) hoc ti v t:</p><p> http://www.gzip.org cho GNUzip</p><p> http://sources.redhat.com/bzip2/ cho bzip2</p><p>6.3 Kim tra thc tnh ca m ngun</p><p>iu quan trng khi ti m ngun ca nhn, nn ti lun ch k GPG .sign cho phinbn tng ng. Mc ch l kim tra thc tnh ca m ngun c ti v. Khi mngun ca nhn Linux c cng b, chng c dn li thnh mt gi (.tar) v sau c nn bng GNUzip hoc bzip2, c hai loi ny sau khi c nn u c to "chk" .sign.</p><p>Kim tra thc tnh ca m ngun c ti v bng phng php kim tra "ch k" catng gi m ngun l mt thi quen cn thit. L do: cc m ngun m ni chung ccng b v ph bin rng ri, ai cng c th chnh sa (mt cch khng chnh thc vkhng c nhm pht trin chnh thc cho php) ri a ln mt my ch no trnInternet. Ngi dng ti v, bin dch v ci trn my m khng kim tra thc tnh cachng (v m ngun ny c nhng thay i m m) th hu qu kh m lng.</p><p>Quy trnh kim tra "ch k" ch n gin gi gn trong mt dng lnh:</p><p>$ gpg --verify linux-2.4.26.tar.bz2.sign linux-2.4.26.tar.bz2</p><p>trong linux-2.4.26.tar.bz2.sign l "ch k" ca gi linux-2.4.26.tar.bz2 c ti v tserver cha m ngun nhn Linux linux-2.4.26.tar.bz2 l gi m ngun nhn Linux cnn bng bzip2.</p><p>Trc khi c th kim tra thnh cng bng lnh trn, bn phi c gpg ci trong my,ti v nhp cha kha cng cng (public key) ca my ch cha m ngun nhn Linux mbn ti v. Chi tit hng dn cho quy trnh ny http://www.kernel.org/signature.html</p><p>Quy trnh ti m ngun nhn Linux v kim tra thc tnh ca m ngun ny...</p></li></ul>