BOOT(7) Linux Programmer’s Manual BOOT(7) 名前 boot-scripts - ブートシーケンスの一般的な解説 説明 細 かいところはシステムによって異なるが、大まかに言うと、ブートシーケン スは以下の段階に分けられる: (1) ハードウェアのブート (2) OS ロ ー ダ ー (3) カーネルの起動 (4) init と inittab (5) ブートスクリプト ハードウェアのブート 電源投入やハードリセットが行われると、 ROM (通常は PROM) に保存されてい るプログラムに制御が渡される。 PC ではこのプログラムは通常 BIOS と呼 ば れる。 ふ つうこのプログラムは、まずマシンの基本的な自己診断を行い、そして不揮 発性メモリにアクセスして各種のパラメータを読み込む。 PC では、このメ モ リは電池によってバックアップされている CMOS メモリである。そのため CMOS と呼ばれることが多い。しかし PC 以外の世界 で は 、 通 常 nvram (non- volatile ram) と呼ばれている。 nvram に保存されているパラメータはシステムによって異なる。しかし、ハー ドウェアブートプログラムは、少なくとも、ブートデバイスがどれであるか 、 も しくはブートデバイスとして探索するデバイスがどれであるかを知っていな ければならない。 ハードウェアブートのシーケンスは、次にブートデバイスにアクセスし、ブ ー ト デバイスのあらかじめ決まった場所に置かれている OS ローダーをロードし 、制御を渡す。 注意: ここではネットワークブートについては触れない。この話題について調 査したい読者は、 DHCP, TFTP, PXE, Etherboot 等について調べてみる とよい。 OS ローダー PC では、OS ローダーはブートデバイスの先頭セクタに置かれる。これは MBR (Master Boot Record) と呼ばれる。 様 々な制約のため、ほとんどのシステムで第一ローダーは非常に簡単な機能し か持っていない。 PC 以外のシステムでも、サイズの制限やローダーの機能 な ど にある程度の制限は存在する。しかしパーティションテーブルを含めて 512 バイトという PC の MBR では、OS ローダーの全機能をここに押し込むのは ま ず不可能だ。 し たがって大抵の OS では、第一ローダーは第二ローダーを呼ぶようになって おり、後者はあらかじめ指定されたディスクパーティションに置けるように な っている。 Linux における OS ローダーは、ふつう lilo(8) か grub(8) である。両者と も第二ローダーとしてインストールすることもでき (この場合 DOS がインスト ー ルした MBR がこれらを指すようにする)、また第一・第二ローダーの両方と してインストールすることもできる。後者の場合向けに、両者は特別な MBR イ メ ージを提供している。これには第二ローダーをルートパーティションからロ ードするようなブートストラップコードが含まれている。 OS ローダーの主な仕事は、カーネルのディスク上の位置を特定し、ロードして 起 動することである。ほとんどの OS ローダーは、対話モードで使用すること もでき、追加のパラメータをカーネルに渡したり、デフォルトとは別のカー ネ ル を指定したりすることができる (例えば、最後にコンパイルしたカーネルが 機能しなかった時にバックアップのカーネルを指定して起動するといったこ と ができる)。 カーネルの起動 カ ーネルはロードされると、デバイスを (ドライバによって) 初期化し、スワ ッパを起動し (最近の Linux カーネルでは、スワッパは kswapd という「カー ネルプロセス」になる)、ルートファイルシステム (/) をマウントする。 カ ーネルに渡すことのできるパラメータのいくつかは、これらの動作に関係す る。 (例えばデフォルトのルートファイルシステムを変更したり で き る) 。 Linux カーネルパラメータに関するより詳しい情報は bootparam(7) を読んで ほしい。 これらが済んではじめて、カーネルは最初の (ユーザランドの) プロセスを 生 成し、番号 1 を与える。このプロセスは /sbin/init プログラムを実行する。 カーネルによって解釈されていないパラメータはすべて /sbin/init に渡さ れ る。 init と inittab init は、起動するとまず /etc/inittab を読み、その後の行動に関する情報を 得る。このファイルは ランレベルによってどのような動作を行うべきであるか を定義する。 こ れによってシステム管理者の管理が楽になる。各ランレベルは提供するサー ビスの集合に対応する (例えば S は シングルユーザ、 2 では大抵のネットワ ー クサービスを起動する、など)。システム管理者は、 init(8) を用いて現在 のランレベルを変更でき、 runlevel(8) によって現在のランレベルを確認でき る。 し かし、このファイルを編集して個々のサービスを管理するのは不便なので、 inittab は単にスクリプトの集合に対するブートストラップになっている。 実 際の個々のサービスの起動や停止は、これらのスクリプトで行う。 ブートスクリプト 注意: 以下の説明は System V Release 4 をベースとしたシステムに関するも のである。現在の大抵の商用 Unix システム (Solaris, HP-UX, Irix, Tru64) や 、 メ ジャーな Linux ディストリビューション (RedHat, Debian, Mandrake, Suse, Caldera) はこれをベースにしたものであ る 。システムによっては、ブートスクリプトの機構がいくらか異なること もある (Slackware Linux, FreeBSD, OpenBSD など)。 管理すべき各サービス (メール、nfs サーバ、cron などなど) それぞれに対し て、ブートスクリプトがひとつずつ特定のディレクトリ (ほとんどの Linux で /etc/init.d) に配置される。これらのスクリプトは、それぞれ引数としてひと つの単語を取る。"start" が指定されるとそのサービスを起動し、"stop" が指 定されるとサービスを停止する。スクリプトは他の「便利な」引数を取って も よ い (例えば "restart" で停止・起動を順番に行ったり、"status" でサービ スの状態を表示するなど)。スクリプトを引数なしで実行すると、指定できる引 数の一覧が表示される。 順序づけディレクトリ あるランレベルで、特定のスクリプトを指定した順序で実行させるため、 順序 付けディレクトリ (sequencing directory) という仕組みが存在する。これ ら はふつう /etc/rc[0-6S].d である。各ディレクトリの内部には、 /etc/init.d ディレクトリに置かれたスクリプトへのリンク (ふつうはシンボリックリンク) が置かれる。 第 一スクリプト (通常 /etc/rc) は inittab(5) から呼ばれ、順序付けディレ クトリに置かれたリンク経由で各サービススクリプトを呼び出す。名前が 'S' ではじまるリンクは "start" という引数をつけて呼び出され (すなわちサービ スが起動し)。名前が 'K' ではじまるリンクは "stop" という引数をつけて 呼 び出される (すなわちサービスが停止する)。 同 じランレベルの内部での起動や停止の順序を規定するために、リンクの名前 には順序を示す数字が含まれる。また、名前をわかりやすくするため、リン ク 名 の 末 尾 に は 対 応 す る サ ー ビ ス の 名前がつけられる。例えば、 /etc/rc2.d/S80sendmail というリンクは、sendmail サービスをランレベル 2 に お い て 起 動 す る。これは、 /etc/rc2.d/S12syslog よりも後に、また /etc/rc2.d/S90xfs よりも先に実行される。 ブートの順序とランレベルを管理するには、これらのリンクを管理しなけれ ば ならない。しかし多くの Linux ディストリビューションでは、これらの作業を 手助けしてくれるツールが存在する (例えば chkconfig(8) など)。 ブートの設定 デーモンの起動時には、コマンドラインオプションやパラメータを指定でき る の が普通である。システム管理者がこれらのパラメータを変更したいと思った ときに、ブートスクリプトそのものを編集しなくてもすむよう、設定ファイ ル が 用 い ら れ る 。 こ れ ら は特定のディレクトリ (RedHat システムでは /etc/sysconfig) に置かれ、ブートスクリプトから参照される。 古い Unix システムでは、これらのファイルにはデーモンに与える実際のコ マ ンドラインオプションが書かれていた。しかし最近の Linux システム (や HP- UX) では、これらのファイルには単にシェル変数が書かれているだけである 。 /etc/init.d に置かれたブートスクリプトは、これらの設定ファイルを source し、その変数の値を用いる。 ファイル /etc/init.d/, /etc/rc[S0-6].d/, /etc/sysconfig/ 関連項目 inittab(5), bootparam(7), init(8), runlevel(8), shutdown(8) Linux 2007-06-03 BOOT(7)
BOOT(7) Linux Programmer’s Manual BOOT(7) NAME boot-scripts - General description of boot sequence DESCRIPTION The boot sequence varies in details among systems but can be roughly divided to the following steps: (i) hardware boot, (ii) OS loader, (iii) kernel startup, (iv) init and inittab, (v) boot scripts. We will describe each of these in more detail below. Hardware-boot After power-on or hard reset, control is given to a program stored on read-only memory (normally PROM). In PC we usually call this program the BIOS. This program normally makes a basic self-test of the machine and accesses non-volatile memory to read further parameters. This memory in the PC is battery-backed CMOS memory, so most people refer to it as the CMOS, although outside of the PC world, it is usually called nvram (non-volatile ram). The parameters stored in the nvram vary between systems, but as a mini- mum, the hardware boot program should know what is the boot device, or which devices to probe as possible boot devices. Then the hardware boot stage accesses the boot device, loads the OS Loader, which is located on a fixed position on the boot device, and transfers control to it. Note: We do not cover here booting from network. Those who want to investigate this subject may want to research: DHCP, TFTP, PXE, Etherboot. OS Loader In PC, the OS Loader is located in the first sector of the boot device - this is the MBR (Master Boot Record). In most systems, this primary loader is very limited due to various constraints. Even on non-PC systems there are some limitations to the size and complexity of this loader, but the size limitation of the PC MBR (512 bytes including the partition table) makes it almost impossi- ble to squeeze a full OS Loader into it. Therefore, most operating systems make the primary loader call a sec- ondary OS loader which may be located on a specified disk partition. In Linux the OS loader is normally lilo(8) or grub(8). Both of them may install either as secondary loaders (where the DOS installed MBR points to them), or as a two part loader where they provide special MBR containing the bootstrap code to load the second part of the loader from the root partition. The main job of the OS Loader is to locate the kernel on the disk, load it and run it. Most OS loaders allow interactive use, to enable speci- fication of alternative kernel (maybe a backup in case the last com- piled one isn’t functioning) and to pass optional parameters to the kernel. Kernel Startup When the kernel is loaded, it initializes the devices (via their drivers), starts the swapper (it is a "kernel process", called kswapd in modern Linux kernels), and mounts the root file system (/). Some of the parameters that may be passed to the kernel relate to these activities (e.g: You can override the default root file system). For further information on Linux kernel parameters read bootparam(7). Only then the kernel creates the first (user land) process which is numbered 1. This process executes the program /sbin/init, passing any parameters that weren’t handled by the kernel already. init and inittab When init starts it reads /etc/inittab for further instructions. This file defines what should be run in different run-levels. This gives the system administrator an easy management scheme, where each run-level is associated with a set of services (e.g: S is single- user, on 2 most network services start, etc.). The administrator may change the current run-level via init(8) and query the current run- level via runlevel(8). However, since it is not convenient to manage individual services by editing this file, inittab only bootstraps a set of scripts that actu- ally start/stop the individual services. Boot Scripts Note: The following description applies to System V release 4 based system, which currently covers most commercial Unix systems (Solaris, HP-UX, Irix, Tru64) as well as the major Linux distri- butions (RedHat, Debian, Mandrake, Suse, Caldera). Some systems (Slackware Linux, FreeBSD, OpenBSD) have a somewhat different scheme of boot scripts. For each managed service (mail, nfs server, cron, etc.) there is a sin- gle startup script located in a specific directory (/etc/init.d in most versions of Linux). Each of these scripts accepts as a single argument the word "start" -- causing it to start the service, or the word "stop" -- causing it to stop the service. The script may optionally accept other "convenience" parameters (e.g: "restart", to stop and then start, "status" do display the service status). Running the script without parameters displays the possible arguments. Sequencing Directories To make specific scripts start/stop at specific run-levels and in spe- cific order, there are sequencing directories. These are normally in /etc/rc[0-6S].d. In each of these directories there are links (usually symbolic) to the scripts in the /etc/init.d directory. A primary script (usually /etc/rc) is called from inittab(5) and calls the services scripts via the links in the sequencing directories. All links with names that begin with 'S' are being called with the argument "start" (thereby starting the service). All links with names that begin with 'K' are being called with the argument "stop" (thereby stop- ping the service). To define the starting or stopping order within the same run-level, the names of the links contain order-numbers. Also, to make the names clearer, they usually end with the name of the service they refer to. Example: the link /etc/rc2.d/S80sendmail starts the sendmail service on runlevel 2. This happens after /etc/rc2.d/S12syslog is run but before /etc/rc2.d/S90xfs is run. To manage the boot order and run-levels, we have to manage these links. However, on many versions of Linux, there are tools to help with this task (e.g: chkconfig(8)). Boot Configuration Usually the daemons started may optionally receive command-line options and parameters. To allow system administrators to change these parameters without editing the boot scripts themselves, configuration files are used. These are located in a specific directory (/etc/sysconfig on RedHat systems) and are used by the boot scripts. In older Unix systems, these files contained the actual command line options for the daemons, but in modern Linux systems (and also in HP- UX), these files just contain shell variables. The boot scripts in /etc/init.d source the configuration files, and then use the variable values. FILES /etc/init.d/, /etc/rc[S0-6].d/, /etc/sysconfig/ SEE ALSO inittab(5), bootparam(7), init(8), runlevel(8), shutdown(8) COLOPHON This page is part of release 3.22 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2007-06-03 BOOT(7)
Copyright(C) linux-cmd.com All Rights Reserved. Author Takayuki Yukawa