Download presentation
Presentation is loading. Please wait.
1
Zagon in zaustavitev računalnika
2
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.
3
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 – Boot 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).
4
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.
5
BIOS Info 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.
6
Interakcija BIOS
7
BIOS Setup
8
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.
9
POST Preveri prisotnost pričakovanih naprav
(le osnovno delovanje, avtomatsko preverjanje)
10
Zagonski postopek (boot procedure)
11
Bootstrap Loader
12
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…
13
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
14
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?
15
Bootstrap Loader (Bootloader)
Program, ki naloži “prvi program” Pogosto “večstopenjski”: primarni, sekundarni Terja podporo firmware (“hardware bootstrap”) PROM (firmware) Pomnilnik bootloader CPE Boot device? Floppy Primarni Primarni Jedro (kernel) Jedro (kernel) CD ROM Sekundarni Sekundarni mreža
16
Zagon PC Intel X86 firmware naloži “boot sector” na 0x7C00 in nanj prenese nadzor v realnem režimu (limita 640K ) pomnilnik Power On Self Test (POST) Proženje INT 19h (bootstrap) Izbira zagonske naprave (boot device) Nalaganje zagonskega sektorja (boot sector) floppy: prvi sektor trdi disk: MBR (mboot) ali “partition boot block” (pboot) Verifikacija “magic number” Izvajanje boot sektorja (primary bootloader) 0xc700 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) 0xfffffff0 BIOS_start 2GB
17
Naloge ob zagonu (nadaljevanje)
Ko najde zagonsko napravo, naloži BIOS njen zagonski sektor (boot sector) in ga sproži. V primeru trdega diska je to na MBR ( master boot record ) in pogosto ni specifično za določen operacijski sistem. 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 (boot sector) 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). MBR Partition table Particija Particija Particija
18
Zagon z diska pri Windows 2000
19
Sekundarni zagonski nalagalnik
20
Sekundarni zagonski nalagalnik
Če ni aktivne particije ali če izbere particijo (lahko s pomočjo vnosa uporabnika), naloži njen zagonski sektor. Primeri sekundarnih zagonskih nalagalnikov: GRUB – GRand Unified Bootloader LILO – LInux LOader NTLDR – NT Loader Sekundarnim zagonskim nalagalnikom pravimo tudi zagonski upravniki (boot managers) MBR Partition table Partition Partition Partition Boot Superblock Free space Inodes Root dir. Files & block management directories
21
LILO: LInux LOader Prilagodljiv zagonski upravnik, ki omogoča:
Izbiro jeder Linux Nastavitev časovnih parametrov zagona Zagon jeder, ki niso Linux Nastavljanje konfiguracij Značilnosti: Leži v MBR ali zagonskem sektorju (boot sector) particije Ne ve nič o datotečnem sistemu LILO was developed by Almesberger as a way of adding flexibility to the boot process, primarily as a means for Linux to co-exist with DOS. There are literally dozens of boot “scenarios” that are possible with LILO.. LILO is the Intel boot manager. Different architectures have variants. MILO for Dec Alpha systems and SILO for SPARC systems are two notable family members. PowerPC platforms use BOOTX and YABOOT. Other, less popular, Intel boot loaders include: LOADLIN, BOOTLIN, SYSLINUX, etc. LILO comes with an extensive User’s Guide and a succinct but valuable Technical Overview. Both of these are available in the LILO distribution tarball. A key issue with boot loaders is whether they have knowledge of the filesystem structure. LILO does not and this explains the need for a “block map” and running the “map installer”. Adding knowledge of filesystem structure simplifies booting but significantly increases the size and complexity of the bootloader. In effect, it contains a minimal (“stand-alone”) filesystem implementation. Solaris OpenBoot uses secondary bootloaders that understand a filesystem (ufsboot, nfsboot). /sbin/lilo must ask the kernel to identify the disk blocks containing the kernel to load as well as other configuration and data blocks. LILO uses these low-level SHC (sector/head/cylinder) addresses to find relevant sectors without needing to “decode” the filesystem structure
22
Komponente LILO /sbin/lilo (“map installer”) /etc/lilo.conf
/boot/boot.b Konfiguracijska datoteka /boot/chain.b /boot/map /boot/vmlinuz The “map installer” is controlled by the text file lilo.conf which identifies the desired boot scenario and details available boot images. Rerun /sbin/lilo anytime boot-related files change! That includes lilo.conf, the kernel itself, the boot loaders, the disk partition structure, etc. Newer versions of LILO keep most files in /boot by default. Under RedHat 6.1 the compressed kernel image is called vmlinuz. The actual primary and secondary bootloaders (the “real” LILO) live in the file /boot/boot.b. You can generate your own if you are clever enough but most people use the supplied loaders. Certain boot scenarios require loading additional loaders (for example, to boot off a logical partition). LILO supports this via the concept of a “chain loader”. The default chain loader is available as /boot/chain.b. The file /boot/map contains the actual sector map with a variety of other information. See the Technical Overview for details. Finally, the /boot directory may also contain an initial ramdisk image (initrd) used during boot.
23
Primer konfiguracijske datoteke lilo.conf
boot=/dev/hda map=/boot/map install=/boot/boot.b prompt timeout=50 default=linux image=/boot/vmlinuz label=linux initrd=/boot/initrd img read-only root=/dev/hda1
24
Primer konfiguracijske datoteke grub.conf
default=0 timeout=10 splashimage=(hd1,2)/grub/splash.xpm.gz password --md5 $1$opeVt0$Y.br.18LyAasRsGdSKLYlp1 title Red Hat Linux password --md5 $1$0peVt0$Y.br.18LyAasRsGdSKLYlp1 root (hd1,2) kernel /vmlinuz ro root=LABEL=/ initrd /initrd img title Windows XP rootnoverify (hd0,0) chainloader +1
25
GRUB “Lupina za čas zaganjanja (Boot time shell)
GRUB interaktivni ukazi Sproti (on the fly) izvaja novo konfiguracijo Dinamično privzeto konfiguriranje Lahko zaganjamo druge OS
26
Primerjava LILO in GRUB
Tradicionalna Če zamenjamo “kernel” ali spremenimo zagonsko konfiguracijo, moramo reinstalirati v “master boot record” GRUB Nova Fleksibilna Interaktivni ukazi
27
Zagon z diska s pomočjo LILO
LILO izpisuje niz “LILO boot:” BIOS naloži zagonski sektor na 0x7c00 ter se sam prestavi na 0x9a00 Nastavi sklad naloži sekundarni nalagalnik na 0x9b00 Nadzor prevzame sekundarni nalagalnik naloži “block map” na0x9d200 Izpiše komandno vrstico In čaka na vnos uporabnika ali iztek časa “timeout” On a modern PC this all happens in the blink of an eye so it loses a bit of its excitement but it’s good to know about when something breaks in the middle of the boot process. A two-digit error code is printed after the first L if a media failure or geometry error has occurred. If only LI is printed, there might be a problem with /boot/boot.b. If only LIL is printed or LIL? or LIL- then there was a problem loading and decoding the map file.
28
LINUX: od zagona do zaustavitve
29
Življenski cikel sistema: gor in dol
Zagon (Booting) Inicializacija jedra (Kernel Initialization) Prvi proces: init 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.
30
LINUX: od zagona do zaustavitve
31
Inicializacija jedra Preveri sistemske naprave
Identifikacija specifičnih naprav Jedro (Kernel) Zagotavlja, da bo strojna oprema delala to, kar hočejo programi
32
Inicializacija jedra Preskus bistvenih naprav
CPE, konzola, pomnilnik Preskus strojnih podsistemov I/O vodila, omrežni vmesniki, trdi diski, CD-ROM pogoni, disketni pogoni, pomnilne naprave
33
Inicializacija jedra Inicializacija datotečnega sistema
Logical volume manager subsystem RAID SCSI naprave Particije na trdem disku Spreminjanje konfiguracije jedra /usr/src/linux/make menuconfig or xconfig rdev Boot loader parameter
34
LINUX: od zagona do zaustavitve
35
Zaporedje procesov, ki zaživijo pri zagonu nekaterih sistemov
Zagon UNIX (Linux) cp Zaporedje procesov, ki zaživijo pri zagonu nekaterih sistemov
36
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.
37
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)
38
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
39
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
40
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)
41
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.
42
Primer iniciacijskega skripta
43
Init Lokacija: /sbin/init Uporablja funkcije iz knjižnjic v jeziku C
Preveri in montira datotečni sistem Požene demone za beleženje sistemskih obvestil Požene procese getty, ki na virtualne terminale izpišejo najavko login Omreženje Strežniki WEB strani Poslušanje miši
44
Spreminjanje nivojev izvajanja
Naslednji ukazi so tipično rezervirani spreminjanje nivojev: UNIX: Ukazi shutown, telinit oz. init Windows: Ukaz shutdown
45
Najava uporabnikov (login)
Ko je jedro naloženo, smo še v privilegiranem režimu. Če bi se sedaj lahko prijavili (login) kot uporabnik, bi imeli sistemske privilegije. Vendar program "login" po preverjanju gesla vrne lupino kot drug proces z nižjimi privilegiji. Jedro procesu "login" zaupa. Če bi ga nadomestili oziroma vanj vdrli, bi lahko dobili administratorsko lupino (root shell) za vsako prijavo.
46
Zaustavitev (shutdown)
Zapis “bufferjev”: da ne bi izgubili podatkov in okvarili datotečni sistem, uporabimo /bin/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.
47
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, da naj spremeni nivo izvajanja Privzeto: 1, -h flag 0, -r flag 6
48
Zaustavljanje Odmontiranje particije
Strukturne informacije datotečnega sistema Shutdown -F (fsck) “Journaling” datotečnega sistema shranjenje zapisa transakcij o spremembah datotečnega sistema Odgovor pri ponovnem zagonu sistema
49
Upravljanje s pomnilnikom
Halting in the idle process idle process executes hlt on Intel low-power consumption mode Suspending the system patches for suspending to disk APM: Advance Power Management laptop standard power management ACPI: Advanced Configuration and Power Interface new comprehensive standard from Intel-Microsoft Power-management is essential for mobile systems This is a big issue. Several years ago, before energy-saving mechanism were widely available, something like 12% of the US powergrid was used by idling computers! Energy-saving mechanisms sometimes end up fighting with each other and with screen-savers. There is a need for a coordinated standard. “Fast-booting” from a system image is an interesting technique significantly slows shutdown to allow writing the image. Making an OS “power consumption aware” requires rethinking the design of lots of subsystems: device-drivers, scheduling, etc. An OS kernel is a precarious balancing act between flexibility, performance, cost and reliability. Designers are preeminently concerned with performance and reliability but as power consumption becomes an increasingly important “cost”, design decisions must be reconsidered. See the Ecology-HOWTO for more details on “green” machines.
50
Dodatek Ali imam na sistemu tudi sekundarni zagonski nalagalnik, če imam en sam operacijski sistem ? Stari sistemi tega morda nimajo. Danes pa so celo Windows nameščeni s privzetim sekundarnim zagonskim nalagalnikom (NTLDR). Tudi Linux je običajno nameščen z LILO ali GRUB kot privzetim zagonskim nalagalnikom. Tako se nam lahko zgodi, da Windows ne moremo zagnati in se pojavi obvestilo “NTLDR missing”. To se zgodi, če primarni zagonski nalagalnik ne more prenesti nadzora na NTLDR, ki je morda pokvarjen ali pomotoma zbrisan.
51
Dodatek Kakšen je vpliv na zagonski sektor (boot sector) in zagonski nalagalnik (boot loader), ko namestimo dva operacijska sistema, na primer Windows in Linux , v dve ločeni particiji ? Predpostavimo, da smo najprej namestili Windows. Privzeti zagonski nalagalnik, nameščen v MBR, je NTLDR in vsebuje podatke o aktivni particiji z Windows. Ko na ta sistem namestimo še Linux, namestitev zahteva prekritje sekundarnega zagonskega nalagalnika, ki identificira aktivni particiji tako z Windows kot z Linux. To nam daje možnost izbire operacijskega sistema ob zagonu. Če pa smo najprej namestili Linux in šele nato Windows, bo “Windows Installer” prekril MBR s svojim lastnim zagonskim nalagalnikom, ki ne spozna aktivne particije Linux. To pa je problem, ki ga rešimo s ponovno namestitvijo sekundarnega nalagalnika, ki zna ugotoviti oba operacijska sistema in ponuditi izbiro. .
52
O tabeli particij When installing an OS on a computer from scratch, here is how the partition table is created. The hard disk is denoted as “hda” where hd=hard disk, and the third letter could mean the hard-disk on the system. For e.g. the first hard disk is “hda”, the second is “hdb”. When the partitioning is done, “hda0” is the place of MBR. “hda1” is the primary partition. Then a secondary partition may be created which is further subdivided into logical drives. Another OS could be installed on any of these logical drives. hda0 – MBR hda1 – Primary Partition e.g. Windows XP hda2 – Secondary Partition hda3 – Logical Drive 1 (FAT32 or NTFS partition) hda4 – Logical Drive 2 (FAT32 or NTFS partition) hda5 – Logical Drive 3 (Swap for Linux Partition) hda6 – Logical Drive 4 (Root for Linux Partition) The above example is a simple example. Specific cases can be different.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.