OSDN Git Service

4fd05dd42cab701c5022802d2a8b16a4f85ad204
[linuxjm/LDP_man-pages.git] / draft / man7 / namespaces.7
1 .\" Copyright (c) 2013 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" and Copyright (c) 2012 by Eric W. Biederman <ebiederm@xmission.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\"
27 .\"*******************************************************************
28 .\"
29 .\" This file was generated with po4a. Translate the source file.
30 .\"
31 .\"*******************************************************************
32 .TH NAMESPACES 7 2014\-09\-21 Linux "Linux Programmer's Manual"
33 .SH 名前
34 namespaces \- Linux 名前空間の概要
35 .SH 説明
36 A namespace wraps a global system resource in an abstraction that makes it
37 appear to the processes within the namespace that they have their own
38 isolated instance of the global resource.  Changes to the global resource
39 are visible to other processes that are members of the namespace, but are
40 invisible to other processes.  One use of namespaces is to implement
41 containers.
42
43 Linux では以下の名前空間が提供される。
44 .TS
45 lB lB lB
46 l lB l.
47 名前空間    定数  分離対象
48 IPC     CLONE_NEWIPC    System V IPC, POSIX メッセージキュー
49 Network CLONE_NEWNET    ネットワークデバイス、スタック、ポートなど
50 Mount   CLONE_NEWNS     マウントポイント
51 PID     CLONE_NEWPID    プロセス ID
52 User    CLONE_NEWUSER   ユーザー ID とグループ ID
53 UTS     CLONE_NEWUTS    ホスト名と NIS ドメイン名
54 .TE
55
56 .\"
57 .\" ==================== The namespaces API ====================
58 .\"
59 このページでは、各種の名前空間と関連する \fI/proc\fP ファイルの説明と、名前空間とともに動作する API の概要を紹介する。
60 .SS "名前空間 API"
61 後で説明する種々の \fI/proc\fP ファイル以外に、名前空間 API として以下のシステムコールがある。
62 .TP 
63 \fBclone\fP(2)
64 \fBclone\fP(2) システムコールは新しいプロセスを作成する。 呼び出し時に \fIflags\fP 引き数で以下のリストにある
65 \fBCLONE_NEW*\fP のフラグを一つ以上指定すると、 各フラグに対応する新しい名前空間が作成され、 子プロセスはこれらの名前空間のメンバーになる。
66 (このシステムコールは名前空間とは関係のない機能も多数実装している。)
67 .TP 
68 \fBsetns\fP(2)
69 \fBsetns\fP(2) システムコールを使うと、呼び出したプロセスを既存の名前空間に参加させることができる。 参加する名前空間は、 以下で説明する
70 \fI/proc/[pid]/ns\fP ファイルのいずれか一つを参照するファイルディスクリプタを使って指定する。
71 .TP 
72 \fBunshare\fP(2)
73 \fBunshare\fP(2) システムコールは、 呼び出したプロセスを新しい名前空間に移動する。 呼び出し時の \fIflags\fP
74 引き数に以下のリストにある \fBCLONE_NEW*\fP フラグを一つ以上指定すると、 各フラグに対応する新しい名前空間が作成され、
75 呼び出したプロセスがこれらの名前空間のメンバーになる。 (このシステムコールは名前空間とは関係のない機能も多数実装している。)
76 .PP
77 .\"
78 .\" ==================== The /proc/[pid]/ns/ directory ====================
79 .\"
80 \fBclone\fP(2) と \fBunshare\fP(2) を使った新しい名前空間の作成のほとんどの場合で \fBCAP_SYS_ADMIN\fP
81 ケーパビリティが必要である。 ユーザー名前空間は例外で、 Linux 3.8 以降ではユーザー名前空間を作成するのに特権が不要である。
82 .SS "/proc/[pid]/ns/ ディレクトリ"
83 .\" See commit 6b4e306aa3dc94a0545eb9279475b1ab6209a31f
84 各プロセスには \fI/proc/[pid]/ns/\fP サブディレクトリがあり、 このサブディレクトリには \fBsetns\fP(2)
85 での操作がサポートされている名前空間単位にエントリが存在する。
86
87 .in +4n
88 .nf
89 $ \fBls \-l /proc/$$/ns\fP
90 total 0
91 lrwxrwxrwx. 1 mtk mtk 0 Jan 14 01:20 ipc \-> ipc:[4026531839]
92 lrwxrwxrwx. 1 mtk mtk 0 Jan 14 01:20 mnt \-> mnt:[4026531840]
93 lrwxrwxrwx. 1 mtk mtk 0 Jan 14 01:20 net \-> net:[4026531956]
94 lrwxrwxrwx. 1 mtk mtk 0 Jan 14 01:20 pid \-> pid:[4026531836]
95 lrwxrwxrwx. 1 mtk mtk 0 Jan 14 01:20 user \-> user:[4026531837]
96 lrwxrwxrwx. 1 mtk mtk 0 Jan 14 01:20 uts \-> uts:[4026531838]
97 .fi
98 .in
99
100 このディレクトリ内のファイルのいずれかをファイルシステムの他のどこかにバインドマウント (\fBmount\fP(2) 参照) することで、
101 その名前空間のすべてのプロセスが終了した場合でも、 \fIpid\fP で指定したプロセスの対応する名前空間を保持することができる。
102
103 このディレクトリ内のファイルのいずれか (またはこれらのファイルのいずれかにバインドマウントされたファイル) をオープンすると、 \fIpid\fP
104 で指定されたプロセスの対応する名前空間に対するファイルハンドルが返される。 このファイルディスクリプタがオープンされている限り、
105 その名前空間のすべてのプロセスが終了した場合であっても、 その名前空間は存在し続ける。 このファイルディスクリプタは \fBsetns\fP(2)
106 に渡すことができる。
107
108 Linux 3.7 以前では、これらのファイルはハードリンクとして見えていた。 Linux 3.8 以降では、これらはシンボリックリンクとして見える。
109 2 つのプロセスが同じ名前空間に所属している場合、 これらのプロセスの \fI/proc/[pid]/ns/xxx\fP シンボリックリンクの inode
110 番号は同じになる。 アプリケーションは、 \fBstat\fP(2) が返す \fIstat.st_ino\fP フィールドを使ってこれを確認することができる。
111 シンボリックリンクの内容は、 以下の例にあるように、名前空間種別と inode 番号を含む文字列である。
112
113 .in +4n
114 .nf
115 $ \fBreadlink /proc/$$/ns/uts\fP
116 uts:[4026531838]
117 .fi
118 .in
119
120 このサブディレクトリのファイルは以下のとおりである。
121 .TP 
122 \fI/proc/[pid]/ns/ipc\fP (Linux 3.0 以降)
123 このファイルはそのプロセスの IPC 名前空間の操作用である。
124 .TP 
125 \fI/proc/[pid]/ns/mnt\fP (Linux 3.8 以降)
126 このファイルはそのプロセスのマウント名前空間の操作用である。
127 .TP 
128 \fI/proc/[pid]/ns/net\fP (Linux 3.0 以降)
129 このファイルはそのプロセスのネットワーク名前空間の操作用である。
130 .TP 
131 \fI/proc/[pid]/ns/pid\fP (Linux 3.8 以降)
132 このファイルはそのプロセスの PID 名前空間の操作用である。
133 .TP 
134 \fI/proc/[pid]/ns/user\fP (Linux 3.8 以降)
135 このファイルはそのプロセスのユーザー名前空間の操作用である。
136 .TP 
137 \fI/proc/[pid]/ns/uts\fP (Linux 3.0 以降)
138 .\"
139 .\" ==================== IPC namespaces ====================
140 .\"
141 このファイルはそのプロセスの UTS 名前空間の操作用である。
142 .SS "IPC 名前空間 (CLONE_NEWIPC)"
143 .\" commit 7eafd7c74c3f2e67c27621b987b28397110d643f
144 .\" https://lwn.net/Articles/312232/
145 IPC 名前空間は、 特定の IPC リソース、すなわち、System V IPC オブジェクト (\fBsvipc\fP(7) 参照)、(Linux
146 2.6.30 以降では) POSIX メッセージキュー (\fBmq_overview\fP(7) 参照) を分離する。 これらの IPC
147 機構に共通の特徴は、 IPC オブジェクトがファイルシステムのパス名以外の方法で識別されるという点である。
148
149 各 IPC 名前空間はそれぞれ、 独自の System V IPC 識別子の集合と独自の POSIX メッセージキューファイルシステムを持つ。 IPC
150 名前空間に作成されたオブジェクトは、 その名前空間のメンバーの他のすべてのプロセスにも見えるが、 他の IPC 名前空間のプロセスには見えない。
151
152 以下の \fI/proc\fP インタフェースは各 IPC 名前空間で別のものとなる。
153 .IP * 3
154 \fI/proc/sys/fs/mqueue\fP の POSIX メッセージキューインタフェース。
155 .IP *
156 \fI/proc/sys/kernel\fP の System V IPC インタフェース。 すなわち、 \fImsgmax\fP, \fImsgmnb\fP,
157 \fImsgmni\fP, \fIsem\fP, \fIshmall\fP, \fIshmmax\fP, \fIshmmni\fP, \fIshm_rmid_forced\fP。
158 .IP *
159 \fI/proc/sysvipc\fP の System V IPC インタフェース。
160 .PP
161 IPC 名前空間が破棄されたときに (すなわち、その名前空間のメンバーの最後のプロセスが終了したときに)、 その名前空間内のすべての IPC
162 オブジェクトが自動的に破棄される。
163
164 .\"
165 .\" ==================== Network namespaces ====================
166 .\"
167 IPC 名前空間を使用するには、設定 \fBCONFIG_IPC_NS\fP が有効になったカーネルが必要である。
168 .SS "ネットワーク名前空間 (CLONE_NEWNET)"
169 .\" FIXME Add pointer to veth(4) page when it is eventually completed
170 ネットワーク名前空間は、 ネットワークに関連するシステムリソースの分離を提供する。 分離されるリソースは、 ネットワークデバイス、 IPv4 と
171 IPv6 のプロトコルスタック、 IP ルーティングテーブル、 ファイアウォール、 \fI/proc/net\fP ディレクトリ、
172 \fI/sys/class/net\fP ディレクトリ、 (ソケットの) ポート番号などである。 物理ネットワークデバイスは 1
173 つのネットワーク名前空間にのみ属すことができる。 仮想ネットワークデバイス ("veth") ペアは、
174 ネットワーク名前空間間のトンネルを作成するのに使うことができるパイプ風の抽象概念で、
175 別の名前空間に属す物理ネットワークデバイスへのブリッジを作成するのに使用できる。
176
177 ネットワーク名前空間が解放されたときに (すなわち、その名前空間の最後のプロセスがしゅうりょうしたときに)、
178 その名前空間に属していた物理ネットワークデバイスは初期ネットワーク名前空間に戻される (プロセスの親プロセスに戻されるわけではない)。
179
180 .\"
181 .\" ==================== Mount namespaces ====================
182 .\"
183 ネットワーク名前空間を使用するには、設定 \fBCONFIG_NET_NS\fP が有効になったカーネルが必要である。
184 .SS "マウント名前空間 (CLONE_NEWNS)"
185 Mount namespaces isolate the set of filesystem mount points, meaning that
186 processes in different mount namespaces can have different views of the
187 filesystem hierarchy.  The set of mounts in a mount namespace is modified
188 using \fBmount\fP(2)  and \fBumount\fP(2).
189
190 The \fI/proc/[pid]/mounts\fP file (present since Linux 2.4.19)  lists all the
191 filesystems currently mounted in the process's mount namespace.  The format
192 of this file is documented in \fBfstab\fP(5).  Since kernel version 2.6.15,
193 this file is pollable: after opening the file for reading, a change in this
194 file (i.e., a filesystem mount or unmount) causes \fBselect\fP(2)  to mark the
195 file descriptor as readable, and \fBpoll\fP(2)  and \fBepoll_wait\fP(2)  mark the
196 file as having an error condition.
197
198 The \fI/proc/[pid]/mountstats\fP file (present since Linux 2.6.17)  exports
199 information (statistics, configuration information)  about the mount points
200 in the process's mount namespace.  This file is only readable by the owner
201 of the process.  Lines in this file have the form:
202 .RS
203 .in 12
204 .nf
205
206 device /dev/sda7 mounted on /home with fstype ext3 [statistics]
207 (       1      )            ( 2 )             (3 ) (4)
208 .fi
209 .in
210
211 各行のフィールドは以下のとおりである。
212 .TP  5
213 (1)
214 マウントされているデバイス名 (もしくは、対応するデバイスがない場合は "nodevice")。
215 .TP 
216 (2)
217 ファイルシステムツリー内のマウントポイント。
218 .TP 
219 (3)
220 ファイルシステム種別
221 .TP 
222 (4)
223 統計情報と設定情報。 オプションフィールドである。 現在のところ (Linux 2.6.26 時点)、NFS
224 ファイルシステムだけがこのフィールドで情報を公開している。
225 .RE
226 .\"
227 .\" ==================== PID namespaces ====================
228 .\"
229 .SS "PID 名前空間 (CLONE_NEWPID)"
230 .\"
231 .\" ==================== User namespaces ====================
232 .\"
233 \fBpid_namespaces\fP(7) 参照。
234 .SS "ユーザー名前空間 (CLONE_NEWUSER)"
235 .\"
236 .\" ==================== UTS namespaces ====================
237 .\"
238 \fBuser_namespaces\fP(7) 参照。
239 .SS "UTS 名前空間 (CLONE_NEWUTS)"
240 UTS 名前空間は、 ホスト名と NIS ドメイン名の 2 つのシステム識別子を分離する。 これらの識別子は \fBsethostname\fP(2) と
241 \fBsetdomainname\fP(2) を使って設定でき、 \fBuname\fP(2), \fBgethostname\fP(2),
242 \fBgetdomainname\fP(2) を使って取得できる。
243
244 UTS 名前空間を使用するには、設定 \fBCONFIG_UTS_NS\fP が有効になったカーネルが必要である。
245 .SH 準拠
246 名前空間は Linux 独自の機能である。
247 .SH 例
248 \fBuser_namespaces\fP(7) 参照。
249 .SH 関連項目
250 \fBnsenter\fP(1), \fBreadlink\fP(1), \fBunshare\fP(1), \fBclone\fP(2), \fBsetns\fP(2),
251 \fBunshare\fP(2), \fBproc\fP(5), \fBcredentials\fP(7), \fBcapabilities\fP(7),
252 \fBpid_namespaces\fP(7), \fBuser_namespaces\fP(7), \fBswitch_root\fP(8)
253 .SH この文書について
254 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.76 の一部
255 である。プロジェクトの説明とバグ報告に関する情報は
256 http://www.kernel.org/doc/man\-pages/ に書かれている。