Tải bản đầy đủ - 0 (trang)
Chapter 17.  System Start and Shutdown

Chapter 17.  System Start and Shutdown

Tải bản đầy đủ - 0trang

17.1.BootingtheSystem

ThereareseveralwaysofbootingLinuxonyoursystem.The

mostcommonmethodsinvolvebootingfromtheharddriveor

usingabootfloppy.Inmanycases,theinstallationprocedure

willhaveconfiguredoneorbothoftheseforyou;inanycase,

it'simportanttounderstandhowtoconfigurebootingfor

yourself.



17.1.1.UsingaBootFloppy

Traditionally,aLinuxbootfloppysimplycontainsakernel

image,whichisloadedintomemorywhenyouinsertthefloppy

andstartthesystem.[*]

[*]ALinuxbootfloppymayinsteadcontainaGRUBbootrecord,whichcausesthesystemtobootakernelfrom

theharddrive.Wediscussthisinthenextsection,whenwetalkmoreaboutGRUB.



ManyLinuxdistributionscreateabootfloppyforyouinthisway

wheninstallingthesystem.Usingabootfloppyisaneasyway

tobootLinuxifyoudon'twanttobotherbootingfromthehard

drive.(Forexample,WindowsNT/2000/XP'sbootmanageris

somewhatdifficulttoconfigureforbootingLinux.Wetalkabout

thisinthenextsection.)Oncethekernelhasbootedfromthe

floppy,youarefreetousethefloppydriveforotherpurposes.

Weincludesometechnicalinformationhereinordertoexplain

thebootprocess,butrestassuredthatinmostcases,youcan

justinsertthefloppydisk,andbootingworks.Readingthe

followingparagraphswillhelpyouunderstandyoursystem,

though.

Thekernelimageisusuallycompressed,usingthesame

algorithmasthegziporthebzip2compressionprograms(more



onthisin"Compilingthekernel"inChapter18).Compression

allowsthekernel,whichmaybeseveralmegabytesormorein

size,torequireonlyafewhundredkilobytesofdiskspace.Part

ofthekernelcodeisnotcompressed:thispartcontainsthe

routinesnecessarytouncompressthekernelfromthedisk

imageandloaditintomemory.Therefore,thekernelactually

bootstrapsitselfatboottimebyuncompressingintomemory.

Anumberofparametersarestoredinthekernelimage.Among

theseparametersisthenameofthedevicetouseastheroot

filesystemoncethekernelboots.Anotherparameteristhetext

modetouseforthesystemconsole.Alltheseparametersmay

bemodifiedusingtherdevcommand,whichwediscusslaterin

thissection.

Afterthekernelhasstarted,itattemptstomountafilesystem

ontherootdevicehardcodedinthekernelimageitself.Thiswill

serveastherootfilesystemthatis,thefilesystemon/.

"ManagingFilesystems"inChapter10discussesfilesystemsin

moredetail;allthatyouneedtoknowfornowisthatthekernel

imagemustcontainthenameofyourrootfilesystemdevice.If

thekernelcan'tmountafilesystemonthisdevice,itgivesup,

issuingakernel"panic"message.(Essentially,akernelpanicis

afatalerrorsignaledbythekernelitself.Apanicwilloccur

wheneverthekernelisterminallyconfusedandcan'tcontinue

withexecution.Forexample,ifthereisabuginthekernel

itself,apanicmightoccurwhenitattemptstoaccessmemory

thatdoesn'texist.We'lltalkaboutkernelpanicsmoreinthe

section"WhattoDoinanEmergency"inChapter27.)

Therootdevicestoredinthekernelimageisthatofyourroot

filesystemontheharddrive.Thismeansthatoncethekernel

boots,itmountsaharddrivepartitionastherootfilesystem,

andallcontroltransferstotheharddrive.Oncethekernelis

loadedintomemory,itstaystherethebootfloppyneednotbe

accessedagain(untilyourebootthesystem,ofcourse).

Givenareasonablysmallkernelimage,youcancreateyour



ownbootfloppy.OnmanyLinuxsystems,thekernelitselfis

storedinthefile/boot/vmlinuz.[*]Thisisnotauniversal

