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