51 Boot Sequence-Run Levels
51 Boot Sequence-Run Levels
4January2007
MichelBisson
51LinuxBootsequence,RunlevelsandLogin
51_Boot_SequenceRun_Levels.sxw1
LinuxCourseBootRunlevelsLogin
4January2007
MichelBisson
FromBooting........toBashprompt.
BiosloadLILOfromMBR(firstharddiskactivatedforbooting)
LILO 1. 2. 3. 4.
Kernel
1. Detectsandinitializesomesystemdevices (mouse,cpu,clock,pcibus,etc) 2. DetectsandinitializesBlockdevices(IDE,SCSI,floppy,cdrom,etc.) 3. Mounttheinitrdfilesystem 1. Startlinuxrcfrominitrd 1. Loads kernel modules to prepare to mount root(/)filesystem. 2. Manages RAID and LVM Setups(optional) 3. Mounts network(NFS) root (/)file system(optional) 4. Unmountsinitrdandmountsroot(/)filesystem. 5. Starts/sbin/init
init
1. Reads/etc/inittabandrunsallbootandbootwaitactions 2. Loadstheblogddaemon: Itlogsallthebootscriptsoutputto/var/log/boot.msg 3. Runs/etc/init.d/boot script Mounts(creates)the/procdevice Activatestheswapdevicesin/etc/fstab Startsthefilesystemcheckingwithfsck Mountsthelocalfilesystem(accordingto/etc/fstab) Settinguplocalparameters:
/etc/ld.so.cache,Timezone,Loopbackdevice,Hostname,CMOSClocketc.
- Executesscripts(ifpresent)in/etc/init.d/boot.d/ - Executesthescript(ifpresent)/etc/init.d/boot.local 4. Reads/etc/inittab(id:x:initdefault:) andstarts/etc/init.d/rcscript: 1. Syy...scripts(Slinks)from/etc/init.d/rcx.d willberuninsequenceorderoftheyy. x=therunlevelyy=executionsequence 2. Asthesescriptsarerun,theirresultsareshownonscreen (OKordone) Notes:Eachtimeachildterminates,initrecordsthefact andthereasonitdiedin/var/run/utmpand /var/log/wtmp, iftheyexist. Eachtimetherunlevelischangedfrom1orSto another,rcrunsalso/etc/init.d/boot.setup:
(keyboard and virtual consoles setup)
5. ClosesLogfile/var/log/boot.msgandterminatesblogd
51_Boot_SequenceRun_Levels.sxw2
LinuxCourseBootRunlevelsLogin
4January2007
MichelBisson
6. Startsmingetty(ttycontroller) mingetty 1. DisplaysBanner:thecontentof/etc/issueor/etc/issue.net 2. Promptsforaloginnameandwaitsfortheusername 3. Startsthe/bin/logincommandwiththeusernameasargument. login 1. Reads/etc/login.defsand/etc/pam.d/login 2. AuthenticatestheuserusingPAM, PAM uses/etc/passwdand/etc/shadoworanothermethod. 3. SetsHOME, PATH, SHELL, TERM, MAIL, &LOGNAMEenv.var. 4. Read/etc/passwd to know which shell to start.(eg./bin/bash) bash 1. Displaysthecontentof/etc/motd 2.Reads/etc/profile Reads/etc/profile.local(SuSEonly,ifitexists) Reads/etc/bash.bashrc(SuSEonly,ifitexists) 3. Reads~/.bash_profileifitexists. if~/.bash_profile doesn't exist then Reads ~/.bash_login if~/.bash_login doesn't exist then Reads ~/.profile whichreads~/.aliasifitexists(SuSE) 4. Presentspromptandwaitsforusercommands.
LinuxRunLevels
Shuttingdownthesystem halt Usesshutdownhtoshutdown haltf Forcesahaltimmediatelywithoutcallingshutdown reboot Usesshutdownrtorebootthesystem rebootf Forcesarebootimmediatelywithoutcallingshutdown poweroff Useshaltp(powersoffthePC) shutdownh Usesinit0toshutdown shutdownr Usesinit6toreboot shutdownf - Reboot fast. Creates the file /fastboot to bypass fsck on reboot shutdownF - Force full fsck filesystem check on reboot. Creates the file /forcefsck to force fsck on reboot shutdownc - Cancel an already launched shutdown command shutdowna - Checks if one of the users in /etc/shutdown.allow is logged in in one of the 6 virtual consoles and proceed if so. shutdown.allow format is one name per line. Maximum 32 users.
51_Boot_SequenceRun_Levels.sxw3
LinuxCourseBootRunlevelsLogin
4January2007
MichelBisson
shutdownt105mThesystemisshuttingdownin5Min. The system send the message The system is ..... to logged in users - wait 5 minutes(5m) - then send the TERM signal to all processes - waits 10 seconds(t10) - then send the KILL signal to processes - then call init1(this is the default if r or h is not used)
Filesinvolved
/sbin/init Fatherofallprocesses /etc/inittab Configurationfileofinit /etc/init.d/rc Mainrunlevelcontrolscript /etc/init.d/yyyyyyy RunlevelsScripts /etc/init.d/rcx.d/Sxxyyyyyyy StartLinkstoRunlevelsScripts /etc/init.d/rcx.d/Kxxyyyyyyy StopLinkstoRunlevelsScripts /usr/sbin/mingetty ttycontrollerthatstartslogin /etc/issueand/etc/issue.net bannershownbeforeloginprompt. issue.netisfortelnetsessions /dev/console Defaultsystemconsole /var/run/utmp (binarylogfileofinitchildrenprocessbornanddied) /var/log/wtmp (binarylogfileofinitchildrenprocessbornanddiedand whyaswellasalllogins,logoutsandshutdowns) /dev/initctl (initcontrolfifo)
Thepurposeof/etc/init.d/rcx.ddirectoriesfordefaultrunlevel Scriptsrunningwithstartandstopparameters Toprovokeinittoreadagainitsconfigurationfile/etc/inittab: initq or telinitQ or telinitq Tocreate/deleterunlevelservicessymboliclinksautomatically: (SuSE8.0andhigheronly) chkconfigsservicenameon|off or insservservicename (installslinksforbootstart/stopofservice) insservrservicename (deleteslinksforbootstart/stopofservice) (servicename=scriptfilenamein/etc/init.d/directory)
51_Boot_SequenceRun_Levels.sxw4
LinuxCourseBootRunlevelsLogin
4January2007
MichelBisson
The/etc/inittabfileformat:
Eachentryin/etc/inittabismadeof4fields: 1)id idisauniquesequenceof14characterswhichidentifiesanentryininittab (forversionsofsysvinitcompiledwithlibraries<5.2.18ora.out librariesthelimitis2characters). Note:Forgettysorotherloginprocesses,theidfieldshouldbethettysuffix ofthecorrespondingtty,e.g.1fortty1.Otherwise,theloginaccounting mightnotworkcorrectly. 2)runlevels liststherunlevelsforwhichthespecifiedactionshouldbetaken. Therunlevelsfieldmaycontainmultiplecharactersfordifferentrunlevels. Forexample: 123specifiesthattheprocessshouldbestartedinrunlevels1,2,and3. TherunlevelsforondemandentriesmaycontainanA,B,orC. Therunlevelsfieldofsysinit,boot,andbootwaitentriesareignored. Whenthesystemrunlevelischanged,anyrunningprocessesthatarenot specifiedforthenewrunlevelarekilled,firstwithSIGTERM,thenwithSIGKILL. 3)action actiondescribeswhichactionshouldbetaken.(seelistofactionsbelow) 4)process Specifiestheprocesstobeexecuted.Iftheprocessfieldstartswitha`+ character,initwillnotdoutmpandwtmpaccountingforthatprocess. Thisisneededforgettysthatinsistondoingtheirownutmp/wtmphouse keeping.Thisisalsoahistoricbug.
51_Boot_SequenceRun_Levels.sxw5
LinuxCourseBootRunlevelsLogin
4January2007
MichelBisson
Actions(field3in/etc/inittab)
respawn wait once boot bootwait off ondemand Theprocesswillberestartedwheneveritterminates(e.g.getty). Theprocesswillbestartedoncewhenthespecifiedrunlevelisenteredand initwillwaitforitstermination. Theprocesswillbeexecutedoncewhenthespecifiedrunlevelisentered. Theprocesswillbeexecutedduringsystemboot.Therunlevelsfieldisignored. Theprocesswillbeexecutedduringsystemboot,whileinitwaitsforits termination(e.g./etc/rc).Therunlevelsfieldisignored. Thisdoesnothing. Aprocessmarkedwithanondemandrunlevelwillbeexecutedwheneverthe specifiedondemandrunleveliscalled.However,norunlevelchangewill occur(ondemandrunlevelsare`a',`b',and`c').
initdefaultAninitdefaultentryspecifiestherunlevelwhichshouldbeenteredafter systemboot.Ifnoneexists,initwillaskforarunlevelontheconsole. Theprocessfieldisignored. sysinit powerwait powerfail Theprocesswillbeexecutedduringsystemboot.Itwillbeexecutedbefore anybootorbootwaitentries.Therunlevelsfieldisignored. Theprocesswillbeexecutedwhenthepowergoesdown.Initisusually informedaboutthisbyaprocesstalkingtoaUPSconnectedtothecomputer. Initwillwaitfortheprocesstofinishbeforecontinuing. Asforpowerwait,exceptthatinitdoesnotwaitfortheprocess'scompletion.
powerokwaitThisprocesswillbeexecutedassoonasinitisinformormedthatthepower hasbeenrestored. powerfailnowThisprocesswillbeexecutedwheninitistoldthatthebatteryofthe externalUPSisalmostemptyandthepowerisfailing(providedthatthe externalUPSandthemonitoringprocessareabletodetectthiscondition). resume ctrlaltdel kbrequest ThisprocesswillbeexecutedwheninitistoldbythekernelthatSoftware Suspendhasresumedthemachine.Thiswayyoumayspecifyuserlandprograms whatcanrestorehardwarestatesthekernelcannot(forexamplesvgatextmode andhdparm). TheprocesswillbeexecutedwheninitreceivestheSIGINTsignal.This meansthatsomeoneonthesystemconsolehaspressedtheCTRLALTDELkey combination.Typicallyonewantstoexecutesomesortofshutdowneitherto getintosingleuserlevelortorebootthemachine. Theprocesswillbeexecutedwheninitreceivesasignalfromthekeyboard handlerthataspecialkeycombinationwaspressedontheconsolekeyboard. Thedocumentationforthisfunctionisnotcompleteyet;moredocumentation canbefoundinthekbdx.xxpackages(mostrecentwaskbd0.94atthetime ofthiswriting).Basicallyyouwanttomapsomekeyboardcombinationtothe "KeyboardSignal"action.Forexample,tomapAltUparrowforthispurpose usethefollowinginyourkeymapsfile:altkeycode103=KeyboardSignal
51_Boot_SequenceRun_Levels.sxw6
LinuxCourseBootRunlevelsLogin
4January2007
MichelBisson
AusschnittausderDatei/etc/inittab:
id:3:initdefault: si:I:bootwait:/sbin/init.d/boot #runlevel0ishalt #runlevelSissingleuser #runlevel1issingleuser #runlevel2ismultiuserwithoutnetwork #runlevel3ismultiuserwithnetwork #runlevel5ismultiuserwithnetworkandxdm #runlevel6isreboot l0:0:wait:/sbin/init.d/rc0 l1:1:wait:/sbin/init.d/rc1 l2:2:wait:/sbin/init.d/rc2 ca::ctrlaltdel:/sbin/shutdownrt4now 1:123:respawn:/sbin/mingettynocleartty1 2:123:respawn:/sbin/mingettytty2 Modus Bedeutung initdefault LegtfestwelcheArbeitsstufebeimSystemstartangesteuertwird bootwait WirdnurbeimSystemstartausgefhrt.EswirdbiszumEndeder Ausfhrunggewartet(synchron) wait EswirdbiszumEndederAusfhrunggewartet(synchron) ctraltdel respawn boot powerfail sysinit ondemand BestimmtwasmitdieserTastenkombinationpassierensoll Wennnichtschonexistent,wirdeinKindprozeerzeugt(asynchron). Sobalderbeendetist,wirdeinneuergestartet(spawned) Ersteprocessgestartedwann/etc/inittabistgelesen WaspassiertewannStrumabgebrochenist Theprocesswillbeexecutedduringsystemboot.Itwillbeexecuted beforeanybootorbootwaitentries.Therunlevelsfieldisignored. Aprocessmarkedwithanondemandrunlevelwillbeexecuted wheneverthespecifiedondemandrunleveliscalled.However,no runlevelchangewilloccur(ondemandrunlevelsare`a',`b',and`c'). Thisdoesnothing. Theprocesswillbeexecutedoncewhenthespecifiedrunlevelis entered. Theprocesswillbeexecutedwhenthepowergoesdown.initis usuallyinformedaboutthisbyaprocesstalkingtoaUPSconnectedto thecomputer.initwillwaitfortheprocesstofinishbeforecontinuing.
51_Boot_SequenceRun_Levels.sxw7