convention,however;otherLinuxsystemsstorethekernelin

/vmlinuzor/vmlinux,andstillothersinafilesuchas/Image.

(Ifyouhavemultiplekernelimages,youcanuseGRUBto

selectwhichonetoboot.Seethenextsection.)Notethatnewly

installedLinuxsystemsmaynothaveakernelimageonthe

harddriveifabootfloppywascreatedforyou.Inanycase,you

canbuildyourownkernel.It'softenagoodideatodothis

anyway:youcancustomizethekerneltoincludeonlythose

driversforyourparticularhardware.See"BuildingtheKernel"

inChapter18fordetails.

[*]Whythesillyfilename?OnmanyUnixsystems,thekernelisstoredinafilenamed/vmunixwherevmstands

for"virtualmemory."Naturally,Linuxhastobedifferentandnamesitskernelimagesvmlinux,andplacesthem

inthedirectory/boottogetthemoutoftherootdirectory.Thenamevmlinuzwasadoptedtodifferentiate

compressedkernelimagesfromuncompressedimages.Actually,thenameandlocationofthekerneldon't

matterabit,aslongasyoueitherhaveabootfloppycontainingakernel,orGRUBknowshowtofindthekernel

image.



Allright.Let'ssaythatyouhaveakernelimageinthefile

/boot/vmlinuz.Tocreateabootfloppy,thefirststepistouse

rdevtosettherootdevicetothatofyourLinuxrootfilesystem.

