这是用户在 2024-10-23 20:43 为 https://tldp.org/HOWTO/Unix-and-Internet-Fundamentals-HOWTO/bootup.html 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?

3. What happens when you switch/swɪtʃ/ on a computer?

A computer without a program running is just an inert hunk of electronics/ɪˌlekˈtrɑːnɪks/. The first thing a computer has to do when it is turned on is start up a special program called an operating system. The operating/ˈɑːpəreɪtɪŋ/ system/ˈsɪstəm/'s job is to help other computer programs to work by handling/ˈhændlɪŋ/ the messy/ˈmesi/ details/ˈdiːteɪlz/ of controlling/kənˈtrəʊlɪŋ/ the computer's hardware/ˈhɑːrdwer/.

The process/ˈprɑːses/ of bringing up the operating/ˈɑːpəreɪtɪŋ/ system/ˈsɪstəm/ is called booting (originally/əˈrɪdʒənəli/ this was bootstrapping and alluded to the process/ˈprɑːses/ of pulling yourself up "by your bootstraps"). Your computer knows how to boot because instructionsɪnstrˈʌkʃənz for booting are built into one of its chips/tʃɪps/, the BIOS (or Basic/ˈbeɪsɪk/ Input/ˈɪnpʊt//Output/ˈaʊtpʊt/ System/ˈsɪstəm/) chip/tʃɪp/.

The BIOS chip/tʃɪp/ tells it to look in a fixed/fɪkst/ place, usually on the lowest-numbered hard disk/dɪsk/ (the boot disk) for a special program called a boot loader (under Linux the boot loader is called Grub or LILO). The boot loader is pulled into memory and started. The boot loader's job is to start the real operating/ˈɑːpəreɪtɪŋ/ system/ˈsɪstəm/.

The loader does this by looking for a kernel, loading/ˈləʊdɪŋ/ it into memory, and starting it. If you Linux and see "LILO" on the screen followed by a bunch/bʌntʃ/ of dots/dɑːts/, it is loading/ˈləʊdɪŋ/ the kernel. (Each dot/dɑːt/ means/miːnz/ it has loaded/ˈləʊdɪd/ another disk block of kernel code/kəʊd/.)

(You may wonder/ˈwʌndər/ why the BIOS doesn't load/ləʊd/ the kernel directly/dəˈrektli/ — why the two-step/step/ process/ˈprɑːses/ with the boot loader? Well, the BIOS isn't very smart/smɑːrt/. In fact it's very stupid/ˈstuːpɪd/, and Linux doesn't use it at all after boot time. It was originally/əˈrɪdʒənəli/ written/ˈrɪtn/ for primitive/ˈprɪmətɪv/ 8-bit/bɪt/ PCs with tiny/ˈtaɪni/ disksdˈɪsks, and literally/ˈlɪtərəli/ can't access/ˈækses/ enough of the disk/dɪsk/ to load/ləʊd/ the kernel directly/dəˈrektli/. The boot loader step/step/ also lets/lets/ you start one of several operating/ˈɑːpəreɪtɪŋ/ systemssˈɪstəmz off different places on your disk/dɪsk/, in the unlikely/ʌnˈlaɪkli/ event/ɪˈvent/ that Unix isn't good enough for you.)

Once the kernel starts, it has to look around, find the rest of the hardware/ˈhɑːrdwer/, and get ready to run programs. It does this by poking not at ordinary/ˈɔːrdneri/ memory locationsloʊkˈeɪʃənz but rather/ˈræðər/ at I/O ports — special bus addresses that are likely/ˈlaɪkli/ to have device/dɪˈvaɪs/ controller cards listening at them for commands/kəˈmændz/. The kernel doesn't poke at random/ˈrændəm/; it has a lot of built-in knowledge/ˈnɑːlɪdʒ/ about what it's likely/ˈlaɪkli/ to find where, and how controllers will respond/rɪˈspɑːnd/ if they're present. This process/ˈprɑːses/ is called autoprobing.

You may or may not be able/ˈeɪbl/ to see any of this going on. Back when Unix systemssˈɪstəmz used/juːzd/ text consoles, you'd see boot messages scroll by on your screen as the system/ˈsɪstəm/ started up. Nowawadays, Unixes often hide/haɪd/ the boot messages behind a graphical splash/splæʃ/ screen. You may be able/ˈeɪbl/ to see them by switching/ˈswɪtʃɪŋ/ to a text console view with the key combination/ˌkɑːmbɪˈneɪʃn/ Ctrl-Shift/ʃɪft/-F1. If this works, you should be able/ˈeɪbl/ to switch/swɪtʃ/ back to the graphical boot screen with a different Ctrl-Shift/ʃɪft/ sequence/ˈsiːkwəns/; try F7, F8, and F9.

Most of the messages emitted/iˈmɪtɪd/ boot time are the kernel autoprobing your hardware/ˈhɑːrdwer/ through the I/O ports/pɔːrts/, figuring/ˈfɪɡjərɪŋ/ out what it has available to it and adapting/əˈdæptɪŋ/ itself to your machine/məˈʃiːn/. The Linux kernel is extremely/ɪkˈstriːmli/ good at this, better than most other Unixes and much better than DOS or Windows. In fact, many Linux old-timers think the cleverness of Linux's boot-time probes (which made it relatively easy to install/ɪnˈstɔːl/) was a major/ˈmeɪdʒər/ reason it broke out of the pack of free-Unix experiments/ɪkˈsperɪments/ to attract/əˈtrækt/ a critical/ˈkrɪtɪkl/ mass/mæs/ of usersjˈuːzəz.

But getting the kernel fully/ˈfʊli/ loaded/ˈləʊdɪd/ and running isn't the end of the boot process/ˈprɑːses/; it's just the first stage (sometimes called run level 1). After this first stage, the kernel hands control/kənˈtrəʊl/ to a special process/ˈprɑːses/ called ‘init’ which spawns several housekeeping processes/ˈprɑːsesɪz/. (Some recent/ˈriːsnt/ Linuxes use a different program called ‘upstart’ that does similar/ˈsɪmələr/ things)

The init process/ˈprɑːses/'s first job is usually to check to make sure your disksdˈɪsks are OK. Disk/dɪsk/ file systemssˈɪstəmz are fragile/ˈfrædʒl/ things; if they've been damaged/ˈdæmɪdʒd/ by a hardware/ˈhɑːrdwer/ failure/ˈfeɪljər/ or a sudden/ˈsʌdn/ power/ˈpaʊər/ outage, there are good reasons to take recovery/rɪˈkʌvəri/ steps/steps/ before your Unix is all the way up. We'll go into some of this later on when we talk about how file systemssˈɪstəmz can go wrong/rɔːŋ/.

Init's next step/step/ is to start several daemons. A daemon is a program like a print spooler, a mail listener/ˈlɪsənər/ or a WWW server/ˈsɜːrvər/ that lurks in the background/ˈbækɡraʊnd/, waiting for things to do. These special programs often have to coordinate several requests/rɪˈkwests/ that could conflict/ˈkɑːnflɪkt/. They are daemons because it's often easier to write one program that runs constantly/ˈkɑːnstəntli/ and knows about all requests/rɪˈkwests/ than it would/wəd/ be to try to make sure that a flock of copies (each processing/ˈprɑːsesɪŋ/ one request/rɪˈkwest/ and all running at the same time) don't step/step/ on each other. The particular/pərˈtɪkjələr/ collection/kəˈlekʃn/ of daemons your system/ˈsɪstəm/ starts may vary/ˈveri/, but will almost always include a print spooler (a gatekeeper daemon for your printer).

The next step/step/ is to prepare for usersjˈuːzəz. Init starts a copy of a program called getty to watch your screen and keyboard (and maybe more copies to watch dial/ˈdaɪəl/-in serial/ˈsɪriəl/ ports/pɔːrts/). Actually/ˈæktʃuəli/, nowadays/ˈnaʊədeɪz/ it usually starts multiple/ˈmʌltɪpl/ copies of getty so you have several (usually 7 or 8) virtual/ˈvɜːrtʃuəl/ consoles, with your screen and keyboards connected/kəˈnektɪd/ to one of them at a time. But you likely/ˈlaɪkli/ won't see any of these, because one of your consoles will be taken over by the X server/ˈsɜːrvər/ (about which more in a bit/bɪt/).

We're not done yet. The next step/step/ is to start up various daemons that support/səˈpɔːrt/ networking/ˈnetwɜːrkɪŋ/ and other services/ˈsɜːrvɪsɪz/. The most important of these is your X server/ˈsɜːrvər/. X is a daemon that manages/ˈmænɪdʒɪz/ your display/dɪˈspleɪ/, keyboard, and mouse. Its main/meɪn/ job is to produce/prəˈduːs/ the color pixel graphics/ˈɡræfɪks/ you normally/ˈnɔːrməli/ see on your screen.

When the X server/ˈsɜːrvər/ comes up, during the last part of your machine/məˈʃiːn/'s boot process/ˈprɑːses/, it effectively/ɪˈfektɪvli/ takes over the hardware/ˈhɑːrdwer/ from whatever/wətˈevər/ virtual/ˈvɜːrtʃuəl/ console was previously/ˈpriːviəsli/ in control/kənˈtrəʊl/. That's when you'll see a graphical login screen, produced/prəˈduːst/ for you by a program called a display manager.