Download presentation
Presentation is loading. Please wait.
1
Zagon in zaustavitev računalnika
2
Zakaj je potreben zagon ?
Aparaturna oprema ne ve, kje leži operacijski sistem in kako naj ga naloži. Za to potrebujemo poseben program – “bootstrap loader”. Na primer: BIOS – Basic Input Output System. “Bootstrap loader” locira jedro (operacijskega sistema), ga naloži v pomnilnik in sproži njegovo izvajanje. V nekaterih primerih pa preprost “bootstrap loader” poišče na disku bolj kompleksen zagonski program, ga naloži v pomnilnik, ta pa nato naloži jedro (kernel).
3
Kako poteka zagon (boot) ?
Dogodek “reset” na CPE (vklop računalnika, ponovni zagon) povzroči, da se programski števec nastavi na preddoločeni naslov v pomnilniku. Sproži se program “Bootstrap” na tej lokaciji. Ta program je pomnjen v ROM, saj je pomnilnik RAM takrat v neznanem stanju. ROM je tako primeren za inicializacijo, nanj pa tudi ne vplivajo virusi.
4
BIOS BIOS na matični plošči. CMOS pomnilnik
pomni ključne začetne podatke CMOS Memory is battery-powered and holds key startup information including the date, time and system startup parameters. A flash memory BIOS differs from ROM BIOS in that they can changed. These changes might include better support for different types of hardware as well as to fix any sort of problems.
5
Interakcija BIOS
6
Naloge ob zagonu Diagnostika, ki določi stanje stroja. Če je diagnostika uspešna, se zagon nadaljuje. Izvedba “Power-On Self Test” (POST), ki preveri, ali naprave, ki sestavljajo računalnik, delujejo. BIOS gre preko predkonfiguriranih naprav in poišče tisto, ki je zagonska (bootable). Če take naprave ne najde, sledi obvestilo o napaki in zagon se zaustavi. Initializacija registrov CPE, krmilnikov naprav in vsebine pomnilnika. Zatem sledi nalaganje operacijskega sistema.
7
POST Preveri prisotnost pričakovanih naprav
(le osnovno delovanje, avtomatsko preverjanje)
8
Zagonski postopek (boot procedure)
9
BIOS Setup
10
Bootstrap Loader
11
Terminologija zagonskega mehanizma
Loader Naloži kodo (običajno) z diska v pomnilnik in sproži izvajanje te kode) Bootloader / Bootstrap Program, ki naloži “prvi program” (jedro oziroma kernel) Boot PROM / PROM Monitor / BIOS Fiksna koda, ki je ob vklopu računalnika “že naložena” Boot Manager Program, ki nam omogoča izbrati “prvi program”, ki naj bo naložen Loading is an important and often over-looked OS concept. Loading is increasingly accomplished “on-demand” via dynamic linking-loaders. The Linux kernel module mechanism is essentially an advanced application of dynamic linking/loading. People often mistakenly think that “bootstrap” refers to boot laces. The “bootstrap” metaphor refers to the nonsensical image of someone lifting themselves up off the ground by their own bootstrap. The impossibility of this image adds to the mystery of the boot process. There are lots of related types of “firmware”: ROM, PROM, EPROM, EEPROM, NVRAM, Flash RAM and who knows what else. PROM in “Boot PROM” or “PROM Monitor” is used informally. In the SPARC architecture, these are actually contained in EEPROMs. The phrase “first program” is in quotes for a reason. Often the first program loaded is itself a boot manager, like LILO. LILO introduces the concept of “chain loaders”. Why not have one loader load another loader which might load another loader…
12
Kaj je nalagalnik (loader)?
Program, ki kopira kodo (običajno z diska) v pomnilnik in sproži izvajanje te kode. Nalagalnik (loader) pomnilnik CPE A great reference is “Linkers & Loaders” by John Levine Morgan Kaufmann 2000. Loaders are also sometimes responsible for allocating memory, setting protection bits, updating memory maps, etc. disk Kopira kodo Sproži kodo koda koda
13
Kdo pa naloži nalagalnik?
Seveda je tudi nalagalnik le program, ki leži v pomnilniku. Kako pa je tja prišel? Potrebujemo “nalagalnik nalagalnika” … Pomnilnik Nalagalnik (loader) disk Executables are stored on disk (by compilers and assemblers) in specific formats. The original UNIX format was known as a.out (hence the default output filename for the C compiler). a.out was superceded by COFF and more recently by ELF (Executable and Linking Format). DOS has .COM and .EXE. Loaders usually only understand how to “interpret” and load files in a single format. Often an OS only allows a single executable format. Linux supports multiple executable formats. (In Linux lingo they are called “binfmts” for “binary formats”.) ELF is widely used. So, what exactly *is* the Linux (or UNIX) loader? Many people would say “ld” but ld is the “Link eDitor”. It’s a linker. Not a loader. Loading is accomplished in the UNIX-world indirectly via the exec family of system calls. exec essentially “overlays” the current process image with the specified executable image file. exec is a loader! We will see in later chapters that Linux goes even further in “hiding” the loader. Executables are typically “loaded” by just setting up the memory map with all pages initially marked “absent”. Virtual memory then “pages in” the executable image as needed. This is “lazy” or “on-demand” loading. In the above, cat is probably “loaded” by a fork/exec from the shell. The shell was started by login, which was started by getty, which was started by init. init is created by the kernel during kernel initialization. So how is the kernel loaded?
14
Bootstrap Loader (Bootloader)
Program, ki naloži “prvi program” Pogosto “večstopenjski”: primarni, sekundarni Terja podporo firmware (“hardware bootstrap”) ROM (BIOS) (firmware) Pomnilnik bootloader CPE Boot device? Floppy Primarni Primarni Jedro (kernel) Jedro (kernel) CD ROM Sekundarni Sekundarni mreža
15
Zagon PC Intel X86-32 firmware naloži “boot sector” na 0x7C00 in nanj prenese nadzor v realnem režimu (limita 640K ) Power On Self Test (POST) Izbira zagonske naprave (boot device) Nalaganje zagonskega sektorja (boot sector) floppy: (prvi sektor) trdi disk: MBR (sektor 0) ali “partition boot block” (pboot) Zagon naložene kode - first stage boot loader Izbor particije iz tabele particij Izvajanje boot sektorja particije – second stage boot loader pomnilnik 0x7C00 boot sektor CPE When you power-on the Intel, it reads a “start address” from location 0xfffffff0 and jumps to that location. In the standard PC configuration, this address is the BIOS entry point. Strangely, the location 0xfffffff0 is also part of BIOS (the high 64K of memory). This indirect mechanism allows Intel chips to be used in non-PC settings. Everything happens in real-mode so some memory mapping tricks are used to make the high BIOS addresses reachable in real-mode. After executing the POST, BIOS enters the bootstrap interrupt handler and tries to load a boot sector using the BIOS-defined order. For a floppy, BIOS always loads the first sector. For a hard disk, the first sector which is a Master Boot Record (MBR or mboot) containing some code and a partition table are loaded. The loaded code searches the partition table for the active (bootable) partition. If the MBR is from the active partition we are done. If the active partition is some other partition, the MBR code loads the boot sector of that partition. This is sometimes referred to as a partition boot sector or pboot. There are further complications for extended and logical partitions. Eventually the “correct” boot sector is loaded. Each boot sector contains a “magic number” to verify that it is, indeed, a boot sector. If the magic number is verified, then the boot sector code is executed. BIOS (64K) 0xFFFF0000 BIOS_start 2GB
16
Naloge ob zagonu (nadaljevanje)
Ko najde zagonsko napravo, naloži BIOS njen zagonski sektor (boot sector) in ga sproži. To je first stage boot loader V primeru trdega diska je to MBR ( master boot record – sektor 0) (tipično ni specifičen za določen operacijski sistem). MBR na x86 platformi je omejen na 512 bytov, skupaj s tabelo particij, kar omeji velikost kode boot sektorja na 446 bytov! 512 bytov
17
Naloge ob zagonu (nadaljevanje)
Koda MBR preveri tabelo particij (partition table) in išče v njej aktivno particijo. Če jo najde, naloži koda MBR zagonski sektor (boot sector) te particije in sproži njegovo izvajanje Zagonski sektor particije (VBR – volume boot record) je pogosto specifičen za dani operacijski sistem. V mnogih operacijskih sistemih je glavna naloga kode zagonskega sektorja nalaganje in proženje jedra (kernel), ki nato nadaljuje zagonske postopke (startup). Namesto jedra, se lahko v VBR nahaja tudi sekundarni zagonski nalagalnik – second stage boot loader
18
Sekundarni zagonski nalagalnik
19
Sekundarni zagonski nalagalnik
V zagonskem sektorju particije (VBR) se lahko nahaja tudi sekundarni nalagalnik, npr: GRUB – GRand Unified Bootloader LILO – LInux LOader NTLDR – NT Loader Sekundarnim zagonskim nalagalnikom pravimo tudi zagonski upravniki (boot managers) Njihova naloga je, da (interaktivno) omogočijo izbiro particije iz katere naj se nalaganje nadaljuje posledično omogočajo nalaganje različnih OS
20
GRUB Prilagodljiv zagonski upravnik, ki omogoča: Značilnosti:
Izbiro jeder Linux Nastavitev časovnih parametrov zagona Zagon jeder, ki niso Linux Nastavljanje konfiguracij, tudi interaktivno ob zagonu Značilnosti: Prva faza GRUB leži v MBR Ne ve nič o datotečnem sistemu Ta faza naloži drugo fazo (sekundarni nalagalnik) GRUB 2, ki se lahko nahaja drugje na disku ali pa vmesno fazo 1.5, ki potem naloži GRUB 2 GRUB 2 prikaže upor. vmesnik z izbiro OSa
21
GRUB Konfiguracija: grub se nahaja v datotekah: /boot/grub/stage1 in /boot/grub/stage2 konfiguracijska datoteka: /boot/grub/grub.conf. default=0 timeout=10 splashimage=(hd1,2)/grub/splash.xpm.gz title Pingo root (hd1,2) kernel /vmlinuz ro root=LABEL=/ initrd /initrd img title Windows XP rootnoverify (hd0,0) chainloader +1
22
Faze nalaganja GRUB BIOS prebere MBR z diska
Izvede naloženo kodo (grub faza 1). Koda ve, kje na disku se nahaja naslednja faza (1.5 ali 2), jo naloži in jo izvede Če je to faza 1.5, ta pozna datotečni sistem particije, ga odpre in poišče datoteko s fazo 2 ter jo naloži in požene Faza 2 vsebuje večino logike gruba. Prebere konfiguracijsko datoteko grub.conf, pokaže uporabniški vmesnik in po izbiri nadaljuje z nalaganjem jedra
23
NTLDR Nalagalnik Windows (NT,2000,XP,2003) Koraki pri nalaganju
omogoča tudi nalaganje drugih OS Nahaja se v datotekah boot.ini in NTLDR, ki morata biti na sistemskem disku (C:). Koraki pri nalaganju BIOS prebere MBR z diska MBR naloži sekundarni nalagalnik NTLDR iz VBR NTLDR dostopi do datotečnega sistema (FAT ali NTFS) Če najde hiberfil.sys, pomeni, da je računalnik hiberniral in naloži hibernirano sliko Drugače prebere boot.ini in uporabniku predstavi upor. vmesnik za izbiro OSa
24
Življenski cikel sistema: gor in dol
Zagon (Booting) Inicializacija jedra (Kernel Initialization) Prvi proces: init Izvajanje Zaustavitev sistema (shutdown) start_kernel Vklop Izklop Boot Kernel Init OS Init izvajanje Shut down init shutdown LILO sleep? (hlt) Much of this chapter is devoted to details of booting which can be quite complex. Reviewing the details helps to dispel some of the mystery surrounding the process and provides an appreciation for the complex hardware, firmware, software coordination required. We spend time looking at the standard Intel boot manager LILO as well as introducing the Skiff bootloader. Kernel initialization is staged. Low-level, device-dependent initialization finally yields to high-level, device-independent initialization. Each category has initialization dependencies. Certain things must be done before other things.Each logical Linux subsystem has one or more _init() functions that are called during this process. Processes 0 and 1 are discussed. Process 1 (init) is responsible for all user-level process creation. Shutdown is also staged but not as complex as startup. /sbin/shutdown and init cooperate to bring the system down gently. Linux enthusiasts continue to stretch the bounds. We review some creative thinking about the boot process. Power management is an increasingly important OS responsibility and part of the system lifecycle.
25
LINUX: od zagona do zaustavitve
26
Inicializacija jedra Po nalaganju se dejanski zagon sistema začne z inicializacijo jedra Jedro preveri sistemske naprave Preskus bistvenih naprav CPE, konzola, pomnilnik Preskus strojnih podsistemov I/O vodila, omrežni vmesniki, trdi diski, CD-ROM pogoni, disketni pogoni, pomnilne naprave Jedro (Kernel) Zagotavlja, da bo strojna oprema delala to, kar hočejo programi
27
Inicializacija jedra Inicializacija datotečnega sistema
Logical volume manager subsystem RAID SCSI naprave Particije na trdem disku
28
Natačna sekvenca začetka postavljanja Linuxa
Grub (ali kak drug nalagalnik) zažene jedro, ki se nahaja v pomnilniku sporoči mu podatke o drugih delih OS, ki se tudi nahajajo v pomnilniku (ramdisk) Jedro izvede inicializacijo Preko datoteke /linuxrc najde lokacijo pravega datotečnega sistema, ter ga pripne (mount) Nalaganje se nadaljuje preko akcij procesa init, ki se požene v uporabniškem načinu (user mode)
29
LINUX: od zagona do zaustavitve
30
Zaporedje procesov, ki zaživijo pri zagonu nekaterih sistemov
Zagon UNIX (Linux) cp Zaporedje procesov, ki zaživijo pri zagonu nekaterih sistemov
31
init() init() začne življenje kot nit jedra in konča kot proces na uporabniškem nivoju (/sbin/init) init/main.c:init acquire “the big kernel lock” on a multiprocessor (MP) perform high-level initialization – do_basic_setup() free __init memory release lock try to exec (in user space) the init process panic if unsuccessful We are now running concurrently with idle. (Actually idle runs until it is rescheduled by a timer interrupt. The scheduler notices that init wants to run and lets it.) So grab the “big kernel lock”. This is a no-op on a uniprocessor. It is important to identify “lock points” even in uniprocessor code but conditional compilation avoids any extra overhead. Call do_basic_setup() for some “real work” as the comment says. Release memory used by init code and data. Release lock. Try to exec /sbin/init, passing appropriate parameters. exec will setup a process image in user space so this is a transition from kernel to user space. init() looks in several places if exec fails. In desperation it tries to exec a shell. If that fails it calls panic() which halts the system with extreme prejudice. /sbin/init doesn’t really need stdin or stdout but we set them up in case we exec a shell or a user-specified init replacement.
32
Init? Init je predhodnik vseh procesov (vendar brezposeln) “seje” otroke Lokacija: /sbin/init Teče v uporabniškem načinu (user mode) (do jedra dostopa preko sistemskih klicev)
33
Kaj naredi Init ob zagonu?
Pregleda datoteko /etc/inittab Preko nje glede na nivo izvajanja požene skripte, ki se nahajajo v datotekah v imeniku /etc/rc.d servisi za beleženje sistemskih obvestil vzpostavitev mreže mrežni strežniki (splet, pošta...) ... Požene procese, ki omogočijo prijavo na sistem na tekstovnih terminalih lahko tudi grafični uporabniški vmesnik
34
Nivoji izvajanja UNIX Run Levels – nivoji izvajanja
pove na kakšnem nivoju (načinu) je sistem single user (vzdrževanje) in multi-user (brez in z omrežnimi servisi) parameter pri poganjanju procesa init pove v kakšen način naj se računalnik postavi Tudi Windows imajo nivoje: Multi-user Safe Mode Safe mode with networking
35
Nivoji izvajanja v init
0: Ustavljen sistem (pripravljen na izklop) 1: Enouporabniški režim 2: Večuporabniški režim brez mrežnih datotečnih sistemov 3: Večuporabniški režim z mrežo 4: navadno ni v uporabi 5: Večuporabniški sistem z GUI 6: Reboot režim S,s: Single user mode (brez /etc/inittab)
36
Init Katere servise init zaganja in njihov vrstni red glede na nivo izvajanja določa datoteka /etc/inittab programi v lupini (skripte) v imenikih /etc/rc.d, ki so urejeni po nivojih izvajanja Ena od prednosti uporabe skript pri zagonu je, da jih lahko preverjamo in spreminjamo skripte lahko ročno pokličemo z argumenti stop in start in preverjamo, ali delujejo pravilno tak postopek je priporočljiv, saj lahko odkrijemo napake, ki bi prekinile zagon in povzročile, da bi bil sistem neuporaben.
37
Primer iniciacijskega skripta
38
Spreminjanje nivojev izvajanja
Naslednji ukazi so tipično rezervirani spreminjanje nivojev: UNIX: Ukazi shutown, telinit oz. init Windows: Ukaz shutdown
39
Zaustavitev (shutdown)
Zapis “bufferjev”: da ne bi izgubili podatkov in okvarili datotečni sistem, uporabimo shutdown shutdown onemogoči logiranje, zahteva od “init”, da pošlje vsem procesom signale SIGTERM in SIGKILL (jih torej konča). Buffered writes are not the only reason why “pulling the plug” is a bad way to shut down a Linux system. “Graceful termination” is important for all sorts of “transaction oriented” activities. Buffered writes are “flushed” via the “sync” command. Old UNIX lore has it that a system admin should type sync three times in rapid succession and then pray before shutdown. Actually the non-deterministic nature of disk access makes it impossible to *guarantee* that all writes have been flushed but it works almost all the time. The kernel demon responsible for periodically flushing write buffers is bdflush. It interacts with a user space demon that is controlled by /sbin/update. The low-level halt and reboot commands are now smarter than they used to be. If you are not in runlevel 0 or 6, they will call shutdown for you to keep your from coming to harm.
40
Zaporedje zaustavitve
Shutdown [-h/r] Blokirano je ponovno prijavljanje Vsem procesom pošljemo signal SIGTERM in jim tako povemo, da se sistem ugaša Procesi se čisto zaključijo Procesu init poščjemo signal, d naj spremeni nivo izvajanja Privzeto: 1, -h flag 0, -r flag 6 Odmontiranje particije
41
Kaj mora administrator razumeti?
Zaporedje dogodkov pri zagonu sistema. Metode, ki jih uporabimo za spreminjanje zagonskega zaporedja. Kako izbiramo alternativne zagonske naprave. Delovanje programov “boot manager” in “boot loader”. Kako pravilno zaustavimo sistem.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.