From Power Up To Bash Prompt <AUTHOR>Greg O'Keefe, <tt>gcokeefe@postoffice.utas.edu.au</tt> <DATE>v0.9, November 2000 <TRANS> 日本語訳 千旦裕司 <TDATE>v0.9j November 2000 <ABSTRACT> <!--This is a brief description of what happens in a Linux system, from the time that you turn on the power, to the time that you log in and get a bash prompt. Understanding this will be helpful when you need to solve problems or configure your system.--> この文書は、電源を入れてからログインし、 bash プロンプトが表示されるまでに Linux システム上で何が起こっているのかを簡潔に解説したものである。この文書を 理解しておけば、問題の解決やシステムの設定が必要になったときに役に立つだろう。 </ABSTRACT> <TOC> <!--######################第一章 イントロダクション####################--> <SECT>Introduction <!-- <P>I find it frustrating that many things happen inside my Linux machine that I do not understand. If, like me, you want to really understand your system rather than just knowing how to use it, this document should be a good place to start. This kind of background knowledge is also needed if you want to be a top notch Linux problem solver. --> <p> よく分からない多くのことが自分の Linux マシンで起きていると思うと、わたしは もどかしくて仕方がない。もし、わたしと同じように、単に使い方が分かるというだ けでなく、本当にシステムを理解したいと思うなら、この文書はその出発点となるだ ろう。Linux における問題解決の権威を目指しているとしても、この種の基礎知識は 必要である。 <!-- <P>I assume that you have a working Linux box, and understand some basic things about Unix and PC hardware. If not, an excellent place to start learning is Eric S. Raymond's <URL URL="http://www.linuxdoc.org/HOWTO/Unix-and-Internet-Fundamentals-HOWTO.html" NAME ="The Unix and Internet Fundamentals HOWTO" > It is short, very readable and covers all the basics. --> <p> Linux の稼働するマシンを持っていることと、Unix および PC ハードウェアの基本を 理解していることが前提になる。もしそうでない場合、それらを学ぶための入門書と して、Eric Raymond の次の文献が優れている。<newline> <URL URL ="http://www.linuxdoc.org/HOWTO/Unix-and-Internet-Fundamentals-HOWTO.html" NAME ="The Unix and Internet Fundamentals HOWTO" > (<url url="http://www.linux.or.jp/JF/JFdocs/Unix-and-Internet-Fundamentals-HOWTO/index.html" name="日本語訳">). これは、簡潔で読み易く、基本事項が網羅されている。<newline> <!-- <P>The main thread in this document is how Linux starts itself up. But it also tries to be a more comprehensive learning resource. I have included exercises in each section. If you actually do some of these, you will learn much more than you could by just reading. --> <p> この文書の主題は、Linux の起動の仕組みである。しかし、むしろ分かり易い学習の 手引きにもなるよう意図されている。各章に演習を設けてあるので、実際にいくつかを 実行するなら、読んだだけの時よりもいっそう多くのことを学べるだろう。 <!--<P>I hope some readers will undertake the best Linux learning exercise that I know of, which is building a system from source code. Giambattista Vico, an Italian philosopher (1668-1744) said ``verum ipsum factum'', which means ``understanding arises through making''. Thanks to Alex (see <REF ID="acknowledge" NAME="Acknowledgements">) for this quote. --> <p> わたしの知る限り、Linux を学ぶ最良の演習は、ソースコードからのシステムを構築 することである。わたしは、それに挑戦する読者がいることを期待している。 イタリアの哲学者 Giambattista Vico (1688-1744) は、"verum ipsum factum" と言っ ている。この意味は、「理解は、作ることから生まれる」ということである。この言葉 を教えてくれた Alex (<REF ID="acknowledge" NAME="Acknowledgements">を参照)に感 謝している。 <!-- <P>If you want to ``roll your own'', you should also see Gerard Beekmans' <URL URL="http://www.linuxfromscratch.org" NAME="Linux From Scratch HOWTO"> (LFS). LFS has detailed instructions on building a complete useable system from source code. On the LFS website, you will also find a mailing list for people building systems this way. The instructions that used to be part of this document are now in a separate document ``Building a Minimal Linux System from Source Code'', and can be found at <URL URL="http://www.netspace.net.au/~gok/power2bash/" NAME="From PowerUp to Bash Prompt home page">. They explain how to ``toy'' system, purely as a learning exercise. --> <p> ソースからシステムを構築したいなら、Gerard Beekmans の文書<URL URL="http://www.linuxfromscratch.org" NAME="Linux From Scratch HOWTO"> (LFS) も見るべきだろう。LFS はソースコードか ら本当に実用的なシステムをつくるための詳細な手引書である。LFS のウェブサイト には、そうした方法でシステムを構築しようとする人向けのメーリングリストもあ る。これまでこの文書の一部であった簡単な構築方法の紹介は、現在 "Building a Minimal Linux System from Source Code (<url url="http://www.linux.or.jp/JF/JFdocs/Building-Minimal-Linux.html" name="日本語訳">)" という別の文書となっていて、 <url url="http://www.netspace.net.au/~gok/power2bash" name="From PowerUp to Bash Prompt home page"> で入手可能となっている。 その文書で述べているのは、純粋な練習課題として「おもちゃ(toy)」のシス テムを作る方法である。(訳注: LFS は翻訳時において、日本語訳作業が進行中です) <!-- <P>Packages are presented in the order in which they appear in the system startup process. This means that if you install the packages in this order you can reboot after each installation, and see the system get a little closer to giving you a bash prompt each time. There is a reassuring sense of progress in this. --> <p> 登場するパッケージは、システムが起動する過程で現れる順番に並んでいる。つま り、その順序でインストールすれば、インストールするたびに再起動できて、しかも システムが毎回少しずつ bash プロンプトの表示に近づいていくのが分かるわけであ る。それによって、着実に進歩していることが実感できる。 <!-- <P>I recommend that you first read the main text of each section, skipping the exercises and references. Then decide how deep an understanding you want to develop, and how much effort you are prepared to put in. Then start at the beginning again, doing the exercises and additional reading as you go. --> <p> 最初は、演習と参考文献等をとばして、各章の本文だけ読むことをお薦めする。そし て、どれだけ理解を深めたいか、どのくらい努力するつもりかはっきり決めて、もう 一度初めにもどり、演習と参考文献等にあたってみてほしい。 <!--########################第二章 ハードウェア#########################--> <!-- <SECT>Hardware --> <SECT> ハードウェア <!-- <P>When you first turn on your computer it tests itself to make sure everything is in working order. This is called the ``Power on self test''. Then a program called the bootstrap loader, located in the ROM BIOS, looks for a boot sector. A boot sector is the first sector of a disk and has a small program that can load an operating system. Boot sectors are marked with a magic number 0xAA55 = 43603(訳者訂正) at byte 0x1FE = 510. That's the last two bytes of the sector. This is how the hardware can tell whether the sector is a boot sector or not. --> <p> まず、コンピュータの電源を入れると、コンピュータはすべてが稼働できる状態にあ るかを自己診断する。これは、パワーオンセルフテスト(Power on self test)と呼ば れる。次に ROM BIOS に置かれたブートストラップローダ(bootstrap loader)という プログラムが、ブートセクタを探す。ブートセクタとはディスクの先頭のセクタで、 オペレーティングシステムを(メモリに)ロードする機能を持った小さなプログラムが 乗っている。ブートセクタの 0x1FE(=510) バイト目には 0xAA55(=43605) のマジックナ ンバー(訳注:ファイル形式を判断するためのナンバー)がマークされている。マークさ れた位置はセクタの末尾 2 バイトに当たる。このマークの有無で、そのセクタが ブートセクタであるかどうかをハードウェア側で識別できるわけである。 <!-- <P>The bootstrap loader has a list of places to look for a boot sector. My old machine looks in the primary floppy drive, then the primary hard drive. More modern machines can also look for a boot sector on a CD-ROM. If it finds a boot sector, it loads it into memory and passes control to the program that loads the operating system. On a typical Linux system, this program will be LILO's first stage boot loader. There are many different ways of setting your system up to boot though. See the <EM>LILO User's Guide</EM> for details. See section <REF ID="lilo-links" NAME="LILO"> for a URL. --> <p> ブートストラップローダには、ブートセクタを探すべき場所のリストが収められてい る。わたしの古いマシンは、プライマリフロッピードライブを探したあと、プライマ リハードドライブを探す。もっと新しいマシンでは CD-ROM のブートセクタを探すこ ともできる。ブートセクタが見つかれば、そこにあるプログラムをメモリにロードし それに制御を任せる。そしてそのプログラムが、オペレーティングシステムをロード する。 典型的な Linux システムでは、そのプログラムとは <tt>lilo</tt> の第一ステージ のブートローダのことになるだろう。しかしシステム起動のための設定方法は多種多 様であるから、詳細については、<em>LILO User's Guide</em> (<url url="http://www.linux.or.jp/JF/JFdocs/LILO-README/index.html" name="日本語訳">)を見てほしい。URL に ついては下記を参照のこと。<ref id="lilo-links" name="LILO"> <!-- <P>Obviously there is a lot more to say about what PC hardware does. But this is not the place to say it. See one of the many good books about PC hardware. --> <p> PC のハードウェアの動作について語るべきことは確かにまだまだあるのだが、ここは それを述べるべき場所ではない。PC のハードウェアに関しては良書がそろっているから そのひとつを読んでほしい。 <!-- <SECT1>Configuration --> <SECT1> 設定 <!-- <P>The machine stores some information about itself in its CMOS. This includes what disks and RAM are in the system. The machine's BIOS contains a program to let you modify these settings. Check the messages on your screen as the machine is turned on to see how to access it. On my machine, you press the delete key before it begins loading its operating system. --> <p> マシンはある種の自己情報を CMOS 内に保持している。その中には、どういうディス クや RAM がシステムに存在するのかという情報も含まれる。マシンの BIOS にあるプ ログラムを使えばそうした情報の設定変更ができる。電源を入れたときスクリーンに 表示されるメッセージに注意すれば、どうやってそのプログラムにアクセスするか分 かるだろう。わたしのマシンでは、オペレーティングシステムがロードされる前に delete キーを押すようになっている。 <!-- <SECT1>Exercises --> <SECT1> 演習 <LABEL ID="hardware-ex"> <!-- <P>A good way to learn about PC hardware is to build a machine out of second hand parts. Get at least a 386 so you can easily run Linux on it. It won't cost much.Ask around, someone might give you some of the parts you need. --> <P> 中古部品を使ってマシンを組み立てることは、PC ハードウェアを知る上で良い方法で ある。最低でも 386 CPU を手に入れよう。そうすれば、簡単に Linux を走らせるこ とができる。それほど費用はかからないだろう。周囲の友人に尋ねてみれば、必要な パーツを譲ってくれるかもしれない。 <!-- <P>Check out, download compile and make a boot disk for <URL URL="http://www.netspace.net.au~gok/resources" NAME=Unios>. (They used to have a home page at <URL URL="http://www.unios.org">, but it disappeared) This is just a bootable ``Hello World!'' program, consisting of just over 100 lines of assembler code. It would be good to see it converted to a format that the GNU assembler <TT>as</TT> can understand. --> <p> <url url="http://www.netspace.net.au/~gok/resources" name=unios >をダウンロード し、コンパイルしてブートディスクを作ること。(これまでは下記にホームページが あったのだが、消えてしまった。<url url="http://www.unios.org">)<newline> これは、ブート機能を持った簡単な (Hello World) プログラムであり、100 行ちょっ とのアセンブラコードでできている。GNU のアセンブラである <tt>as</tt> で理解で きるフォーマットに変換されているので、見てみるとよい。 <!-- <P>Open the boot disk image for unios with a hex editor. This image is 512 bytes long, exactly one sector. Find the magic number 0xAA55. Do the same for the boot sector from a bootable floppy disk or your own computer. You can use the <TT>dd</TT> command to copy it to a file: <TT>dd if=/dev/fd0 of=boot.sector</TT>. Be <EM>very</EM> careful to get <TT>if</TT> (input file) and <TT>of</TT> (output file) the right way round! <P>Check out the source code for LILO's boot loader. --> <p> hex editor を使って unios のブートディスクイメージを開くこと。このイメージは 512 バイトあり、ちょうど 1 セクタ分である。マジックナンバー 0xAA55 を探すこ と。起動用フロッピーディスクやコンピュータにあるブートセクタでも同じことをし てほしい。<tt>dd</tt> コマンドを使えば、それをファイルにコピーできる。<tt>dd if=/dev/fd0 of=boot.sector</tt><newline> <tt>if</tt>(input file) と <tt>of</tt>(output file) とを逆にしないように特に 注意すること! <p> LILO のブートローダのコードもチェックすること。 <!-- <SECT1>More Information --> <SECT1>参考文献等 <P> <ITEMIZE> <ITEM> <URL URL="http://www.linuxdoc.org/HOWTO/Unix-and-Internet-Fundamentals-HOWTO/index.html" NAME="The Unix and Internet Fundamentals HOWTO"> by Eric S. Raymond, <!--especially section 3, <EM>What happens when you switch on a computer? </EM>--> 特に第三章の<em>「コンピュータの電源を入れた時に何が起こるのか?」 </em>がよい。 (<url url="http://www.linux.or.jp/JF/JFdocs/Unix-and-Internet-Fundamentals-HOWTO/bootup.html" name="日本語訳">) <ITEM> <!--The first chapter of <EM>The LILO User's Guide</EM> gives an excellent explanation of PC disk partitions and booting. See section <REF ID="lilo-links" NAME="LILO"> for a URL.--> <em>The LILO User's Guide</em> (<url url="http://www.linux.or.jp/JF/JFdocs/LILO-README/index.html" name="日本語訳">)の第一章には、PC のディスクパーティションと起 動に関する優れた解説がある。URL については、<ref id="lilo-links" name="LILO"> の章を参照すること。 <ITEM> <EM>The NEW Peter Norton Programmer's Guide to the IBM PC & PS/2</EM>, by Peter Norton and Richard Wilton, Microsoft Press 1988<newline> <!--There is a newer Norton book, which looks good, but I can't afford it right now!--> 新しい Norton 本である。なかなかいいようだが、今は手が出ない。 <ITEM> <!--One of the many books available on upgrading PC's--> PC のアップグレードに関する多くの本のなかの一冊。 </ITEMIZE> <!--#########################第三章 LILO #############################--> <!-- <SECT>Lilo --> <sect>Lilo <!-- <P>When the computer loads a boot sector on a normal Linux system, what it loads is actually a part of lilo, called the ``first stage boot loader''. This is a tiny program who's only job in life is to load and run the ``second stage boot loader''. <P>The second stage loader gives you a prompt (if it was installed that way) and loads the operating system you choose. --> <p> 一般的な Linux システム上でコンピュータがブートセクタをロードするとき、実際に ロードしているのは <tt>lilo</tt> の一部である。それは「第一ステージブートロー ダ(first stage boot loader)」と呼ばれる小さなプログラムで、それに割り当てられ た唯一の仕事は「第二ステージブートローダ (second stage boot loader)」をロード して実行することである。 <p>第二ステージ(ブート)ローダは、(インストールされた方法にもよるのだが)プロン プトを表示し、そこで選択されたオペレーティングシステムをロードする。 <!-- <P>When your system is up and running, and you run <TT>lilo</TT>, what you are actually running is the ``map installer''. This reads the configuration file <TT>/etc/lilo.conf</TT> and writes the boot loaders, and information about the operating systems it can load, to the hard disk. <P>There are lots of different ways to set your system up to boot. What I have just explained is the most obvious and ``normal'' way, at least for a system who's main operating system is Linux. The Lilo Users' Guide explains several examples of ``boot concepts''. It is worth reading these, and trying some of them out. --> <p> システムが立ち上がった後で <tt>lilo</tt> と打った場合、実際に実行されるのは、 「マップインストーラー(map installer)」である。このプログラムが設定ファイル である <tt>/etc/lilo.conf</tt> を読み込んで、ハードディスクにブートローダ を書き込み、同時にロードできるオペレーティングシステムに関する情報も書き込む。 <p> システムを起動させる方法には様々な種類がある。いま説明した方法は、少なくとも Linux をメインとするシステムにおいては、もっとも分かり易い普通の方法である。 "The Lilo Users's Guide" には、ブートの概念について何通りかの例が説明されて いる。一読に値するだけでなく、そのいくつかはやってみる価値がある。 <!-- <SECT1>Configuration --> <SECT1> 設定 <!-- <P>The configuration file for lilo is <TT>/etc/lilo.conf</TT>. There is a manual page for it: type <TT>man lilo.conf</TT> into a shell to see it. The main thing in <TT>lilo.conf</TT> is one entry for each thing that lilo is set up to boot. For a Linux entry, this includes where the kernel is, and what disk partition to mount as the root filesystem. For other operating systems, the main piece of information is which partition to boot from. --> <p> <tt>lilo</tt> の設定ファイルは <tt>/etc/lilo.conf</tt> である。マニュアルの ページがあるので、<tt>man lilo.conf</tt> とタイプし、読んでみること。 <tt>lilo.conf</tt> ファイルで重要なのは、<tt>lilo</tt> を使って起動する対象ご とに個別のエントリー(entry)があるということである。Linux のエントリーならば、 カーネルがどこにあるか、ルートファイルシステムとしてどのディスクパーティショ ンをマウントするかという項目が含まれる。他のオペレーティングシステムなら、 どのパーティションから起動するかが重要な情報になる。 <!-- <SECT1>Exercises --> <SECT1> 演習 <!-- <P><EM>DANGER:</EM> take care with these exercises. It is easy enough to get something wrong and screw up your master boot record and make your system unuseable. Make sure you have a working rescue disk, and know how to use it to fix things up again. See below for a link to tomsrtbt, the rescue disk I use and recommend. The best precaution is to use a machine that doesn't matter. --> <p> <em>「危険」 </em> この演習は注意して行うこと。何かがおかしくなって、マスター ブートレコードを台無しにしてしまい、システムが使えなくなるおそれが充分にあ る。問題なく作動するレスキューディスクがあるか、それを使って復旧する方法を 知っているのかを確認してほしい。tomsrtbt へのリンクが下記にある。これは、わた しも使っているレスキューディスクで、読者にもお勧めしたい。最も慎重な方法は、 壊れてもかまわないマシンを使うことである。 <!--<P>Set up lilo on a floppy disk. It doesn't matter if there is nothing other than a kernel on the floppy - you will get a ``kernel panic'' when the kernel is ready to load init, but at least you will know that lilo is working. --> <p> フロッピーディスク上に <tt>lilo</tt> をセットアップすること。それには、カーネ ル以外何も乗っていなくてよい。ただその場合、カーネルが <tt>init</tt> をロード する態勢に入ったとき、"kernel panic" と表示される。しかし、少なくとも <tt>lilo</tt> が作動していること は分かる。 <!--<P>If you like you can press on and see how much of a system you can get going on the floppy. This is probably the second best Linux learning activity around. See the Bootdisk HOWTO (url below), and tomsrtbt (url below) for clues. --> <p> できるなら、さらに進んで、フロッピーでどこまでシステムを構築できるか試してみ ること。これはおそらく Linux をいろいろ学ぶうえで最良とは言えないまでも非常に 優れた方法だろう。Bootdisk HOWTO (下記の URL を参照)を見てほしい。また、 tomsrtbt (下記の URL) も手がかりになるだろう。 <!--<P>Get lilo to boot unios (see section <REF ID="hardware-ex" NAME="hardware exercises""> for a URL). As an extra challenge, see if you can do this on a floppy disk. --> <p> <tt>lilo</tt> を使って unios を起動させること。(<ref id="hardware-ex" name="ハードウェア 演習"> の章に URL がある) さらなるチャレンジとしてフロッ ピー上でそれができるかやってみるとよい。 <!--<P>Make a boot-loop. Get lilo in the master boot record to boot lilo in one of the primary partition boot sectors, and have that boot lilo in the master bootrecord... Or perhaps use the master boot record and all four primary partitions to make a five point loop. Fun! --> <p> ブートプロセスをループさせること。マスターブートレコード上の <tt>lilo</tt> を使って、どれかひとつのプライマリーパーティションのブートセクタ上にあるもう ひとつの <tt>lilo</tt> を起動させる。そして、その <tt>lilo</tt> にマスター ブートレコードの <tt>lilo</tt> を起動させるようにする。あるいは、マスター ブートレコードと 4 つある全てのプライマリパーティションを使って、5 点ループを 作ってみる。おもしろい! <!--<SECT1>More Information--> <SECT1>参考文献等 <P> <LABEL ID="lilo-links"> <ITEMIZE> <ITEM> <!--The lilo man page.--> <tt>lilo</tt> のマニュアルページ(<tt>man lilo</tt>) <ITEM> <!--The Lilo package (<URL URL="ftp://lrcftp.epfl.ch/pub/linux/local/lilo/" NAME="lilo">), contains the `` LILO User's Guide'' <TT>lilo-u-21.ps.gz</TT> (or a later version).You may already have this document though. Check <TT>/usr/doc/lilo</TT> or there abouts. The postscript version is better than the plain text, since it contains diagrams and tables. --> <tt>lilo</tt> のパッケージ (<URL URL="ftp://lrcftp.epfl.ch/pub/linux/local/lilo/" NAME="lilo">) には、"LILO User's Guide" (<url url="http://www.linux.or.jp/JF/JFdocs/LILO-README/index.html" name="日本語訳">)が含まれている。 この文書はもう持っているかもしれない。<tt>/usr/doc/lilo</tt> あたりを探すこと。 テキスト版よりもポストスクリプト版のほうが図表が付いているのでよい。 (そのドキュメントには、<tt>lilo-u-21.ps.gz</tt> か、それ以後のバージョン名が ついている。) <ITEM> <URL URL="http://www.toms.net/rb" NAME="tomsrtbt"> <!--the coolest single floppy linux. Makes a great rescue disk.--> 最もクールなシングルフロッピーの Linux である。すばらしいレスキューディスク になる。 <ITEM> <URL URL="http://www.linuxdoc.org/HOWTO/Bootdisk-HOWTO/" NAME="The Bootdisk HOWTO">(<url url="http://www.linux.or.jp/JF/JFdocs/Bootdisk-HOWTO.html" name="日本語 訳">)。(訳注: <url url="http://www.linux.or.jp/JF/JFdocs/inside-lilo.html" name="LILO の動作について"> もご覧ください。) </ITEMIZE> <!--############################第四章 カーネル#########################--> <!--<SECT>The Linux Kernel--> <sect> Linux カーネル <!--<P>The kernel does quite a lot really. I think a fair way of summing it up is that it makes the hardware do what the programs want, fairly and efficiently. --> <p> カーネルは実際非常に多くの仕事をしている。それらの仕事の内容を的確に要約する なら、プログラムからの要求を適正かつ効率的にハードウェアに実行させることだと 思われる。 <!--<P>The processor can only execute one instruction at a time, but Linux systems appear to be running lots of things simultaneously. The kernel acheives this by switching from task to task really quickly. It makes the best use of the processor by keeping track of which processes are ready to go, and which ones are waiting for something like a record from a hard disk file, or some keyboard input.This kernel task is called scheduling.--> <p> プロセッサは一度にひとつの命令しか実行できない。しかし、Linux システムは 同時に多くの作業をこなしているように見える。カーネルは、タスクからタスク へと瞬時の切り替え(switch)をすることでこれを実現しているのである。また カーネルは、どのプロセスが実行可能で、どのプロセスがハードディスク上の ファイルレコードやキーボードからのインプットなどを待っているのかを常に 監視することで、プロセッサ資源を最大限に活用している。 <!--<P>If a program isn't doing anything, then it doesn't need to be in RAM. Even a program that is doing something, might have parts that aren't doing anything. The address space of each process is divided into pages. The Kernel keeps track of which pages of which processes are being used the most. The pages that aren't used so much can be moved out to the swap partition. When they are needed again, another unused page can be paged out to make way for it. This is virtual memory management. --> <p> プログラムがなにもしていなければ、RAM 上にある必要はない。なにかしていたと しても、そのプログラムの内部には、なにもしていない部分があるかもしれない。 プロセスごとのアドレス空間は、ページ(という単位)に分割されている。カーネル は、どのプロセスのどのページが最も使われているかを絶えず監視している。ほと んど使われていないページは、スワップパーティションへと立ち退かせることがで きる。再度それが必要なときは、使われていない別のページをページアウトさせて、 空間を確保することが可能である。これを仮想記憶操作という。 <!--<P>If you have ever compiled your own Kernel, you will have noticed that there are many many options for specific devices. The kernel contains a lot of specific code to talk to diverse kinds of hardware, and present it all in a nice uniform way to the application programs.--> <p> カーネルをコンパイルしたことがあるなら、具体的なデバイスに関するオプションが 大量にあることに気付いただろう。カーネルには、多種多様なハードウェアと対話す るために大量の具体的なコードが含まれている。そしてアプリケーションプログラム に対しては、整然と統一された方法で、それら(へのアクセス手段)を提供する。 <!--<P>The Kernel also manages the filesystem, interprocess communication, and a lot of networking stuff.--> <p> カーネルは同時に、ファイルシステム、プロセス間通信、多くのネットワークプログ ラムなども管理している。 <!--<P>Once the kernel is loaded, the first thing it does is look for an <TT>init</TT> program to run.--> <p> いったんロードされたら、カーネルが行う最初の仕事は、<tt>init</tt> プログラムの 探知とその実行である。 <!--<SECT1>Configuration--> <SECT1> 設定 <!--<P>Most of the configuration of the kernel is done when you build it, using <TT>make menuconfig</TT>, or <TT>make xconfig</TT> in <TT>/usr/src/linux/</TT> (or wherever your Linux kernel source is). You can reset the default video mode, root filesystem, swap device and RAM disk size using <TT>rdev</TT>. These parameters and more can also be passed to the kernel from lilo. You can give lilo parameters to pass to the kernel either in lilo.conf, or at the lilo prompt. For example if you wanted to use hda3 as your root file system instead of hda2, you might type <VERB> LILO: linux root=/dev/hda3 </VERB>--> <p> カーネルソースのある場所、例えば <tt>/usr/src/linux</tt> において、 <tt>make menuconfig</tt> か <tt>make xconfig</tt> を使いカーネルをビルドすれ ば、設定の大部分は終了する。 ビデオモードやルートファイルシステム、スワップデバイス、また <tt>rdev</tt> を 使えば RAM のサイズについても、デフォルトの設定を変更することは可能である。 これらのパラメータ等は、<tt>lilo</tt> からカーネルに渡すこともできる。 <tt>lilo.conf</tt> ファイルに書くか、<tt>lilo</tt> プロンプトから入力すれば、 カーネルに渡すべき情報を <tt>lilo</tt> に取り次がせることができる。 例えば、<tt>hda2</tt> の代わりに <tt>hda3</tt> をルートファイルシステムとした いのであれば、以下のようにタイプすればよい。 <VERB> LILO: linux root=/dev/hda3 </VERB> <!--<P>If you are building a system from source, you can make life a lot simpler by creating a ``monolithic'' kernel. That is one with no modules. Then you don't have to copy kernel modules to the target system.--> <p> ソースコードからシステムを構築している場合、モノリシック(monolithic)なカーネ ルを作れば作業を単純化できる。これは、モジュールを持たないカーネルのことであ る。そうすれば構築中のシステムにカーネルモジュールをコピーする必要がなくなる。 <!--<P>NOTE: The <TT>System.map</TT> file is used by the kernel logger to determine the module names generating messages. The program <TT>top</TT> also uses this information. When you copy the kernel to the target system, copy <TT>System.map</TT> too.--> <p> 原注: <tt>System.map</tt> ファイルは、カーネルのログ記録プログラム (kernel logger)がどのモジュール名を使ってメッセージを出すか決定する際に使用さ れる。<tt>top</tt> というプログラムもこのファイルの情報を使う。 カーネルを目的のシステムにコピーするときは、<tt>System.map</tt> も一緒に コピーすること。 <!--<SECT1>Exercises--> <SECT1> 演習 <!--<P>Think about this: <TT>/dev/hda3</TT> is a special type of file that describes a hard disk partition. But it lives on a file system just like all other files. The kernel wants to know which partition to mount as the root filesystem - it doesn't have a file system yet. So how can it read <TT>/dev/hda3</TT> to find out which partition to mount? --> <p> 以下のことについて考えること: <tt>/dev/hda3</tt> は、ハードディスクのパーティ ションを表す特別な種類のファイルである。しかし、それは他の普通のファイルと全 く同じようにファイルシステム上に存在する。カーネルは、まだファイルシステムを 持たない段階で、どのパーテイションをルートファイルシステムとしてマウントする か知る必要がある。では、カーネルは、どういう方法でマウントすべきパーティション を突き止めて、 <tt>/dev/hda3</tt> を読み込むのか? <!--<P>If you haven't already: build your own kernel. Read all the help information for each option.--> <p> もしまだカーネル構築をしたことがないなら、自分のカーネルをビルドすること。 個々のオプションについてのヘルプ情報には全て目を通すこと。 <!--<P>See how small a kernel you can make that still works. You can learn a lot by leaving the wrong things out! --> <p> 驚くほど小さなカーネルを作っても動作することを確認すること。間違った思いこみ を捨てることで、多くを学べる。 <!--<P>Read ``The Linux Kernel'' (URL below) and as you do, find the parts of the source code that it refers to. The book (as I write) refers to kernel version 2.0.33, which is pretty out of date. It might be easier to follow if you download this old version and read the source there. Its amazing to find bits of C code called ``process'' and ``page''.--> <p> "The Linux Kernel" (URL は以下)を読むこと。読みながらそこで紹介されているソー スコードの一部を実際に見つけること。(この文書の執筆時において)そこでは、バー ジョン 2.0.33 のカーネルが取り上げられているが、そのバージョンはもうかなり時 代遅れになっている。その旧バージョンのカーネルソースをダウンロードしてから、 コードに目を通したほうが、読みやすいだろう。"process" や "page" と呼ばれる C のコード群を発見するのは面白いことだと思う。 <!--<P>Hack! See if you can make it spit out some extra messages or something.--> <p> ハックせよ! カーネルメッセージに何かを追加して、それを出力できるかどうか 確認すること。 <SECT1>参考文献等 <LABEL ID="Kernel"> <P> <ITEMIZE> <ITEM> <!--<TT>/usr/src/linux/README</TT> and the contents of <TT>/usr/src/linux/ Documentation/</TT> (These may be in some other place on your system)--> <tt>/usr/src/linux/README</tt> と <tt>/usr/src/linux/Documentation/</tt> の 中にある文書(システムによっては、違う場所にあるかもしれない) <ITEM> <URL URL="http://linuxdoc.org/HOWTO/Kernel-HOWTO.html" NAME="The Kernel HOWTO"> (<url url="http://www.linux.or.jp/JF/JFdocs/Kernel-HOWTO.html" name="日本語訳">) <ITEM> <!--The help available when you configure a kernel using <TT>make menuconfig </TT> or <TT>make xconfig</TT>--> <tt>make menuconfig</tt> や <tt>make xconfig</tt> を使ってカーネル設定をする 時のヘルプ情報 <ITEM> <!--<URL URL="http://mirror.aarnet.edu.au/linux/LDP/LDP/" NAME="The Linux Kernel"(and other LDP Guides)>--> <url url="http://www.linuxdoc.org/LDP/tlk/tlk.html" name="The Linux Kernel"> (<url url="http://www.linux.or.jp/JF/JFdocs/The-Linux-Kernel.html" name="日本語訳">) およびその他の <url url="http://www.linuxdoc.org/" name="LDP 文書">。<newline> <ITEM> <!--source code, see <URL URL="http://www.netspace.net.au/~gok/power2bash" NAME="Building a Minimal Linux System from Source Code"> for urls--> ソースコードについては、<url url="http://www.netspace.net.au/~gok/power2bash" name="Building a Minimal Linux System from Source Code"> (<url url="http://www.linux.or.jp/JF/JFdocs/Building-Minimal-Linux.html" name="日本語訳">) の URL の項目を見る こと。 </ITEMIZE> <!--###########################第五章 GNU C ライブラリ##################--> <!--<SECT>The GNU C Library--> <SECT> GNU C ライブラリ <!--<P>The next thing that happens as your computer starts up is that init is loaded and run. However, init, like almost all programs, uses functions from libraries.--> <p> コンピュータの起動において次に起こる出来事は、<tt>init</tt> プロセスがロード され実行されるということである。しかし、<tt>init</tt> は、他のほとんどのプロ グラムと同様にライブラリの関数を利用している。 <!--<P>You may have seen an example C program like this: <P> <VERB> main() { printf("Hello World!\n"); } </VERB>--> <p> 以下のような C プログラムの例題をみたことがあるかもしれない。 <P> <verb> main() { printf("Hello World!\n"); } </verb> <!--The program contains no definition of <TT>printf</TT>, so where does it come from? It comes from the standard C libraries, on a GNU/Linux system, glibc. If you compile it under Visual C++, then it comes from a Microsoft implementation of the same standard functions. There are zillions of these standard functions, for math, string, dates/times memory allocation and so on. Everything in Unix (including Linux) is either written in C or has to try hard to pretend it is, so everything uses these functions.--> <p> このプログラムでは、<tt>printf</tt> が定義されていないが、その定義はどこ から来るのか?それは標準 C ライブラリから、すなわち GNU/Linux システム上で あれば <tt>glibc</tt> から来る。 もし Visual C++ でコンパイルしたなら、同じ標準関数を持った Microsoft の実装か ら来る。このような標準関数は、計算、文字列、日付、メモリアロケーションなど 様々な領域で、無数に存在している。Linux を含む Unix の全ては、C 言語で書かれ たものと、なんとかして C で書かれたように見せかけようとするもののいずれかで出 来ているので、すべてがそうした関数を使用する。 <!--<P> If you look in <TT>/lib</TT> on your linux system you will see lots of files called <TT>libsomething.so</TT> or <TT>libsomething.a</TT> etc. They are libraries of these functions. Glibc is just the GNU implementation of these functions.--> <p> Linux システムの <tt>/lib</tt> を見れば、<tt>libxxx.so</tt> や <tt>libxxx.a </tt> といったファイルがたくさんあるのが分かるだろう。それらは、こうした関数 のライブラリである。<tt>glibc</tt> は、こうした関数についての GNU の実装であ る。 <!--<P>There are two ways programs can use these library functions. If you <EM>statically</EM> link a program, these library functions are copied into the executable that gets created. This is what the <TT>libsomething.a</TT> libraries are for. If you <EM>dynamically</EM> link a program (and this is the default), then when the program is running and needs the library code, it is called from the <TT>libsomething.so</TT> file.--> <p> ライブラリ関数を使う方法には二種類ある。静的(statically) にプログラムにリンク すれば、そうした関数はできあがった実行ファイルにコピーされて、組み込まれる。 動的(dynamically) にプログラムにリンクすれば(これが普通であるが)、プログラム が実行されてそのライブラリコードが必要になったときに、<tt>libxxx.so</tt> から 呼び出される。 <!--<P>The command <TT>ldd</TT> is your friend when you want to work out which libraries are needed by a particular program. For example, here are the libraries that <TT>bash</TT> uses: <P><VERB> [greg@Curry power2bash]$ ldd /bin/bash libtermcap.so.2 => /lib/libtermcap.so.2 (0x40019000) libc.so.6 => /lib/libc.so.6 (0x4001d000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) </VERB>--> <p> 特定のプログラムにどのライブラリが必要なのか調べたいときは、<tt>ldd</tt> コマンドが役に立つ。たとえば、以下は <tt>bash</tt> が使うライブラリである。 <P> <VERB> [greg@Curry power2bash]$ ldd /bin/bash libtermcap.so.2 => /lib/libtermcap.so.2 (0x40019000) libc.so.6 => /lib/libc.so.6 (0x4001d000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) </VERB> <!--<SECT1>Configuration--> <SECT1> 設定 <!--<P>Some of the functions in the libraries depend on where you are. For example, in Australia we write dates as dd/mm/yy, but Americans write mm/dd/yy. There is a program that comes with the <TT>glibc</TT> distribution called <TT>localedef</TT> which enables you to set this up.--> <p> ライブラリにある関数のいくつかは、あなたがどこに住んでいるかに依存している。 たとえば、オーストラリアなら、日付は 日/月/年と表記するが、アメリカでは、 月/日/年と表記する。<tt>glibc</tt> が配布されるときには <tt>localedef</tt> と呼ばれるプログラムが付属し、それによってこうしたことの設定ができるように なっている。 <!--<SECT1>Exercises--> <SECT1> 演習 <!--<P>Use <TT>ldd</TT> to find out what libraries your favourite applications use.--> <p> あなたの好きなプログラムがどんなライブラリを使っているのかを <tt>ldd</tt> で調べてみること。 <!--<P>Use <TT>ldd</TT> to find out what libraries <TT>init</TT> uses.--> <P> <tt>init</tt> がどんなライブラリを使うのか、<tt>ldd</tt> で調べること。 <!--<P>Make a toy library, with just one or two functions in it. The program <TT>ar</TT> is used to create them, the man page for <TT>ar</TT> might be a good place to start investigating how this is done. Write, compile and link a program that uses this library.--> <p> ひとつかふたつだけの関数が入ったおもちゃのライブラリを作ること。それを作るに は、<tt>ar</tt> というプログラムを使う。<tt>ar</tt> の man ページは、作り方を 調べる出発点になる。そして、そのライブラリを使うプログラムを書いて、コンパイ ルして、リンクすること。 <!--<SECT1>More Information--> <sect1>参考文献等 <P> <ITEMIZE> <ITEM> <!--source code, see <URL URL="http://www.netspace.net.au/~gok/power2bash" NAME="Building a Minimal Linux System from Source Code"> for urls--> ソースコードについては、<url url="http://www.netspace.net.au/~gok/power2bash" name="Building a Minimal Linux System from Source Code"> (<url url="http://www.linux.or.jp/JF/JFdocs/Building-Minimal-Linux.html" name="日本語訳">) で URL を確認すること。 </ITEMIZE> <!--###########################第六章 Init ###########################--> <!--<SECT>Init--> <SECT> Init <!--<P>I will only talk about the ``System V'' style of init that Linux systems mostly use. There are alternatives. In fact, you can put any program you like in <tt>/sbin/init</tt>, and the kernel will run it when it has finished loading.--> <p> ここでは、大部分の Linux システムで使用されている "System V" スタイルの <tt>init</tt> についてだけ話す。違うスタイルも存在する。実際、好きなプログラ ムを <tt>/sbin/init</tt> として置いておけば、カーネルはロードが終わった時に それを実行する。 <!--<P>It is <TT>init</TT>'s job to get everthing running the way it should be. It checks that the file systems are ok and mounts them. It starts up ``daemons'' to log system messages, do networking, serve web pages, listen to your mouse and so on. It also starts the getty processes that put the login prompts on your virtual terminals. --> <p> 全てのプログラムを的確に走らせるのが <tt>init</tt> の仕事である。ファイル システムに問題がないか確認し、それをマウントする。デーモン(daemons)プロセスを 起動することで、システムメッセージをログに記録し、ネットワークを監視し、ウェ ブページを提供し、マウスからの信号を受け取ったりする。また、仮想端末上にログ インプロンプトを出力する <tt>getty</tt> プロセスの起動も行う。 <!--<P>There is a whole complicated story about switching ``run-levels'', but I'm going to mostly skip that, and just talk about system start up.--> <p> 実行レベル(run-level)の変更については非常に複雑なはなしがあるが、大部分は飛ば して、システムの起動についてだけ説明しようと思う。 <!--<P>Init reads the file <TT>/etc/inittab</TT>, which tells it what to do. Typically, the first thing it is told to do is to run an initialisation script. The program that executes (or interprets) this script is <TT>bash</TT>, the same program that gives you a command prompt. In Debian systems, the initialisation script is <TT>/etc/init.d/rcS</TT>, on Red Hat, <TT>/etc/rc.d/rc.sysinit</TT>. This is where the filesystems get checked and mounted, the clock set, swap space enabled, hostname gets set etc. --> <p> <tt>init</tt> は、<tt>/etc/inittab</tt> というファイルを読み込む。このファイ ルが <tt>init</tt> に仕事の内容を伝える。一般的には、伝えられる最初の仕事は 初期化スクリプトを走らせることである。このスクリプトを実行する(あるいは解釈 する)プログラムが、<tt>bash</tt> であり、これは、コマンドプロンプトを出力する プログラムと同一のものだ。Debian のシステムでは、初期化スクリプトは <tt>/etc/init.d/rcS</tt> であり、Red Hat では <tt>/etc/rc.d/rc.sysinit</tt> である。この過程で、ファイルシステムの検証とマウント、日時の設定、スワップス ペースの稼働、ホスト名の設定などが行われる。 <!--<P>Next, another script is called to take us into the default run-level. This just means a set of subsystems to start up. There is a set of directories <TT>/etc/rc.d/rc0.d</TT>, <TT>/etc/rc.d/rc1.d</TT>, ..., <TT>/etc/rc.d/rc6.d</TT> in Red Hat, or <TT>/etc/rc0.d</TT>, <TT>/etc/rc1.d</TT>, ..., <TT>/etc/rc6.d</TT> in Debian, which correspond to the run-levels. If we are going into runlevel 3 on a Debian system, then the script runs all the scripts in <TT>/etc/rc3.d</TT> that start with `S' (for start). These scripts are really just links to scripts in another directory usually called <TT>init.d</TT>. --> <p> 次にもうひとつのスクリプトが呼び出されて、デフォルトの実行レベルにシステムを移 行させる。これは一連のサブシステムが起動されるという意味である。これに関して は、ディレクトリのセットが存在する。例えば Red Hatでは、 <tt>/etc/rc.d/rc0.d</tt>, <tt>/etc/rc.d/rc1.d</tt>, ..., <tt>/etc/rc.d/rc6.d</tt> といったものがあり、Debian では、 <tt>/etc/rc0.d</tt>, <tt>/etc/rc1.d</tt>, ..., <tt>/etc/rc6.d</tt> となっている。これらのディレクトリは、実行レベルに対応していて、Debian の システムで実行レベル <tt>3</tt> に移行しようとするなら、そのスクリプトは <tt> /etc/rc3.d</tt> にある '<tt>S</tt>'(start のこと) で始まる全てのスクリプト群 を実行する。実際には、これらのスクリプト群は、通常 <tt>init.d</tt> と呼ばれる 別のディレクトリにあるスクリプトへの単なるリンクである。 <!--<P>So our run-level script was called by <TT>init</TT>, and it is looking in a directory for scripts starting with `S'. It might find <TT>S10syslog</TT> first. The numbers tell the run-level script which order to run them in. So in this case <TT>S10syslog</TT> gets run first, since there were no scripts starting with S00 ... S09. But <TT>S10syslog</TT> is really a link to <TT>/etc/init.d/syslog</TT> which is a script to start and stop the system logger. Because the link starts with an `S', the run-level script knows to execute the <TT>syslog</TT> script with a ``start'' parameter. There are corresponding links starting with `K' (for kill), which specify what to shut down and in what order when leaving the run-level.--> <p> これらの実行レベルに関するスクリプトは、<tt>init</tt> から呼び出され、ディレ クトリ内にある頭文字が S のスクリプトを探す。(例えば)最初に見つけたのが、<tt> S10syslog</tt> であるとしよう。付けられた数字は実行レベルスクリプトにどういう 順番で実行していくかを伝える。このケースでは、<tt>S00 ... S09</tt> で始まるス クリプトがないので、<tt>S10syslog</tt> が最初に実行される。ただ、 <tt>S10syslog</tt> は実際には <tt>/etc/init.d/syslog</tt> へのリンクにすぎ ず、システムのログ記録プログラム(system logger)を開始したり停止したりしている のは後者のスクリプトである。 リンク(名)が <tt>S</tt> で始まるので、実行レベルスクリプトは <tt>syslog</tt> スクリプトを '<tt>start</tt>' のパラメータを付けて実行すべきことを知る。それ に対応する '<tt>K</tt>'(kill のこと)で始まるリンクも存在し、それによって実行 レベルの変更時に何をどういう順番で終了させるかが指定される。 <!--<P>To change what subsystems start up by default, you must set up these links in the <TT>rcN.d</TT> directory, where N is the default runlevel set in your <TT>inittab</TT>.--> <p> デフォルトで起動するサブシステムを変更するには、<tt>rcN.d</tt> ディレクトリ にあるそうしたリンクを設定し直さなければならない。ここで <tt>N</tt> とは、 <tt>inittab</tt> で設定した実行レベルのことである。 <!--<P>The last important thing that init does is to start some <TT>getty</TT>'s. These are ``respawned'' which means that if they stop, <TT>init</TT> just starts them again. Most distributions come with six virtual terminals. You may want less than this to save memory, or more so you can leave lots of things running and quickly flick to them as you need them. You may also want to run a <TT>getty</TT> for a text terminal or a dial in modem. In this case you will need to edit the <TT>inittab</TT> file.--> <p> <tt>init</tt> が最後に行う重要な仕事は、<tt>getty</tt> をいくつか起動すること である。彼らは、"何度でも生き返る(respawned)" 設定になっている。つまり、もし 止まっても <tt>init</tt> がまたそれらを再起動させるのである。 大部分のディストリビューションは 6 個の仮想端末を用意する。メモリを節約するた めにその数を少なくしたいかもしれないし、たくさん走らせておいて必要なときにす ばやく使うため、その数を増やしたいかもしれない。また、文字端末かモデムでの通 信用に <tt>getty</tt> をひとつだけ実行したいのかもしれない。そうした場合は、 <tt>inittab</tt> ファイルを編集する必要が生じる。 <!--<SECT1>Configuration--> <SECT1> 設定 <!--<P><TT>/etc/inittab</TT> is the top level configuration file for init.--> <p> <tt>/etc/inittab</tt> は、init のトップレベルの設定ファイルである。 <!--<P>The <TT>rcN.d</TT> directories, where N = 0, 1, ..., 6 determine what subsystems are started.--> <p> <TT>rcN.d</TT> ディレクトリにおいて、N には 1 から 6 までの数字が入るが、それ らのディレクトリ(の内容)が、起動されるサブシステムを決めている。 <!--<P>Somewhere in one of the scripts invoked by init, the <TT>mount -a</TT> command will be issued. This means mount all the file systems that are supposed to be mounted. The file <TT>/etc/fstab</TT> defines what is supposed to be mounted. If you want to change what gets mounted where when your system starts up, this is the file you will need to edit. There is a man page for <TT>fstab</TT>.--> <p> init から呼び出されるあるスクリプトの内部で、<TT>mount -a</TT> コマンドが 実行される。これは、マウントされるよう定められた全てのファイルシステムをマウ ントすることを意味する。何がマウントされるべきかは、<TT>/etc/fstab</TT> ファイルで定められている。システム起動時になにをどこにマウントするかを変更した いなら、編集すべきファイルはこれである。<TT>fstab</TT> の man ページがあるの でみてほしい。 <!--<SECT1>Exercises--> <SECT1> 演習 <!--<P>Find the <TT>rcN.d</TT> directory for the default run-level of your system and do a <TT>ls -l</TT> to see what the files are links to.--> <p> システムのデフォルト実行レベルに相当する <TT>rcN.d</TT> ディレクトリを 見つけて、そこで <TT>ls -l</TT> と打つことでファイルがどこにリンクされ ているかを理解すること。 <!--<P>Change the number of gettys that run on your system.--> <p> システム上で実行している <tt>getty</tt> の数を変更すること。 <!--<P>Remove any subsystems that you don't need from your default run-level.--> <p> 不要なサブシステムをデフォルト実行レベルから取り除くこと。 <!--<P>See how little you can get away with starting.--> <p> ほとんどなにもない状態からでもスタートできることを確認すること。 <!--<P>Set up a floppy disk with lilo, a kernel and a statically linked "hello world" program called <TT>/sbin/init</TT> and watch it boot up and say hello.--> <p> フロッピーディスク上に、<tt>lilo</tt> とカーネルを構築し、さらに静的にリンク されたおもちゃのプログラム("hello world program")を置いて、それが <TT>/sbin/init</TT> から呼び出されるように設定しておくこと。 そのディスクが起動して、プログラムの実行結果が表示されるのを確認すること。 <!--<P>Watch carefully as your system starts up, and take notes about what it tells you is happening. Or print a section of your system log <TT>/var/log/messages</TT> from start up time. Then starting at <TT>inittab</TT>, walk through all the scripts and see what code does what. You can also put extra start up messages in, such as <verb> echo "Hello, I am rc.sysinit" </verb> This is a good exercise in learning Bash shell scripting too, some of the scripts are quite complicated. Have a good Bash reference handy.--> <p> システムが起動するときの画面を注意深く観察し、起きている事柄についてメモを とること。あるいは、<TT>/var/log/messages</TT> にあるシステムログの起動時 からの部分をプリントすること。次に、<TT>inittab</TT> ファイルを出発点にして すべてのスクリプトに目を通し、どのコードが何をしているか理解すること。 また、以下のように書き込むと、出るはずのないスタートアップメッセージを付け 加えることができる。 <verb> echo "Hello, I am rc.sysinit" </verb> これは <tt>bash</tt> を使ったシェルスクリプトのよい練習にもなる。スクリプトの いくつかは非常に複雑である。良くできたハンディな <tt>bash</tt> のリファレンス ブックを手元に置いておこう。 <!--<SECT1>More Information--> <SECT1>参考文献等 <P> <ITEMIZE> <ITEM> <!--There are man pages for the <TT>inittab</TT> and <TT>fstab</TT> files. Type (eg) <TT>man inittab</TT> into a shell to see it.--> <tt>inittab</tt> と <tt>fstab</tt> ファイルにはマニュアルページがある。 シェル画面で <tt>man inittab</tt> とタイプして、それを見ること。 <ITEM> <!--The Linux System Administrators Guide has a good <URL URL="http://mirror.aarnet.edu.au/linux/LDP/LDP/" NAME="section"> on init.--> "The Linux System Administrators Guide" の <tt>init</tt> に関する章はよく書か れている。 <url url="http://www.linuxdoc.org/LDP/sag/index.html" name="ここ">で読める。 <ITEM> <!--source code, see <URL URL="http://www.netspace.net.au/~gok/power2bash" NAME="Building a Minimal Linux System from Source Code"> for urls--> ソースコードについては、<url url="http://www.netspace.net.au/~gok/power2bash" name="Building Minimal Linux System from Source Code"> (<url url="http://www.linux.or.jp/JF/JFdocs/Building-Minimal-Linux.html" name="日本語訳">)で URL を確認すること。 <item> (訳注)JF 文書に <url url="http://www.linux.or.jp/JF/JFdocs/readkernel.html" name="「コメントから読む Linux カーネル」">があります。Linux の起動に関し、 詳細に解説されています。 </ITEMIZE> <!--##############################第七章 ファイルシステム##############--> <!--<SECT>The Filesystem--> <SECT> ファイルシステム <!--<P>In this section, I will be using the word ``filesystem'' in two different ways. There are filesystems on disk partitions and other devices, and there is the filesystem as it is presented to you by a running Linux system. In Linux, you ``mount'' a disk filesystem onto the system's filesystem.--> <p> この章では、「ファイルシステム」という言葉をふたつの違った意味で使用する。 ディスクパーティションやその他のデバイス上のファイルシステムがひとつ、 Linux システムを走らせることで提示されるファイルシステムがひとつである。 Linux では、ディスクのファイルシステムをシステムのファイルシステム上に マウント(mount)している。 <!--<P>In the previous section I mentioned that init scripts check and mount thefilesystems. The commands that do this are <TT>fsck</TT> and <TT>mount</TT> respectively.--> <p> 前章では、<tt>init</tt> スクリプトがファイルシステムをチェックしてマウントす ると述べた。これを実行するコマンドは、それぞれ <TT>fsck</TT> と <TT>mount</TT> である。 <!--<P>A hard disk is just a big space that you can write ones and zeros on. A filesystem imposes some structure on this, and makes it look like files within directories within directories... Each file is represented by an inode, which says who's file it is, when it was created and where to find its contents. Directories are also represented by inodes, but these say where to find the inodes of the files that are in the directory. If the system wants to read <TT>/home/greg/bigboobs.jpeg</TT>, it first finds the inode for the root directory <TT>/</TT> in the ``superblock'', then finds the inode for the directory <TT>home</TT> in the contents of <TT>/</TT>, then finds the inode for the directory <TT>greg</TT> in the contents of <TT>/home</TT>, then the inode for <TT>bigboobs.jpeg</TT> which will tell it which disk blocks to read.--> <p> ハードディスクは 1 と 0 を書き込める巨大な空間にすぎない。ファイルシステム がそれにかたち(structure)を与え、ディレクトリ構造をもったファイル群に見えるよ うにしている。個々のファイルは、i-node によって表わされる。i-node は、誰の ファイルか、いつ作られたのか、ファイルの中身はどこにあるのかといった情報を伝 える。 ディレクトリも i-node で表現されているが、その i-node は、当該ディレクトリに あるファイルの i-node がどこにあるかという情報しか伝えない。システムが <TT> /home/greg/bigboobs.jpg</TT> というファイルを読み込もうとすると、まず最初に ルートディレクトリである <TT>/</TT> の i-node を「スーパーブロック(super block)」から探しだす。次にディレクトリ <TT>home</TT> の i-node を <TT>/</TT> の内容のなかから探す。そして、ディレクトリ <TT>greg</TT> を <TT>/home</TT> の 内容から見つけだして、さらに <TT>bigboobs.jpg</TT> の i-node を見つける。そう して、その i-node がシステムにどのディスクブロックを読めばいいかを教えるわけ である。 <!--<P>If we add some data to the end of a file, it could happen that the data is written before the inode is updated to say that the new blocks belong to the file, or vice versa. If the power cuts out at this point, the filesystem will be broken. It is this kind of thing that <TT>fsck</TT> attempts to detect and repair.--> <p> ファイルの末尾にデータを付け加えた場合、新しいブロックがそのファイルの一部で あると伝達できる状態にするため、i-node の更新がなされる。しかし、その更新がな される前に、データが書き込まれてしまうことがあるし、その逆もある。もしその時 点で電源が落ちると、ファイルシステムは整合性を失う。<TT>fsck</TT> が検出し補 修しようとするのは、この種の事柄である。 <!--<P>The mount command takes a filesystem on a device, and adds it to the heirarchy that you see when you use your system. Usually, the kernel mounts its root file system read-only. The mount command is used to remount it read- write after <TT>fsck</TT> has checked that it is ok.--> <p> マウントコマンドはデバイス上のファイルシステムを把握し、システムを利用する時 に目にするようなファイルの階層構造(hierarchy)にそれを付け加える。カーネルは、 通常ルートファイルシステムを読み込み専用(read-only)でマウントする。マウントコ マンドは、<TT>fsck</TT> の検査で問題のないことが分かってからそれを読み書き兼 用(read-write)でマウントし直す。 <!--<P>Linux supports other kinds of filesystem too: msdos, vfat, minix and so on. The details of the specific kind of filesystem are abstracted away by the virtual file system (VFS). I won't go into any detail on this though. There is a discussion of it in ``The Linux Kernel'' (see section <REF ID="Kernel" NAME="The Linux Kernel"> for a url)--> <p> Linux は他の種類のファイルシステムもサポートしている。<tt>msdos</tt>, <tt>vfat</tt>,<tt>minix</tt> などである。 具体的なファイルシステム間での区々の相違は、仮想ファイルシステム(VFS)に よって抽象化される。ここではその詳細については触れない。それについての解説は "The Linux Kernel" の文中にある。(<ref id="Kernel" name="Linux カーネル"> の章に URL があるのでそこで見てほしい。) <!-- A completely different kind of filesystem gets mounted on <TT>/proc</TT>. It is really a representation of things in the kernel. There is a directory there for each process running on the system, with the process number as the directory name. There are also files such as <TT>interrupts</TT>, and <TT>meminfo</TT> which tell you about how the hardware is being used. You can learn a lot by exploring <TT>/proc</TT>.--> <p> さらに、<tt>/proc</tt> には完全に種類の異なるファイルシステムがマウントされて いる。これは、カーネル内の状況を忠実に表すものである。そこには、システム上の プロセスごとにディレクトリがあり、ディレクトリ名としてプロセス番号が付けられ ている。また、<tt>/proc</tt> には <tt>interrupts</tt> や <tt>meminfo</tt> と いったファイルもあり、そこにはハードウェアの利用情報が書かれている。<tt>/proc </tt> を詳しく調べれば、多くを学ぶことができる。 <!--<SECT1>Configuration--> <sect1>設定 <!--<P>There are parameters to the command <TT>mke2fs</TT> which creates ext2 filesystems. These control the size of blocks, the number of inodes and so on. Check the <TT>mke2fs</TT> man page for details.--> <p> ext2 ファイルシステムを作る <TT>mke2fs</TT> というコマンドには複数のパラメー タがある。それを使えば、ブロックのサイズや i-node の数などを設定できる。 詳細は、<TT>mke2fs</TT> のマニュアルページを調べてほしい。 <!--<P>What gets mounted where on your filesystem is controlled by the <TT>/etc/fstab</TT> file. It also has a man page. --> <p> ファイルシステム上のどこに何がマウントされるかは、<TT>/etc/fstab</TT> で 管理されている。このファイルのマニュアルページもある。 <!--<SECT1>Exercises--> <SECT1> 演習 <!--<P>Make a very small filesystem, and view it with a hex viewer. Identify inodes, superblocks and file contents.--> <p> 非常に小さなファイルシステムを作って、hex ビューワで見てみること。 i-node や スーパーブロック、ファイルの中身がどれなのか見分けること。 <!--<P>I believe there are tools that give you a graphical view of a filesystem. Find one, try it out, and email me the url and a review!--> <p> ファイルシステムをグラフィカルに見ることができるツールがあるはずだと思う。 それを見つけて試してみたら、その URL と使った感想をわたしにメールで教えて ほしい。(訳注: <url url="http://tanaka-www.cs.titech.ac.jp/%7Eeuske/prog/" name="xcruise"> というのがあります。) <!--<P>Check out the ext2 filesystem code in the Kernel.--> <p> カーネルの ext2 ファイルシステムのコードをチェックすること。 <!--<SECT1>More Information--> <SECT1>参考文献等 <P> <ITEMIZE> <ITEM> <!--Chapter 9 of the LDP book ``The Linux Kernel'' is an excellent description of filesystems. You can find it at the Australian LDP <URL URL="http://mirror.aarnet.edu.au/linux/LDP/LDP/" NAME="mirror">--> LDP の文書である <url url="http://www.linuxdoc.org/LDP/tlk/tlk.html" name="The Linux Kernel"> の第九章 (<url url="http://www.linux.or.jp/JF/JFdocs/The-Linux-Kernel-10.html" name="日本語訳">)には、ファイルシステムに関する優 れた記述がある。オーストラリアの LDP にその文書がある。 <url url="http://mirror.aarnet.edu.au/linux/LDP/LDP/" name="mirror"> <ITEM> <!--The <TT>mount</TT> command is part of the util-linux package, there is a link to it in <URL URL="http://www.netspace.net.au/~gok/power2bash" NAME="Building a Minimal Linux System from Source Code">--> <tt>mount</tt> コマンドは <tt>util-linux</tt> パッケージの一部であり、これに 関するリンクが <url url="http://www.netspace.net.au/~gok/power2bash" name="Building a Minimal Linux System from Source Code"> (<url url="http://www.linux.or.jp/JF/JFdocs/Building-Minimal-Linux.html" name="日本語訳">)からたどれる。 <ITEM> <!--man pages for-->次のコマンドのマニュアルページ<newline> <TT>mount</TT>, <TT>fstab</TT>, <TT>fsck</TT>, <TT>mke2fs</TT> および、 <tt>proc</tt>。 <ITEM> <!--The file <TT>Documentation/proc.txt</TT> in the Linux source code explains the <TT>/proc</TT> filesystem.--> Linux カーネルのソースコードにある <tt>Documentation/proc.txt</tt> ファイル (<url url="http://www.linux.or.jp/JF/JFdocs/kernel-docs-2.2/proc.txt.html" name="日本語訳">)に、<tt>/proc</tt> ファイルシステムについての説明がある。 <ITEM> <!--EXT2 File System Utilities <URL URL="http://web.mit.edu/tytso/www/linux/e2fsprogs.html" NAME="ext2fsprogs"> home page <URL URL="ftp://mirror.aarnet.edu.au/pub/linux/metalab/system/filesystems/ext2/" NAME="ext2fsprogs"> Australian mirror. --> EXT2 ファイルシステムのユーティリティに関するホームページは <url url="http://web.mit.edu/tytso/www/linux/e2fsprogs.html" name="こちら"> <newline> オーストラリアのミラーは<url url="ftp://mirror.aarnet.edu.au/pub/linux/ metalab/system/filesystems/ext2/" name="こちら"><newline> <!--There is also a Ext2fs-overview document here, although it is out of date, and not as readable as chapter 9 of ``The Linux Kernel''--> Ext2fs-overview というドキュメントもそこにあるが、情報が古く、 "The Linux Kernel" の第九章ほどは読みやすくない。 <ITEM><LABEL ID="FHS"> <URL URL="ftp://tsx-11.mit.edu/pub/linux/docs/linux-standards/fsstnd/" NAME="Unix File System Standard"> <!--Another <URL URL="http://www.pathname.com/fhs/" NAME="link"> to the Unix File System Standard.--><newline> 上記以外の Unix File System Standard へのリンクは <url url="http://www.pathname.com/fhs/" name="ここ"><newline> (訳注: 14.2 での Filesystem Hierarchy Standard(FHS) という文献は上記にあります) <!--This describes what should go where in a Unix file system, and why. It also has minimum requirements for the contents of <TT>/bin</TT>, <TT>/sbin</TT> and so on. This is a good reference if your goal is to make a minimal yet complete system.--> <p> 上記では、Unix のファイルシステムで何が起こっていて、なぜそうなのかが述べられ ている。また、<tt>/bin</tt>, <tt>/sbin</tt> などに最低限度入れておくべき 内容について書かれている。もし自分で最小だが完全なシステムを構築しようと しているなら、これはとても参考になる。 </ITEMIZE> <!--########################第八章 カーネルデーモン#####################--> <!--<SECT>Kernel Daemons--> <SECT> カーネルデーモン <!--<P>If you issue the <TT>ps aux</TT> command, you will see something like the following:--> <p> <TT>ps aux</TT> コマンドを実行すると、以下に示すようなものが現れる。 <P> <VERB> USER PID %CPU %MEM SIZE RSS TTY STAT START TIME COMMAND root 1 0.1 8.0 1284 536 ? S 07:37 0:04 init [2] root 2 0.0 0.0 0 0 ? SW 07:37 0:00 (kflushd) root 3 0.0 0.0 0 0 ? SW 07:37 0:00 (kupdate) root 4 0.0 0.0 0 0 ? SW 07:37 0:00 (kpiod) root 5 0.0 0.0 0 0 ? SW 07:37 0:00 (kswapd) root 52 0.0 10.7 1552 716 ? S 07:38 0:01 syslogd -m 0 root 54 0.0 7.1 1276 480 ? S 07:38 0:00 klogd root 56 0.3 17.3 2232 1156 1 S 07:38 0:13 -bash root 57 0.0 7.1 1272 480 2 S 07:38 0:01 /sbin/agetty 38400 tt root 64 0.1 7.2 1272 484 S1 S 08:16 0:01 /sbin/agetty -L ttyS1 root 70 0.0 10.6 1472 708 1 R Sep 11 0:01 ps aux </VERB> <!--<P>This is a list of the processes running on the system. The information comes from the <TT>/proc</TT> filesystem that I mentioned in the previous section. Note that <TT>init</TT> is process number one. Processes 2, 3, 4 and 5 are kflushd, kupdate, kpiod and kswapd. There is something strange here though: notice that in both the virtual storage size (SIZE) and the Real Storage Size (RSS) columns, these processes have zeroes. How can a process use no memory?--> <p> 上記はシステム上で動いているプロセスのリストである。これらの情報は、前章で説明 した <tt>/proc</tt> ファイルシステムから取得される。<TT>init</TT> のプロセス ID が 1 であることに注意してほしい。プロセス ID の 2,3,4 と 5 は、それぞれ <tt>kflushd</tt>, <tt>kupdate</tt>, <tt>kpiod</tt>, そして <tt>kswapd</tt> である。しかしこれには奇妙な点がある。仮想ストレージサイズ(SIZE)とリアルスト レージサイズ(RSS)の行に注目すると、これらのプロセスのサイズはゼロとなっている。 プロセスがメモリを消費しないことが起こりうるだろうか? <!--<P> These processes are the kernel daemons. Most of the kernel does not show up on process lists at all, and you can only work out what memory it is using by subtracting the memory available from the amount on your system. The kernel daemons are started after init, so they get process numbers like normal processes do. But their code and data lives in the kernel's part of the memory. --> <p>これらのプロセスは、カーネルデーモンである。カーネルの大部分はプロセス リストには現れないので、それらが消費するメモリの量を割り出すには、システムの 総メモリ量から利用可能なメモリ量を引いて計算するしかない。カーネルデーモンは、 <tt>init</tt> の後で起動されるため、通常のプロセスと同様にプロセス番号を持つ。 しかし、それらのコードとデータは、カーネル用のメモリ領域に置かれる。 <!--<P> There are brackets around the entries in the command column because the <TT>/proc</TT> filesystem does not contain command line information for these processes. --> 上記の表では <tt>COMMAND</tt> の行に丸カッコがついているエントリがあるが、 これは、<tt>/proc</tt> ファイルシステムに、それらのプロセスのコマンドライン 情報が含まれていないからである。 <!--<P> So what are these kernel daemons for? Previous versions of this document had a plea for help, as I didn't know much about the kernel daemons. The following partial story has been patched together from various replies to that plea, for which I am most grateful. Further clues, references and corrections are most welcome! --> では、カーネルデーモンは何のためにあるのか? わたしはカーネルデーモンについて ほとんど知らなかったので、今回の改訂版を出すまで、その点に関し、この文書では 読者からの教えを請うていた。以下の断片的な説明は、読者からの様々な返答を つなぎ合わせたものであり、疑問に答えてくれたひとたちには非常に感謝している。 より詳しい手がかりや参照先、この文の訂正なども引き続き歓迎している。 <!--<P> Input and output is done via <em>buffers</em> in memory. This allows things to run faster. What programs write can be kept in memory, in a buffer, then written to disk in larger more efficient chunks. The daemons <TT>kflushd</TT> and <TT>kupdate</TT> handle this work: <TT>kupdate</TT> runs periodically (5 seconds?) to check whether there are any dirty buffers. If there are, it gets <TT>kflushd</TT> to flush them to disk. --> <p>入力と出力は、メモリ内の <em>buffers</em> 経由で行われる。実行速度を上げる ためである。プログラムの出力は一旦メモリに、つまりバッファに蓄えられ、その後で より安価で大容量を実現できるディスクに書き込まれる。<tt>kflushd</tt> と <tt>kupdate</tt> デーモンは、この処理を担当している。<tt>kupdate</tt> は、 定期的に(5 秒ごとに?)書き込まれたバッファ(dirty buffer)がないかチェック する。そうしたバッファがある場合、<tt>kflushd</tt> を呼び出して、それを ディスクに書き込ませる。 <!--<P> Processes often have nothing to do, and ones that are running often don't need all of their code and data in memory. This means we can make better use of our memory, by shifting unused parts of running programs out to the swap partition(s) of the hard disk. Moving this data in and out of memory as needed is done by <TT>kpiod</TT> and <TT>kswapd</TT>. Every second or so, <TT>kswapd</TT> wakes up to check out the memory situation, and if something out on the disk is needed in memory, or there is not enough free memory, <TT>kpiod</TT> is called in. --> <p>プロセスは、何もしていない状態になることがしばしばあり、実行中のプロセスと いえどもそのコードとデータ全部をメモリ内に置く必要があるわけではない。すなわ ちこれは、実行中のプロセスの使用されていない部分を、ハードディスクのスワップ パーティションに移すことで、メモリを有効利用できることを意味する。 必要に応じてそうしたデータをメモリから出し入れする処理は、<tt>kpiod</tt> と <tt>kswapd</tt> によって行われる。ほぼ毎秒、<tt>kswapd</tt> が起動し、 メモリの状態をチェックする。そして、ディスクに書き出された情報をメモリに 戻す必要があったり、空きメモリの量が不足していたりする場合、<tt>kpiod</tt> が呼び出される。 <!--<P> There might also be a <TT>kapmd</TT> daemon running on your system if you have configured automatic power management into your kernel. --> <p>また、カーネルに省電力機能を組み込んでいる場合は、システム上で <tt>kapmd </tt> デーモンが走っているかもしれない。 <!--<P><SECT1>Configuration--> <P><SECT1> 設定 <!--<P> The program <TT>update</TT> allows you to configure <TT>kflushd</TT> and <TT> kswapd</TT>. Try <TT>update -h</TT> for some information. --> <p><tt>update</tt> プログラムを使えば、<tt>kflushd</tt> と <tt>kswapd</tt> を 設定することができる。コマンド <tt>update -h</tt> を使えば詳しい情報が 表示される。 <!--<P> Swap space is turned on by <TT>swapon</TT> and off by <TT>swapoff</TT>. The init script (<TT>/etc/rc.sysinit</TT> or <TT>/etc/rc.d/rc.sysinit</TT>) usually calls <TT>swapon</TT> as the system is coming up. I'm told that <TT>swapoff</TT> is handy for saving power on laptops. --> <p>スワップ空間は、<tt>swapon</tt> コマンドで有効になり、<tt>swapoff</tt> コマンドで無効になる。初期化スクリプト(<tt>/etc/rc.sysinit</tt> もしくは <tt>/etc/rc.d/rc.sysinit</tt>)は、通常、システム起動時に <tt>swapon</tt> を 呼び出す。<tt>swapoff</tt> は、ラップトップ上での消費電力節約のために有効で あるそうだ。 <!--<SECT1>Exercises--> <SECT1> 演習 <!--<P> Do an <TT>update -d</TT>, note the blatherings on the last line about ``threshold for buffer fratricide''. Now there's an intriguing concept, go investigate! --> <p><tt>update -d</tt> と打ち、表示された行の最後に「兄弟バッファ殺し の閾値(threshold for buffer fratricide)」と書かれていることに注目せよ。 面白そうな概念である。調べてみよう! <!--<P> Change directory to <TT>/proc/sys/vm</TT> and <TT>cat</TT> the files there. See what you can work out. --> <p><tt>/proc/sys/vm</tt> ディレクトリに行き、そこにあるファイルの内容を <tt> cat</tt> で出力し、出力結果を見ること。 <!--<SECT1>More Information--> <SECT1>参考文献等 <P> <!--The Linux Documentation Project's ``The Linux Kernel'' (see section <REF ID="Kernel" NAME="The Linux Kernel"> for a url) --> <p>Linux Documentation Project の "The Linux Kernel" ( URL については、<ref id="Kernel" name="ここ">を見ること。) <!--<P> The Linux kernel source code, if you are brave enough! The <TT>kswapd</TT> code is in <TT>linux/mm/vmscan.c</TT>, and <TT>kflushd</TT> and <TT>kupdate</TT> are in <TT>linux/fs/buffer.c</TT>. --> <p>勇気ある読者は、Linux カーネルのソースコードを読むこと。 <tt>kswapd</tt> のコードは、<tt>linux/mm/vmscan.c</tt> にあり、 <tt>kflushd</tt> と <tt>kupdate</tt> のコードは <tt>linux/fs/buffer.c</tt> にある。 <!--#######################第九章 システムログ########################--> <!--<SECT>System Logger--> <SECT> システムのログ記録 <!-- <P>Init starts the <TT>syslogd</TT> and <TT>klogd</TT> daemons. They write messages to logs. The kernel's messages are handled by <TT>klogd</TT>, while <TT>syslogd</TT> handles log messages from other processes. The main log is <TT>/var/log/messages</TT>. This is a good place to look if something is going wrong with your system. Often there will be a valuable clue in there. --> <P> <tt>init</tt> は、<tt>syslogd</tt> と <tt>klogd</tt> をスタートさせる。 それらは、メッセージをログに書き取る。カーネルのメッセージは、<tt>klogd</tt> が書き取り、<tt>syslogd</tt> は、その他のプロセスのメッセージを扱う。 主要なログは、<tt>/var/log/messages</tt> にある。システムの調子が悪いとき、 このログをのぞくとよい。ここにはよく重要な手がかりがある。 <!-- <SECT1>Configuration --> <sect1> 設定 <!-- <P>The file <TT>/etc/syslog.conf</TT> tells the loggers what messages to put where. Messages are identified by which service they come from, and what priority level they are. This configuration file consists of lines that say messages from service x with priority y go to z, where z is a file, tty, printer, remote host or whatever. --> <p> <tt>/etc/syslog.conf</tt> ファイルは、ログプログラムに対して、どういうメッ セージをどこに出力するかを伝える。メッセージは、どのサービスから送られた のか、どのプライオリティレベルにそれらがあるのかということによって識別され る。この設定ファイルは、行単位に構成されていて、そこには、サービス x が、 プライオリティ y で、メッセージを z に出力するということが書かれている。ここ での z には、ファイルや tty やプリンタ、リモートホスト等がある。 <!-- <P>NOTE: Syslog requires the <TT>/etc/services</TT> file to be present. The services file allocates ports. I am not sure whether syslog needs a port allocated so that it can do remote logging, or whether even local logging is done through a port, or whether it just uses <TT>/etc/services</TT> to convert the service names you type <TT>/etc/syslog.conf</TT> into port numbers. --> <p> 注意:<tt>syslog</tt> は、<tt>/etc/services</tt> ファイルの存在を必要とする。 この <tt>services</tt> というファイルにはポート(port)の割り当てのことが書かれ ている。<tt>syslog</tt> がポートの割り当てを知る必要があるのは、リモートログ を取るためなのか、それともローカルログを取るときにもポートを経由しているの か、あるいは、<tt>/etc/services</tt> は <tt>/etc/syslog.conf</tt> に記述され たサービス名をポート番号に変換するためにだけ使われるのかは、わたしにはよく分 からない。 <!--リモートログを取るために、syslog がポートの割付を知る必要があるのか、それ ともローカルログを取るにもポートを経由しているのか、あるいは、 <tt>/etc/syslog.conf</tt> ファイルに書かれたサービス名をポート番号に変換 するためだけに使うのかは、わたしにはよく分からない。--> <!-- <SECT1>Exercises --> <sect1> 演習 <P> <!--Have a look at your system log. Find a message you don't understand, and find out what it means.--> 自分のシステムのログを見ること。理解できない部分を探して、その意味を調べる こと。 <P> <!--Send all your log messages to a tty. (set it back to normal once done)--> 全てのログメッセージを端末に表示させること。(それが終わったら、元に戻すこと) <!--<SECT1>More Information--> <sect1>参考文献等 <!--<P>Australian sysklogd--> <p>オーストラリアの <tt>syslogd</tt> の <URL URL="http://mirror.aarnet.edu.au/pub/linux/metalab/system/daemons/" NAME="Mirror"> (訳注:<url url="http://metalab.unc.edu/pub/Linux/system/daemons" name="こちら">にもあります) <!--#########################第十章 Getty とログイン#################--> <!-- <SECT>Getty and Login --> <sect> Getty と login <!-- <P>Getty is the program that enables you to log in through a serial device such as a virtual terminal, a text terminal, or a modem. It displays the login prompt. Once you enter your username, getty hands this over to <TT>login</TT> which asks for a password, checks it out and gives you a shell. --> <p> <tt>getty</tt> とは、仮想端末やテキスト端末あるいはモデムといったシリアルデ バイス経由でログインするために必要なプログラムである。それがログインプロンプ トを表示する。ユーザ名を打ち込むと、<tt>getty</tt> はそれを <tt>login</tt> に手渡し、そのプログラムがパスワードを尋ね、それをチェックした上で、ユーザが シェルを使えるようにする。 <!-- <P>There are many getty's available. Some distributions, including Red Hat use a very small one called <TT>mingetty</TT> that only works with virtual terminals. --> <p> 多くの <tt>getty</tt> プログラムが入手可能である。Red Hat を含むいくつかの ディストリビューションは、仮想端末だけで動作する <tt>mingetty</tt> と呼ばれる 非常に小さなプログラムを使っている。 <!--<P>The <TT>login</TT> program is part of the util-linux package, which also contains a getty called <TT>agetty</TT>, which works fine. This package also contains <TT>mkswap</TT>, <TT>fdisk</TT>, <TT>passwd</TT>, <TT>kill</TT>, <TT>setterm</TT>, <TT>mount</TT>, <TT>swapon</TT>, <TT>rdev</TT>, <TT>renice</TT>, <TT>more</TT> (the program) and more (ie more programs). --> <p> <tt>login</tt> プログラムは、<tt>util-linux</tt> パッケージの一部で、そのパッ ケージには<tt>agetty</tt> と呼ばれる快適に動く <tt>getty</tt> の一種が含まれ ている。 そのパッケージには、また <tt>mkswap</tt>, <tt>fdisk</tt>, <tt>passwd</tt>, <tt>kill</tt>, <tt>setterm</tt>, <tt>mount</tt>, <tt>swapon</tt>, <tt>rdev</tt>, <tt>renice</tt>, <tt>more</tt> などなどが含まれている。 <!-- <SECT1>Configuration --> <sect1> 設定 <!--<P>The message that comes on the top of your screen with your login prompt comes from <TT>/etc/issue</TT>. Gettys are usually started in <TT>/etc/inittab</TT>. Login checks user details in <TT>/etc/passwd</TT>, and if you have password shadowing, <TT>/etc/shadow</TT>.--> <p> ログインプロンプトと一緒に画面上部に表示されるメッセージは、<tt>/etc/issue </tt> から来ている。<tt>getty</tt> は、通常 <tt>/etc/inittab</tt> から起動さ れる。<tt>login</tt> は、<tt>/etc/passwd</tt> でユーザの詳細をチェックする が、シャドーパスワードを使っている場合は、<tt>/etc/shadow</tt> を チェックする。 <!--<SECT1>Exercises--> <sect1> 演習 <!--<P>Create a <TT>/etc/passwd</TT> by hand. Passwords can be set to null, and changed with the program <TT>passwd</TT> once you log on. See the man page for this file Use <TT>man 5 passwd</TT> to get the man page for the file rather than the man page for the program.--> <p> <tt>/etc/passwd</tt> ファイルを自分の手で作ること。パスワード部分は無し(null) にしておいて、ログオンしてから <tt>passwd</tt> プログラムで書き換えてもよい。 そのマニュアルページを見ること。その際、<tt>passwd</tt> プログラムのマニュア ルページではなく、そのファイルについてのマニュアルである <tt>man 5 passwd</tt> を使うこと。 <!--#########################第十一章 bash ##########################--> <!-- <SECT>Bash --> <sect> Bash <!-- <P>If you give <TT>login</TT> a valid username and password combination, it will check in <TT>/etc/passwd</TT> to see which shell to give you. In most cases on a Linux system this will be <TT>bash</TT>. It is <TT>bash</TT>'s job to read your commands and see that they are acted on. It is simultaneously a user interface, and a programming language interpreter. --> <p> <tt>login</tt> に有効なユーザ名とパスワードの組み合わせを送ると、<tt>login </tt>は、<tt>/etc/passwd</tt> をチェックし、どのシェルを起動すべきか確認する。 Linux システムではほとんどの場合、それは <tt>bash</tt> である。<tt>bash</tt> の仕事はユーザのコマンドを読み込んで、自分のプロセス上でそのコマンドが実行さ れるのを確認することである。<tt>bash</tt> は、ユーザインターフェイスであると 同時にプログラミング言語のインタープリタでもある。 <!--<P>As a user interface it reads your commands, and executes them itself if they are ``internal'' commands like <TT>cd</TT>, or finds and executes a program if they are ``external'' commands like <TT>cp</TT> or <TT>startx</TT>. It also does groovy stuff like keeping a command history, and completing filenames.--> ユーザインターフェイスとして見た場合、<tt>bash</tt> は、まずコマンドを読み込 み、次に、もしそのコマンドが <tt>cd</tt> のような「内部コマンド (internal command)」であるなら、自分でそれを実行し、<tt>cp</tt> や <tt>startx</tt> のような「外部コマンド(external command)」であるならそのプロ グラムを探し出して実行する。 また <tt>bash</tt> は、コマンドヒストリーの記憶やファイル名の補完などの優れた 機能も持っている。 <!--<P>We have already seen <TT>bash</TT> in action as a programming language interpreter. The scripts that <TT>init</TT> runs to start the system up are usually shell scripts, and are executed by <TT>bash</TT>. Having a proper programming language, along with the usual system utilities available at the command line makes a very powerful combination, if you know what you are doing. For example (smug mode on) I needed to apply a whole stack of ``patches'' to a directory of source code the other day. I was able to do this with the following single command:--> <p> <tt>bash</tt> がプログラム言語のインタープリタとして働いていることは既に見た。 <tt>init</tt> がシステム起動のために実行するスクリプトは通常シェルスクリプト であり、それらのスクリプトは <tt>bash</tt> によって実行されている。適切なプロ グラム言語とコマンドラインで利用できる普通のシステムユーティリティがあり、そ れを使って自分のしていることを自覚できる程度の知識があれば、その組み合わせから 大きな力を引き出せる。例えば、(これは自己満足にすぎないかもしれないのだが、) わたしは先日ソースコードのディレクトリに大量のパッチを当てる必要が生じた。 しかし、わたしはそれを以下のような一行のコマンドで解決した。 <VERB> for f in /home/greg/sh-utils-1.16*.patch; do patch -p0 < $f; done; </VERB> <!--<P>This looks at all the files in my home directory whose names start with <TT>sh-utils-1.16</TT> and end with <TT>.patch</TT>. It then takes each of these in turn, and sets the variable <TT>f</TT> to it and executes the commands between <TT>do</TT> and <TT>done</TT>. In this case there were 11 patch files, but there could just as easily have been 3000.--> <p> このコマンドは、わたしのホームディレクトリにあるファイルのうち、ファイル名が <tt>sh-utils-1.16</tt> で始まり <tt>.patch</tt> で終わるものすべてを対象とし て認識する。そして、それらを ひとつずつ順番に取り上げて、変数 <tt>f</tt> をセットし、<tt>do</tt> と <tt> done</tt> の間にあるコマンドを実行する。このケースでは、11 のパッチファイルで あったが、たとえそれが 3000 個あったとしても同じように簡単に処理されていたは ずである。 <!--<SECT1>Configuration--> <sect1> 設定 <!--<P>The file <TT>/etc/profile</TT> controls the system-wide behaviour of bash. What you put in here will affect everybody who uses bash on your system. It will do things like add directories to the <TT>PATH</TT>, set your <TT>MAIL</TT> directory variable.--> <p> <tt>/etc/profile</tt> というファイルが、システム全体における <tt>bash</tt> の 振る舞いをコントロールしている。そこに何かを加えたとすると、それはシステム上 で <tt>bash</tt> を使う全員に影響を及ぼす。そのファイルでは、(環境変数) <tt>PATH</tt> へのディレクトリの追加や、<tt>MAIL</tt> ディレクトリの変数の 設定などがなされる。 <!--<P>The default behaviour of the keyboard often leaves a lot to be desired. It is actually readline that handles this. Readline is a separate package that handles command line interfaces, providing the command history and filename completion, as well as some advanced line editing features. It is compiled into bash. By default, readline is configured using the file <TT>. inputrc</TT> in your home directory. The bash variable INPUTRC can be used to override this for bash. For example in Red Hat 6, <TT>INPUTRC</TT> is set to <TT>/etc/inputrc</TT> in <TT>/etc/profile</TT>. This means that backspace, delete, home and end keys work nicely for everyone.--> <p> キーボードのデフォルト設定は、しばしば満足のいくものになっていないことが多い。 それを実際に解決するのが、<tt>readline</tt> である。<tt>readline</tt> は、コ マンドラインのインターフェイスを担当する(<tt>bash</tt> とは)別のパッケージに なっているプログラムで、いくつかの先進的なライン編集機能を持つのはもちろん、 コマンド履歴やファイル名補完といった機能を提供する。 <tt>readline</tt> は、コンパイル時に <tt>bash</tt> に組み込まれる。デフォルト では、<tt>readline</tt> はホームディレクトリの <tt>.inputrc</tt> ファイルを 使って設定するようになっている。<tt>bash</tt> の変数である <tt>INPUTRC</tt> を使って <tt>bash</tt> 用にこの設定ファイルを上書きすることもできる。例えば Red Hat 6 では、<tt>/etc/profile</tt> において <tt>INPUTRC</tt> は <tt>/etc/inputrc</tt> を上書きするよう設定されている。これは、 バックスペースやデリート、あるいはホームキーやエンドキーが誰にとっても上手 く働くようにするためである。 <!--<P>Once bash has read the system-wide configuration file, it looks for your personal configuration file. It checks in your home directory for <TT>.bash_profile</TT>, <TT>.bash_login</TT> and <TT>.profile</TT>. It runs the first one of these it finds. If you want to change the way bash behaves for you, without changing the way it works for others, do it here. For example, many applications use environment variables to control how they work. I have the variable <TT>EDITOR</TT> set to <TT>vi</TT> so that I can use vi in Midnight Commander (an excellent console based file manager) instead of its editor. --> <p> <tt>bash</tt> はシステム全体の設定ファイルを読み終わると、今度は個人用設定 ファイルを探し、ホームディレクトリにある <tt>.bash_profile</tt>, <tt>.bash_login</tt>,<tt>.profile</tt> をチェックする。そしてこの順番で最初に 見つけたファイルを実行する。 もし他人の <tt>bash</tt> の振る舞いを変更せずに自分のものだけを変えたいの であれば、ここを編集すればよい。例えば、多くのアプリケーションは動作方法を コントロールするのに環境変数を使っている。わたしは Midnight Commander(優れた コンソールベースのファイルマネージャ)で組み込みのエディタではなく <tt>vi</tt> を使えるようにするために、変数 <tt>EDITOR</tt> を <tt>vi</tt> にセットしている。 <!--<SECT1>Exercises--> <sect1> 演習 <!--<P>The basics of bash are easy to learn. But don't stop there: there is an incredible depth to it. Get into the habit of looking for better ways to do things.--> <p> <tt>bash</tt> の基礎は簡単に学べる。しかし、そこで終わらないこと。それは信じ られないくらい奥が深いからである。より良いやり方がないか調べる癖をつけること。 <!--<P>Read shell scripts, look up stuff you don't understand.--> シェルスクリプトを読んで、理解できない部分を調べること。 <!--<SECT1>More Information--> <sect1>参考文献等 <P> <ITEMIZE> <ITEM> <!--There is a ``Bash Reference Manual'' with this, which is comprehensive, but heavy going.--> ソースには "Bash Reference Manual" が添付されている。これは分かり易いが、 全部読むのは大変である。 <ITEM> <!--There is an O'Rielly book on Bash, not sure if it's good.--> O'Reilly から <tt>bash</tt> に関する本が出ているが、いい本かどうかは知らない。 <ITEM> <!--I don't know of any good free up to date bash tutorials. If you do, please email me a url.--> 他にも <tt>bash</tt> に関するフリーで新しい入門書があるかどうか知らない。 御存知なら、メールで URL を教えてほしい。 <ITEM> <!--source code, see <URL URL="http://www.netspace.net.au/~gok/power2bash" NAME="Building a Minimal Linux System from Source Code"> for urls--> ソースコードについては、<url url="http://www.netspace.net.au/~gok/power2bash" name="Building a Minimal Linux System from Source Code"> (<url url="http://www.linux.or.jp/JF/JFdocs/Building-Minimal-Linux.html" name="日本語訳">)で URL を確認すること。 </ITEMIZE> <!--########################第十二章 コマンド########################--> <!--<SECT>Commands--> <sect> コマンド <!--<P>You do most things in bash by issuing commands like <TT>cp</TT>. Most of these commands are small programs, though some, like <TT>cd</TT> are built into the shell.--> <p> <tt>bash</tt> から <tt>cp</tt> のようなコマンドを実行することで、大部分の作業 は済んでしまう。<tt>cd</tt> のようにシェルに組み込まれたいくつかのコマンドを 除くと、それらのコマンドのほとんどは、小さなプログラムである。 <!--<P>The commands come in packages, most of them from the Free Software Foundation (or GNU).Rather than list the packages here, I'll direct you to the <URL URL="http://www.linuxfromscratch.org" NAME="Linux From Scratch HOWTO">. It has a full and up to date list of the packages that go into a Linux system as well as instructions on how to build them.--> <p> コマンドはパッケージで配布されるが、これらのほとんどは Free Software Fundation (あるいは、GNU) からのものである。ここでそのパッケージを数え上げるよりも、わた しは <url url="http://www.linuxfromscratch.org" name="Linux From Scratch HOWTO"> を見ることをお薦めしたい。このサイトでは、Linux システムに組み入れら れるパッケージの完全で最新のリストがあり、同時にその構築の仕方も説明されて いる。 <!--######################### 第十三章 結論 ###########################--> <!--<sect>Conclusion--> <sect>結論 <!--<P>One of the best things about Linux, in my humble opinion, is that you can get inside it and really find out how it all works. I hope that you enjoy this as much as I do. And I hope that this little note has helped you do it.--> <p> Linux の最大の長所は、私見では、内部を覗いて、全体がどう動いているか調べられ ることだ。わたしと同じくらい、読者もそれを楽しんでくれればと思う。そして、この 文書が、それをする読者の一助となることを願う。 <!--#################### 第十四章 Administrivia ###########################--> <SECT>Administrivia <SECT1>Copyright <P> <!--This document is copyright (c) 1999, 2000 Greg O'Keefe. You are welcome to use, copy, distribute or modify it, without charge, under the terms of the <URL URL="http://www.gnu.org/copyleft/gpl.html" NAME="GNU General Public Licence">. Please acknowledge me if you use all or part of this in another document.--> この文書の著作権: Copyright (c) 1999, 2000 Greg O'Keefe. <p> この文書の利用、配布、修正は、次のライセンスの条項に従う限り無料です。 <URL URL="http://www.gnu.org/copyleft/gpl.html" NAME="GNU General Public Licence"><newline> 他の文書においてこの文書の全体もしくは部分を利用するときは、著者まで連絡願い ます。 <!--<SECT1>Homepage--> <sect1>ホームページ <!--<P>The lastest version of this document lives at <URL URL="http://www.netspace.net.au/~gok/power2bash" NAME="From Powerup To Bash Prompt"> as does its companion ``Building a Minimal Linux System from Source Code''.--> <p> この文書の最新バージョンは、こちらにです。 <url url="http://www.netspace.net.au/~gok/power2bash" name="From Powerup To Bash Prompt"><newline> なお、付属文書として、"Building a Minimal Linux System from Source Code" も 同じ場所にあります。 <P> <!--There is a French translation at <URL URL="http://www.freenix.fr/unix/linux/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.html" NAME="From Powerup To Bash Prompt"> thanks to Dominique van den Broeck. --> <p> Dominique van den Broeck によるフランス語訳が、以下にあります。<newline> <URL URL="http://www.freenix.fr/unix/linux/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.html" NAME="From Powerup To Bash Prompt"> <!-- A Japanese by Yuji Senda is coming soon, if it's not at <URL URL="http://www.linux.or.jp/JF" NAME="Japanese Documentation and FAQ Project"> already. --> <p>Yuji Senda による日本語版が、<url url="http://www.linux.or.jp/JF" name="Japanese Documentation and FAQ Project"> にあります。ない場合は、もうすぐ登場です。 <!--<SECT1>Feedback--> <sect1>フィードバック <!--<P>I would like to hear any comments, criticisms and suggestions for improvement that you have. Please send them to me--> <p>読者のコメント、批判、改善ついての提案など何なりと聞かせてください。 <newline> Greg O'Keefe gcokeefe@postoffice.utas.edu.au <SECT1>Acknowledgements <LABEL ID="acknowledge"> <!--<P>Product names are trademarks of the respective holders, and are hereby considered properly acknowledged.--> <p>製品名はそれぞれの権利者の登録商標です。 <!--<P>There are some people I want to say thanks to, for helping to make this happen.--> <p>この文書をつくるにあたって、お世話になった何人もの 方がいるので、ここに感謝のことばを述べたいと思います。 <P> <DESCRIP> <TAG>Michael Emery</TAG> <!--For reminding me about Unios.--> unios のことを思い出させてくれた。 <TAG>Tim Little</TAG> <!--For some good clues about <TT>/etc/passwd</TT>--> <tt>/etc/passwd</tt> に関するいくつかのよい手がかりを与えてくれた。 <TAG>sPaKr on #linux in efnet</TAG> <!--Who sussed out that syslogd needs <TT>/etc/services</TT>, and introduced me to the phrase ``rolling your own'' to describe building a system from source code.--> <tt>syslogd</tt> が <tt>/etc/services</tt> を必要とすることを指摘し、同時に "rolling your own" という言葉がソースからシステムを作ることを指すのだと 教えてくれた。 <TAG>Alex Aitkin</TAG> <!--For bringing Vico and his ``verum ipsum factum'' (understanding arises through making) to my attention.--> Vico と "verum ipsum factum" が「理解はつくることから生まれる」 という意味であることを知らせてくれた。 <TAG>Dennis Scott</TAG> <!--For correcting my hexidecimal arithmetic.--> わたしの 16 進数の計算の間違いを指摘してくれた。 <TAG>jdd</TAG> <!--For pointing out some typos.--> 誤植を指摘してくれた。 <TAG>David Leadbeater</TAG> <!--For contributing some ``ramblings'' about the kernel deamons.--> カーネルデーモンについての「冗長な記述」を送ってくれた。 <TAG>Dominique van den Broeck </TAG> <!--For translating this doc into French.--> この文書をフランス語に翻訳してくれた。 <TAG>Matthieu Peeters </TAG> <!--For some good information about kernel deamons.--> カーネルデーモンに関する貴重な情報を提供してくれた。 <TAG>John Fremlin</TAG> <!--For some good information about kernel deamons.--> カーネルデーモンに関する貴重な情報を提供してくれた。 <TAG>Yuji Senda</TAG> <!--For the Japanese translation.--> 日本語への翻訳。 <TAG>Antonius de Rozari</TAG> <!--For contributing a GNU assembler version of UNIOS (see resources section on the home page)--> UNIOS の GNU アセンブラバージョンを提供してくれた。 (詳細は、わたしのホームページの resources セクションを見て欲しい。) </DESCRIP> <!--<SECT1>Change History--> <sect1>改訂履歴 <SECT2>0.8 -> 0.9 (November 2000) <P> <ITEMIZE> <ITEM><!--Incorporated some information from Matthieu Peeters on kernel deamons and the <TT>/proc</TT> filesystem.--> カーネルデーモンと <tt>/proc</tt> ファイルシステムに関する Matthieu Peeters からの情報を組み込んだ。 </ITEMIZE> <SECT2>0.7 -> 0.8 (September 2000) <P> <ITEMIZE> <ITEM> <!-- Removed instructions on how to build a system, placing them in a separate document. Adjusted a few links accordingly. --> システム構築に関する手引きの部分を削除して、別文書とした。いくつかのリンクを 修正した。 <ITEM> <!-- Changed homepage from <URL URL="http://learning.taslug.org.au/power2bash" NAME="learning@TasLUG"> to <URL URL="http://www.netspace.net.au/~gok/power2bash" NAME="my own webspace">. --> ホームページを <url url="http://learning.taslug.org.au/power2bash" name="learning@TasLUG"> から <url url="http://www.netspace.net.au/~gok/power2bash" name="わたし自身のページ"> に移動した。 <ITEM> <!-- Completely failed to incorporate a lot of good material contributed by various people. Maybe next time :( --> 様々なひとから知らせてもらった、多くの情報を付け加えることには完全に失敗した。 おそらく、次の版になると思う :( </ITEMIZE> <SECT2>0.6 -> 0.7 <P> <ITEMIZE> <ITEM> <!--more emphasis on explanation, less on how to build a system, building info gathered together in a separate section and the system built is trimmed down, direct readers to Gerard Beekmans' ``Linux From Scratch'' doc for serious building--> システム構築法よりもシステムの説明に重点をおいた。章ごとに情報をまとめ、 システム構築は分量を減らし、実用的な構築に関しては、Gerard Beekmans の "Linux From Scratch" を見てもらうようにした。 <ITEM> <!--added some ramblings contributed by David Leadbeater--> David Leadbeater の冗長な寄稿を付け加えた。 <ITEM> <!--fixed a couple of url's, added link to unios download at learning.taslug.org.au/resources--> いくつかの URL を修正し、learning.taslug.org.au/resources から unios をダウン ロードできるようにリンクを付け足した。 <ITEM> <!--tested and fixed url's--> URL のリンク切れを調べて、訂正した。 <ITEM> <!--generally rewrite, tidy up--> 全体的にリライトして、整頓した。 </ITEMIZE> <SECT2>0.5 -> 0.6 <P> <ITEMIZE> <ITEM> <!--added change history-->改訂履歴を付け加えた。 <ITEM> <!--added some todos-->TODO の項目をいくつか増やした。 </ITEMIZE> <SECT1>TODO <P> <ITEMIZE> <ITEM> <!--explain kernel modules, depmod, modprobe, insmod and all that (I'll have to find out first!)--> カーネルモジュール、depmod,modprobe,insmod などを説明すること。 <ITEM> <!--mention the /proc filesystem, potential for exercises here--> /proc ファイルシステムに言及し、できれば、演習も付けること。 <ITEM> <!--convert to docbook sgml--> docbook の sgml 形式に変更すること <ITEM> <!--add more exercises, perhaps a whole section on larger exercises, like creating a minimal system file by file from a distro install.--> もっと演習を増やすこと。最初のインストールからファイルをひとつずつ 削除して最小限度のシステムをつくるといったような、もっと手の込んだ 演習をつくって一章を割くといったようなこと。 <ITEM> <!--add makefile hack to bash build instructions - see easter notes.--> <tt>bash</tt> をビルドする際の makefile のハックの方法を付け加えること。 - easter notes を見て欲しい。 </ITEMIZE> <sect1>日本語訳について <p> <verb> 翻訳: 千旦 裕司 校正: 山森 浩幸 武井 伸光 佐野 武俊 川嶋 勤 </verb> </ARTICLE>