INITRD(4) Linux Programmer’s Manual INITRD(4) 名前 initrd - ブートローダによって初期化された RAM ディスク 設定 /dev/initrd は、メジャー番号 1、マイナー番号 250 が割り当てられた読み込 み専用のブロックデバイスである。普通、 /dev/initrd の所有者は root.disk であり、モードは 400 (root のみが読み出し可能) である。もし、Linux シス テムに作成済の /dev/initrd ファイルがなかった場合、以下のコマンドで作成 することができる: mknod -m 400 /dev/initrd b 1 250 chown root:disk /dev/initrd ま た 、 /dev/initrd を使用するためには、 "RAM disk" と "Initial RAM disk" の両方の機能が Linux カーネルに直接組み込まれていなければならない ( 例えば、カーネルのコンパイル時の設定で CONFIG_BLK_DEV_RAM=y かつ CON- FIG_BLK_DEV_INITRD=y とする)。 /dev/initrd を使用する場合には、RAM ディ スクドライバをモジュールとしてロードすることはできない。 説明 /dev/initrd スペシャルファイルは読み込み専用のブロックデバイスである。 このデバイスはカーネルが起動される前にブートローダ (boot loader) によっ て初期化 (例えば、ロード) される RAM ディスクである。その後、カーネルは /dev/initrd の内容を二段階のシステム起動 (two-phase system boot-up) で 利用することができる。 最初のブートアップ段階 (first boot-up phase) では、カーネルは (例えば、 ブートローダによって初期化された RAM disk である) /dev/initrd の内容 を 初 期ルートファイルシステム (root file-system) としてマウントして起動す る。第二段階では初期ルートデバイスに含まれているものから、追加のドラ イ バ やその他のモジュールがロードされる。追加のモジュールがロードされた後 、新しいルートファイルシステム (すなわち、通常時のルートファイルシス テ ム) が別のデバイスからマウントされる。 ブートアップ作業 initrd を利用した時は、システムは次のようにブートする: 1. ブートローダはカーネルプログラムと /dev/initrd の内容をメモリにロー ドする。 2. カーネル起動時、カーネルは /dev/initrd デバイスの内容を展開 (uncom- press) し、 /dev/ram0 にコピーする。さらに、 /dev/initrd の使ってい たメモリを解放する。 3. カーネルは /dev/ram0 デバイスを初期のルートファイルシステムとして 読 み書き可能な形式でマウントする。 4. 指示されたルートファイルシステムが初期ルートファイルシステム (例えば /dev/ram0) と同一の場合は、カーネルは普通のブートシーケンスのため の 最後のステップを省略する。 5. /linuxrc という実行可能なファイルが初期ルートファイルシステムに存在 すれば、 /linuxrc を UID 0 (すなわち、root) の権限 で 実 行 す る 。 (/linuxrc ファイルは実行可能パーミッションが与えられていなければなら ない。 /linuxrc は正当な実行ファイルであればよく、シェルスクリプトで も構わない。) 6. /linuxrc が実行されない、または、 /linuxrc の実行が終了した時は、通 常時ルートファイルシステムがマウントされる。 (/linuxrc を終了した 時 、何らかのファイルシステムが初期ルートファイルシステム上にマウントさ れている場合のカーネルの動作は決められていない (不定である)。現在 の カ ー ネルがどのように動作するかは、「注意」のセクションを参照のこと 。) 7. 通常時ルートファイルシステムにディレクトリ /initrd が あ れ ば 、 /dev/ram0 デバイスは / から /initrd に移動される。 /initrd ディレク トリが存在しない場合は、 /dev/ram0 はアンマウントされ る 。 (/ が /initrd に移動された場合には、 /dev/ram0 はアンマウントされず、その 結果、 /dev/ram0 で走り始めたプロセスはそのまま残る事ができる。も し 、 /initrd ディレクトリが通常時ルートファイルシステムに存在せず、 /linuxrc が終了した時に /dev/ram0 上で実行された、なんらかのプロセス が走り続けていた場合のカーネルの動作は 決められていない (不定である) 。現在のカーネルが、この時どのような動作をするかについては、「注意」 を参照のこと。) 8. 普通のブートシーケンス (例えば、 /sbin/init の起動) が通常時ルートフ ァイルシステム上で行われる。 オプション initrd を用いる場合に、カーネルのブートアップ操作に影響を与えるブートロ ーダ・オプションは次のようなものがある、 initrd=filename /dev/initrd の内容としてロードするファイルを指定する。 LOADLIN では、これはコマンドラインオプションである。 LILO では、 LILO の 設定ファイル /etc/lilo.config 内でコマンドとして使用しなければな らない。このオプションで指定されるファイルは、多くの場合 gzip 圧 縮されたファイルシステムイメージである。 noinitrd こ の 起 動 オプションは二段階の起動操作を無効にする。カーネルは /dev/initrd が初期化されていない場合と同様の、通常のブートアップ 動作を行う。このオプションを用いると、ブートローダによってメモリ 上にロードされた /dev/initrd の内容はそのまま保存される。つま り 、 このオプションを用いることによって、 /dev/initrd の内容を (ブ ート以外の目的に) 利用することが可能になる。また、その内容はファ イ ルシステムイメージに限定されない。しかし、 /dev/initrd デバイ スは読みだしのみ可能であり、システムの起動後 1 度しか読み出す 事 ができない。 root=device-name 通 常 時ルートファイルシステムとして使われるデバイスを指定する。 LOADLIN では、これはコマンドラインオプションである。 LILO ではコ マ ン ド ラ イ ン オプション、または、 LILO の設定ファイルである /etc/lilo.config のオプションラインとして使用する。このオプシ ョ ンで指定されるデバイスは、適切なルートファイルシステムとしてマウ ント可能なデバイスでなければならない。 通常時ルートファイルシステムの変更 デフォルトでは、カーネルの設定 (例えば、 rdev(8) を用いてカーネルファイ ル 内にセットされたもの、または、コンパイル時にカーネルファイル内に埋め 込まれたもの)、または、ブートローダのオプション設定によって指定されたも のが通常時ルートファイルシステムとして使われる。 NFS マウントされた通常 時ルートファイルシ ス テ ム を 利 用 す る 場 合 、 nfs_root_name と nfs_root_addrs ブートオプションを使って NFS の設定を与えなければならな い。 NFS マウントされたルート (ファイルシステム) についてのより詳しい情 報 は 、 カ ーネルのドキュメントファイル Documentation/filesystems/nfs- root.txt を参照のこと。ルートファイルシステムの設定についてのより詳しい 情報は、 LILO と LOADLIN のドキュメントも参照のこと。 ま た、 /linuxrc を用いる事によっても通常時ルートファイルシステムデバイ スを変更することができる。 /linuxrc を用いて、通常時ルートデバイスを 変 更 するためには、 /proc がマウントされていなければならない。 /proc をマ ウントした後で、 /linuxrc は proc ファイル /proc/sys/kernel/real-root- dev, /proc/sys/kernel/nfs-root-name, /proc/sys/kernel/nfs-root-addrs に 書き込みを行い、通常時ルートデバイスを変更する。 (NFS ではない) 物理 的 な ルートデバイスの場合、 /linuxrc が新しいルートファイルシステムのデバ イス番号を /proc/sys/kernel/real-root-dev に書き込むことで、ルートデ バ イ ス が変更される。 NFS ルートファイルシステムの場合、 /linuxrc が NFS の設定を /proc/sys/kernel/nfs-root-name と /proc/sys/kernel/nfs-root- addrs に書き込み、それから /proc/sys/kernel/real-root-dev に (疑似 NFS デバイスナンバーである) 0xff を書き込むことで、ルートデバイスが変更され る 。 例 え ば 、次のシェルコマンドラインにより、通常時ルートデバイスを /dev/hdb1 に変更できるだろう: echo 0x365 >/proc/sys/kernel/real-root-dev また、NFS の場合、次のようなシェルコマンドラインにより、ローカルネッ ト ワークの 193.8.232.2 という IP アドレスを持つ NFS サーバの NFS ディレク トリ /var/nfsroot を 193.8.232.7 という IP アドレスを持つ "idefix" とい う 名前のシステムの通常時ルートデバイスとしてマウントするように変更でき るだろう: echo /var/nfsroot >/proc/sys/kernel/nfs-root-name echo 193.8.232.2:193.8.232.7::255.255.255.0:idefix \ >/proc/sys/kernel/nfs-root-addrs echo 255 >/proc/sys/kernel/real-root-dev 注意: ルートファイルシステムを変更する た め に /proc/sys/kernel/real- root-dev を使うのは以前の方法である。ルートファイルシステムを変更する新 しい方法についての情報は、カーネルソースに含まれ る Documentation/ini- trd.txt ファイルや、 pivot_root(2) や pivot_root(8) を参照してほしい。 使い方 initrd が実装された主な目的は、システムインストール時に、モジュール化さ れたカーネルの設定を可能にすることであった。 次のような流れのシステムインストールが可能になる: 1. ローダプログラムは、フロッピーやその他のメディアから、最小限のカーネ ル (例えば、 /dev/ram, /dev/initrd, ext2 ファイルシステムのみのサポ ートしたカーネル) をブートし、 gzip 圧縮された初期ファイルシステムイ メージを /dev/initrd にロードする。 2. 実行ファイル /linuxrc は、(1) 通常時ルートファイルシステムのマウント に何が必要か (すなわち、デバイスタイプ、デバイスドライバ、ファイルシ ステム)、 (2) 配布メディアに何が必要か (例えば、CD-ROM, ネットワーク 、テープなど) を決定する。決定は、ユーザへの問い合わせ、自動検出、あ るいはその両者の方法を組み合わせて行われる。 3. 実行ファイル /linuxrc は、初期ルートファイルシステムから必要なモジュ ールをロードする。 4. 実行ファイル /linuxrc は、ルートファイルシステムを作成し、配置する ( この段階では、通常時ルートファイルシステムは完全なシステムである必要 はない)。 5. 実行ファイル /linuxrc は、 /proc/sys/kernel/real-root-dev を設定し、 /proc 、マウントされている通常時ファイルシステム及びその他のファイル システムをアンマウントし、実行を終了する。 6. 次に、カーネルは、通常時ルートファイルシステムをマウントする。 7. この段階で、ファイルシステムは全く変更が行われていない状態で、アクセ スできる状態になる。また、ブートローダをインストールすることができる 。 8. ブートローダを設定し、システム起動時に使用されるカーネルモジュールの セ ットを含んだファイルシステムを /dev/initrd にロードする (例えば、 /dev/ram0 デバイスの内容を修正し、アンマウン ト す る 。 最 後 に 、 /dev/ram0 のイメージをファイルに書き出す)。 9. これで、システムがブート可能になる。この後、さらにその他のインストー ルの作業を実行できる。 上記の動作での /dev/initrd の役割のキーポイントは、初期カーネルの選択や 大 きなジェネリックカーネル、カーネルの再構築なしに、通常のシステム操作 で再利用可能な設定データを利用することにある。 2 番目のケースは、一つの管理上のネットワークにおいて、異なる設定のハ ー ドウェアのシステム上で Linux を動作させるためのインストールを行う場合で ある。このようなケースの場合、ごく小数のカーネルのセット (理想的には た っ た一つのカーネル) のみを利用し、システム固有の設定情報は可能な限り小 さくすることが望ましいであろう。この場合、全ての必要なモジュールが入 っ た共通ファイルを作成する。そして、 /linuxrc ファイル、または、 /linuxrc から実行されるファイルのみを異なったものにしておく。 3 番目のケースは、より便利な復旧用ディスクを作る場合である。ルートフ ァ イ ルシステムのパーティションの位置といった情報はブート時に必要ないため 、 /dev/initrd からロードされたシステムは、必要な正常性チェックを行った 後 で、ユーザへの問い合わせや自動検出 (もしくはその両方) を行うことがで きるようになる。 (他にもたくさん例があるだろうが) 最後の例としては、 initrd を利用すると 、CD-ROM 上の Linux ディストリビューションをより簡単に CD-ROM からイン ストールすることができるだろう。ディストリビューションは、 LOADLIN を使 って、フロッピーを全く利用せずに CD-ROM から /dev/initrd を直接ロードす ることができる。また、 LILO ブートフロッピーを使ってブー ト を 行 い 、 /dev/initrd を通して CD-ROM からより大きな RAM ディスクを起動することも できる。 ファイル /dev/initrd /dev/ram0 /linuxrc /initrd 注意 1. 現在のカーネルでは、 /dev/ram0 が / から /initrd に移動された際に 、 移動時にマウントされていたファイルシステムは、その後も継続的にアクセ ス可能である。しかし、 /proc/mounts のエントリは更新されない。 2. 現在のカーネルでは、ディレクトリ /initrd が 存 在 し な い 場 合 、 /dev/ram0 を何らかのプロセスが利用していたり、何らかのファイルシステ ムが /dev/ram0 上にマウントされていると、 /dev/ram0 は完全にはアンマ ウ ント「されない」。 /dev/ram0 が、完全にアンマウント「されなければ 」、 /dev/ram0 はメモリ上に残ってしまうはずである。 3. /dev/initrd の利用者は、上記の注意事項で述べた動作に依存しないように す べきである。これらの動作は Linux カーネルの将来のバージョンでは変 更されるかもしれないからだ。 関連項目 chown(1), mknod(1), ram(4), freeramdisk(8), rdev(8) カーネルソースパッケージに含まれるドキュメントファ イ ル initrd.txt 、 LILO のドキュメント、LOADLIN のドキュメント、SYSLINUX のドキュメント。 Linux 2009-04-04 INITRD(4)
INITRD(4) Linux Programmer’s Manual INITRD(4) NAME initrd - boot loader initialized RAM disk CONFIGURATION The /dev/initrd is a read-only block device assigned major number 1 and minor number 250. Typically /dev/initrd is owned by root.disk with mode 0400 (read access by root only). If the Linux system does not have /dev/initrd already created, it can be created with the following commands: mknod -m 400 /dev/initrd b 1 250 chown root:disk /dev/initrd Also, support for both "RAM disk" and "Initial RAM disk" (e.g. CON- FIG_BLK_DEV_RAM=y and CONFIG_BLK_DEV_INITRD=y) must be compiled directly into the Linux kernel to use /dev/initrd. When using /dev/initrd, the RAM disk driver cannot be loaded as a module. DESCRIPTION The special file /dev/initrd is a read-only block device. This device is a RAM disk that is initialized (e.g., loaded) by the boot loader before the kernel is started. The kernel then can use /dev/initrd’s contents for a two-phase system boot-up. In the first boot-up phase, the kernel starts up and mounts an initial root file-system from the contents of /dev/initrd (e.g., RAM disk ini- tialized by the boot loader). In the second phase, additional drivers or other modules are loaded from the initial root device’s contents. After loading the additional modules, a new root file system (i.e., the normal root file system) is mounted from a different device. Boot-up Operation When booting up with initrd, the system boots as follows: 1. The boot loader loads the kernel program and /dev/initrd’s contents into memory. 2. On kernel startup, the kernel uncompresses and copies the contents of the device /dev/initrd onto device /dev/ram0 and then frees the memory used by /dev/initrd. 3. The kernel then read-write mounts the device /dev/ram0 as the ini- tial root file system. 4. If the indicated normal root file system is also the initial root file-system (e.g. /dev/ram0) then the kernel skips to the last step for the usual boot sequence. 5. If the executable file /linuxrc is present in the initial root file- system, /linuxrc is executed with UID 0. (The file /linuxrc must have executable permission. The file /linuxrc can be any valid exe- cutable, including a shell script.) 6. If /linuxrc is not executed or when /linuxrc terminates, the normal root file system is mounted. (If /linuxrc exits with any file-sys- tems mounted on the initial root file-system, then the behavior of the kernel is UNSPECIFIED. See the NOTES section for the current kernel behavior.) 7. If the normal root file system has a directory /initrd, the device /dev/ram0 is moved from / to /initrd. Otherwise if the directory /initrd does not exist, the device /dev/ram0 is unmounted. (When moved from / to /initrd, /dev/ram0 is not unmounted and therefore processes can remain running from /dev/ram0. If directory /initrd does not exist on the normal root file system and any processes remain running from /dev/ram0 when /linuxrc exits, the behavior of the kernel is UNSPECIFIED. See the NOTES section for the current kernel behavior.) 8. The usual boot sequence (e.g., invocation of /sbin/init) is per- formed on the normal root file system. Options The following boot loader options, when used with initrd, affect the kernel’s boot-up operation: initrd=filename Specifies the file to load as the contents of /dev/initrd. For LOADLIN this is a command-line option. For LILO you have to use this command in the LILO configuration file /etc/lilo.config. The filename specified with this option will typically be a gzipped file-system image. noinitrd This boot option disables the two-phase boot-up operation. The kernel performs the usual boot sequence as if /dev/initrd was not initialized. With this option, any contents of /dev/initrd loaded into memory by the boot loader contents are preserved. This option permits the contents of /dev/initrd to be any data and need not be limited to a file system image. However, device /dev/initrd is read-only and can be read only one time after system startup. root=device-name Specifies the device to be used as the normal root file system. For LOADLIN this is a command-line option. For LILO this is a boot time option or can be used as an option line in the LILO configuration file /etc/lilo.config. The device specified by the this option must be a mountable device having a suitable root file-system. Changing the Normal Root File System By default, the kernel’s settings (e.g., set in the kernel file with rdev(8) or compiled into the kernel file), or the boot loader option setting is used for the normal root file systems. For an NFS-mounted normal root file system, one has to use the nfs_root_name and nfs_root_addrs boot options to give the NFS settings. For more infor- mation on NFS-mounted root see the kernel documentation file Documenta- tion/filesystems/nfsroot.txt. For more information on setting the root file system see also the LILO and LOADLIN documentation. It is also possible for the /linuxrc executable to change the normal root device. For /linuxrc to change the normal root device, /proc must be mounted. After mounting /proc, /linuxrc changes the normal root device by writing into the proc files /proc/sys/kernel/real-root-dev, /proc/sys/kernel/nfs-root-name, and /proc/sys/kernel/nfs-root-addrs. For a physical root device, the root device is changed by having /lin- uxrc write the new root file system device number into /proc/sys/ker- nel/real-root-dev. For an NFS root file system, the root device is changed by having /linuxrc write the NFS setting into files /proc/sys/kernel/nfs-root-name and /proc/sys/kernel/nfs-root-addrs and then writing 0xff (e.g., the pseudo-NFS-device number) into file /proc/sys/kernel/real-root-dev. For example, the following shell com- mand line would change the normal root device to /dev/hdb1: echo 0x365 >/proc/sys/kernel/real-root-dev For an NFS example, the following shell command lines would change the normal root device to the NFS directory /var/nfsroot on a local net- worked NFS server with IP number 193.8.232.7 for a system with IP num- ber 193.8.232.7 and named "idefix": echo /var/nfsroot >/proc/sys/kernel/nfs-root-name echo 193.8.232.2:193.8.232.7::255.255.255.0:idefix \ >/proc/sys/kernel/nfs-root-addrs echo 255 >/proc/sys/kernel/real-root-dev Note: The use of /proc/sys/kernel/real-root-dev to change the root file system is obsolete. See the kernel source file Documentation/ini- trd.txt as well as pivot_root(2) and pivot_root(8) for information on the modern method of changing the root file system. Usage The main motivation for implementing initrd was to allow for modular kernel configuration at system installation. A possible system installation scenario is as follows: 1. The loader program boots from floppy or other media with a minimal kernel (e.g., support for /dev/ram, /dev/initrd, and the ext2 file- system) and loads /dev/initrd with a gzipped version of the initial file-system. 2. The executable /linuxrc determines what is needed to (1) mount the normal root file-system (i.e., device type, device drivers, file system) and (2) the distribution media (e.g., CD-ROM, network, tape, ...). This can be done by asking the user, by auto-probing, or by using a hybrid approach. 3. The executable /linuxrc loads the necessary modules from the initial root file-system. 4. The executable /linuxrc creates and populates the root file system. (At this stage the normal root file system does not have to be a completed system yet.) 5. The executable /linuxrc sets /proc/sys/kernel/real-root-dev, unmount /proc, the normal root file system and any other file systems it has mounted, and then terminates. 6. The kernel then mounts the normal root file system. 7. Now that the file system is accessible and intact, the boot loader can be installed. 8. The boot loader is configured to load into /dev/initrd a file system with the set of modules that was used to bring up the system. (e.g., Device /dev/ram0 can be modified, then unmounted, and finally, the image is written from /dev/ram0 to a file.) 9. The system is now bootable and additional installation tasks can be performed. The key role of /dev/initrd in the above is to re-use the configuration data during normal system operation without requiring initial kernel selection, a large generic kernel or, recompiling the kernel. A second scenario is for installations where Linux runs on systems with different hardware configurations in a single administrative network. In such cases, it may be desirable to use only a small set of kernels (ideally only one) and to keep the system-specific part of configura- tion information as small as possible. In this case, create a common file with all needed modules. Then, only the /linuxrc file or a file executed by /linuxrc would be different. A third scenario is more convenient recovery disks. Because informa- tion like the location of the root file-system partition is not needed at boot time, the system loaded from /dev/initrd can use a dialog and/or auto-detection followed by a possible sanity check. Last but not least, Linux distributions on CD-ROM may use initrd for easy installation from the CD-ROM. The distribution can use LOADLIN to directly load /dev/initrd from CD-ROM without the need of any floppies. The distribution could also use a LILO boot floppy and then bootstrap a bigger ram disk via /dev/initrd from the CD-ROM. FILES /dev/initrd /dev/ram0 /linuxrc /initrd NOTES 1. With the current kernel, any file systems that remain mounted when /dev/ram0 is moved from / to /initrd continue to be accessible. However, the /proc/mounts entries are not updated. 2. With the current kernel, if directory /initrd does not exist, then /dev/ram0 will not be fully unmounted if /dev/ram0 is used by any process or has any file-system mounted on it. If /dev/ram0 is not fully unmounted, then /dev/ram0 will remain in memory. 3. Users of /dev/initrd should not depend on the behavior give in the above notes. The behavior may change in future versions of the Linux kernel. SEE ALSO chown(1), mknod(1), ram(4), freeramdisk(8), rdev(8) The documentation file initrd.txt in the kernel source package, the LILO documentation, the LOADLIN documentation, the SYSLINUX documenta- tion. 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 2009-04-04 INITRD(4)
コロナウイルスの日ごとの感染者数・死者数をグラフ化してみました。どの国が増加傾向にあり、どの国が終息に向かっているかを視覚化しています。
Copyright(C) linux-cmd.com All Rights Reserved. Author Takayuki Yukawa