(Ifyoubuiltthekernelyourself,thisshouldbealreadysetto

thecorrectvalue,butitcan'thurttocheckwithrdev.)We

discussedhowtocreatetherootdevicein"Editing/etc/fstab"in

Chapter2.

Asroot,userdev-htoprintausagemessage.Asyouwillsee,

therearemanysupportedoptions,allowingyoutospecifythe

rootdevice(ourtaskhere),theswapdevice,ramdisksize,and

soon.Forthemostpart,youneedn'tconcernyourselfwith

theseoptionsnow.

Ifweusethecommandrdev/boot/vmlinuz,therootdevice

encodedinthekernelfoundin/boot/vmlinuzwillbeprinted:

courgette:/#rdev/boot/vmlinuz

Rootdevice/dev/hda1



Ifthisisincorrect,andtheLinuxrootfilesystemisactuallyon

/dev/hda3,weshouldusethefollowingcommand:

courgette:/#rdev/boot/vmlinuz/dev/hda3

courgette:/#



rdevisthestrong,silenttype;nothingisprintedwhenyouset

therootdevice,sorunrdev/boot/vmlinuzagaintocheckthatit

issetcorrectly.

Nowyou'rereadytocreatethebootfloppy.Forbestresults,use

abrand-new,formattedfloppy.Youcanformatthefloppyunder

WindowsorusingfdformatunderLinux;thiswilllaydownthe

sectorandtrackinformationsothatthesystemcanautodetect

thesizeofthefloppy.(Seethesection"ManagingFilesystems"

inChapter10formoreonusingfloppies.)

Tocreatethebootfloppy,useddtocopythekernelimagetoit,

asinthefollowingexample:

courgette:/#ddif=/boot/vmlinuzof=/dev/fd0bs=8192



Ifyou'reinterestedindd,themanualpagewillbeillustrative;

inbrief,thiscopiestheinputfile(ifoption)named

/boot/vmlinuztotheoutputfile(ofoption)named/dev/fd0(the

firstfloppydevice),usingablocksize(bs)of8192bytes.Of

course,theplebiancpcanbeusedaswell,butweUnix

sysadminslovetousecrypticcommandstocompleterelatively

simpletasks.That'swhatseparatesusfrommortalusers.

Yourbootfloppyshouldnowbereadytogo.Youcanshutdown

thesystem(see"ShuttingDowntheSystem"laterinthis



chapter)andbootwiththefloppy,andifallgoeswell,your

Linuxsystemshouldbootasitusuallydoes.Itmightbeagood

ideatomakeanextrabootfloppyasaspare.In"WhattoDoin

anEmergency,"inChapter27,wedescribemethodsbywhich

bootfloppiescanbeusedtorecoverfromdisaster.



17.1.2.UsingGRUB

GRUBisageneral-purposebootmanagerthatcanboot

whateveroperatingsystemsyouhaveinstalledonyour

machine,includingLinux.Therearedozensofwaystoconfigure

GRUB.Here,wediscussthetwomostcommonmethods:

installingGRUBonthemasterbootrecordofyourharddrive

andinstallingGRUBasasecondarybootloaderforLinuxonly.

GRUBisthemostcommonwaytobootLinuxfromthehard

drive.(Bytheexpression"bootfromtheharddrive,"wemean

thatthekernelitselfisstoredontheharddriveandnoboot

floppyisrequired,butrememberthatevenwhenyouusea

bootfloppy,controlistransferredtotheharddriveoncethe

kernelisloadedintomemory.)IfGRUBisinstalledonyour

drive'smasterbootrecord,orMBR,itisthefirstcodetorun

whentheharddriveisbooted.GRUBcanthenbootother

operatingsystemssuchasLinuxorWindowsandallowyouto

selectbetweenthematboottime.



ItshouldbementionedherethatGRUBisnottheonlybootmanager

availableforbootingLinux.Therearealternatives,suchastheolder

LILO(LinuxLoader)thatworkjustaswell.However,becausemost

distributionsthesedaysuseGRUB,thisiswhatwecoverhere.



WindowsNTandlaterversionsofWindowshavebootmanagers

oftheirownthatoccupytheMBR.Ifyouareusingoneofthese



systems,inordertobootLinuxfromtheharddrive,youmay

havetoinstallGRUBasthe"secondary"bootloaderforLinux

only.Inthiscase,GRUBisinstalledonthebootrecordforjust

yourLinuxrootpartition,andthebootmanagersoftware(for

WindowsNT/2000)takescareofexecutingGRUBfromthere

whenyouwishtobootLinux.

Aswe'llsee,however,theWindowsNT/2000/XPbootmanagers

aresomewhatuncooperativewhenitcomestobootingGRUB.

Thisisapoordesigndecision,andifyoumustabsolutelyuse

oneofthesebootmanagers,itmightbeeasiertobootLinux

fromfloppyinstead.Readon.Or,ifyoureallywanttogowith

Linuxalltheway,youcanuseGRUBtobootWindows

NT/2000/XPanddumptheWindowsbootmanagerscompletely.

Thatisusuallyafairlypainlessway,andtheonewe

recommend.Itisalsowhatmostdistributionsinstall

automaticallyifyoutrytoinstallLinuxonacomputerwithan

existingWindowsinstallation.

UseofGRUBwithWindows95/98/ME/2000/XPisquitesimple.

YoujustconfigureGRUBtobootWindows95/98/ME/2000/XP

(seethenextsection).However,ifyouinstallWindows

95/98/ME/2000/XPafterinstallingGRUB,youneedtoreinstall

GRUB(astheWindows95/98/ME/2000/XPinstallation

procedureoverwritestheMBRofyourprimaryharddrive).Just

besureyouhaveaLinuxbootfloppyonhandsothatyoucan

bootLinuxandrerunGRUB.

BeforeproceedingyoushouldnotethatanumberofLinux

distributionsarecapableofconfiguringandinstallingGRUB

whenyoufirstinstalltheLinuxsoftware.Itmightbeagood

ideatojustletyourdistribution'sinstallationprogramdoits

thing,installGRUB,andthencheckwhatithasdone;thisgives

yousomethingworkingtostartwiththatyoucanthentweakto

yourtaste.



17.1.2.1.The/etc/grub.conffile



ThefirststepinconfiguringGRUBistosetuptheGRUB

configurationfile,whichisoftenstoredin/etc/grub.conf.The

/etc/grub.conffilereferencesotherconfigurationfilesthatwe

lookatlater.Often,the/etc/grub.conffilecanbeveryshort.

Wearegoingtolookatasamplegrub.conffile.Youcanusethis

fileasabaseforyourowngrub.confandedititforyourown

system.

ItshouldbesaidatthispointthatGRUBisveryflexibleandcan

actuallydropyouintoashellthatletsyouenterGRUB

commandsinteractivelyduringthebootprocess.However,most

userswouldfindthisbothtediousanderror-prone,whichis

whywedescribeanotherusehere,whichwillprovideyouwith

aconvenientmenuthatyoucanselectfrom(forexample,in

ordertobootdifferentkernelsorevendifferentoperating

systems).Withthissetup,thegrub.conffilecanbequite

concise.Hereisanexample:



root(hd0,0)

install--stage2=/boot/grub/stage2/grub/stage1(hd0)/grub/sta

(hd0,0)/grub/menu.lst

quit



Thefirstlinespecifiesthedrivetobootfrom.Inthiscase,itis

thefirstpartitiononthefirstharddisk--hdisforharddisk,the

firstzeroisforthefirstharddiskinthesystem,andthesecond

zeroforthefirstpartitiononthatparticularharddisk(GRUB

alwaysstartscountingatzero!).Itisquitecommonamong

Linuxuserstoreserveasmallpartition(oftenmountedas

/boot)forthekernelimageandbooting-relatedfiles.Because

therehavebeenlimitsinthepastregardingthepartsofthe

diskfromwhichbootloaderscouldloadkernelimages,ithas

becomecustomarytomakethispartitiontheveryfirstone.

Althoughtheselimitsaremostlygonewithmodernhardware,



modernBIOSes,andmodernbootloaders,thistradition

prevails,anditdefinitelydoesnothurttokeepit.

Afewmoreexamples:(fd0)wouldmeantobootfromthefirst

floppydiskinthesystem,and(hd3,4)wouldmeanthefifth

partitiononthefourthharddrive(ofoneluckyLinuxuserwho

apparentlycanaffordlotsofhardware).Thereisalsothe

specialname(nd)whichisusedforbootingthekernelimage

fromthenetwork,somethingthatisbeyondthescopeofthis

book.

Thesecondlineisfairlycomplex.Itwouldgotoofartodissect

thecompletebootingprocess,butwecanatleastsaythat

GRUBusesatwo-stagebootingprocess,andthiscommand

specifieswheretogettheinstructionsforthetwostagesfrom,

atwhichaddresstoloadthemintothecomputer'smemory,and

whattodothen.The"whattodothen"partisthemost

interestingforus;intheexampleconfigurationfile,itisthe

(hd0,0)/grub/menu.lstpartattheend.Whereshouldthisfilebe

locatedsothatGRUBcanfindit?Ifyoutry:

pooh:~#ls/grub/menu.lst

/bin/ls:/grub/menu.lst:Nosuchfileordirectory



youwillnotfindit.ButrememberthatGRUBusesthe

parenthesestodenoteadevice,inourcaseaharddisk

partition,thefirstpartitiononthefirstharddrive.Thiscouldbe

anywhere,ofcourse,butifyourememberthatmostsystems

createasmallpartitionthatdoesnotcontainmuchexceptthe

kernelimageandthebootloaderfiles,andthatitisoften

mountedas/boot,youcantry:

pooh:~#ls/boot/grub/menu.lst

/boot/grub/menu.lst



Aha!Ofcourse,ifyouareinstallingGRUBfromscratchonyour

systemand,unlikeus,donothaveapreinstalledconfiguration

thatyouarejustfiddlingaroundwith,thenyouwillnotgeta

resulthereeither.Restassured,however,thatthisiswhere

GRUBwillsearchforthemenufile.

Whatwouldsuchamenufilelooklike?Hereisanexampleofa

versionthatloadstwodifferentLinuxconfigurationsandMSWindows,allpresentedinaconvenientmenu:

default0

timeout10

titleLinux

kernel(hd0,5)/boot/vmlinuzroot=/dev/hda6vga=0x314



titleLinuxFailsafe

kernel(hd0,5)/boot/vmlinuzroot=/dev/hda6ide=nodmaapm=of

barrier=offnosmpnoapicmaxcpus=03

titleWindows

root(hd0,0)

chainloader+1



Thefirsttwolinestogethermeanthatwhenthebootmenuis

presentedbyGRUB,theuserhas10seconds(timeout)tomake

achoice;otherwise,thefirstentryofthefollowinglistwillbe

booted.

Afterthesetwoinitiallines,therearethreesectionsthateach

startwithtitle.Afterthetitle,astringisspecifiedthatwillbe

showninthebootmenuatboottime.ForthetwoLinux

configurations,thereisthenakernellinethatshowswherethe



kernelimageisloadedfrom.Everythingelseispasseddirectly

tothekernelasbootparameters,includingwhattherootdevice

shouldbe,andtheterminalmode(vga=0x314).Intheso-called

failsafeconfiguration,wespecifyalotofkernelparametersthat

turnoffjustaboutanykernelfunctionalitythathastheslightest

chanceofgoingwrong.Suchasystemwillbeslowandnot

havecompletefunctionality,butifyouhavemisconfigured

something,thefailsafekernelmaystillgetalongandletyouat

leastbootthesystemsothatyoucanrepairthings.

IfyoutypeinthosecommandsmanuallyattheGRUBshell,you

wouldhaveendedwiththecommandboot.Thekernelcommand

loadsthekernelintomemory,butdoesnotactuallybootit;the

bootcommandperformstheactualbootingprocess.However,if

youusetheGRUBmenusystemaswedohere,theboot

commandisimplicitandcanbeleftoutattheendofeach

section.

LoadingWindowsworksdifferently.GRUBisnotabletoload

operatingsystemsotherthanLinux,theBSDfamily,andafew

othersdirectly.Forthoseothersystems,suchasWindows,it

invokesinsteadthebootloaderthatcomeswiththosesystems.

Thisiscalledchain-loading,andtheGRUBcommandtodothis

isnotsurprisinglycalledchainloader.The+1meansthatGRUB

canfindthebootloaderonthepartitionspecifiedwiththe

previousrootcommand,onesectorintothepartition.

WhenyouaresatisfiedwithyourGRUBsetup,youstillneedto

installit.Thisisbestdonewiththecommandgrub-install,

whichexpectstobetoldthedirectoryinwhichthestagefiles

andkernelimagescanbefound,andonwhichdevicetoinstall

thebootloader.Thiscouldlooklikethis:

pooh:~#grub-install--root-directory=/boot/dev/hda



ThisinstallsthebootloaderonthefirstIDEharddrive(/dev/hda),



whichistypicallytheonethatthecomputer'sBIOSsearchesfor

findingtheinitialbootinginformation.

ThiswasjustashortintroductionintotheworldofGRUB.GRUB

candoalotmore,suchasbootingkernelimagesfromthe

networkoroveraserialline,providingfancygraphics,andso

on.IfyouplantodoanyseriousworkwithGRUB(andsincea

bootloaderiscrucialforbeingabletousethesystematall,any

changesofconfigurationfilesbeyondtrivialthingssuchas

changingthestringsofthemenuentries,thedefaultentry,or

thetimeout,canbeconsideredseriousinthiscontext),weurge

youtoreadtheexcellentGRUBdocumentationthatcomesas

Infofiles,andthatyoucanreadnicelyinKDEbytyping

info:grubinKonqueror'slocationbar.



17.1.2.2.Specifyingboot-timeoptions

WhenyoufirstinstalledLinux,morethanlikelyyoubooted

eitherfromafloppyoraCD-ROM,whichverylikelygaveyoua

GRUB(orotherbootloader)bootmenu.Selectinganentryand

typingegetsyouabootprompt.Atthispromptyoucanenter

severalboot-timeoptions,suchas:

hd=cylinders,heads,sectors



tospecifytheharddrivegeometry.EachtimeyoubootLinux,it

maybenecessarytospecifytheseparametersinorderforyour

hardwaretobedetectedcorrectly.IfyouareusingGRUBto

bootLinuxfromtheharddrive,youcanspecifythese

parametersinthekernellineintheGRUBconfigurationfile

insteadofenteringthematthebootprompteachtime.Tothe

Linuxentry,justaddalinesuchas:

append="hd=683,16,38"



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 17.  System Start and Shutdown

Tải bản đầy đủ ngay(0 tr)

×