]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man7/namespaces.7
namespaces.7: Remove /proc/PID/mountstats description
[thirdparty/man-pages.git] / 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 .TH NAMESPACES 7 2016-03-15 "Linux" "Linux Programmer's Manual"
28 .SH NAME
29 namespaces \- overview of Linux namespaces
30 .SH DESCRIPTION
31 A namespace wraps a global system resource in an abstraction that
32 makes it appear to the processes within the namespace that they
33 have their own isolated instance of the global resource.
34 Changes to the global resource are visible to other processes
35 that are members of the namespace, but are invisible to other processes.
36 One use of namespaces is to implement containers.
37
38 Linux provides the following namespaces:
39 .TS
40 lB lB lB
41 l lB l.
42 Namespace Constant Isolates
43 Cgroup CLONE_NEWCGROUP Cgroup root directory
44 IPC CLONE_NEWIPC System V IPC, POSIX message queues
45 Network CLONE_NEWNET Network devices, stacks, ports, etc.
46 Mount CLONE_NEWNS Mount points
47 PID CLONE_NEWPID Process IDs
48 User CLONE_NEWUSER User and group IDs
49 UTS CLONE_NEWUTS Hostname and NIS domain name
50 .TE
51
52 This page describes the various namespaces and the associated
53 .I /proc
54 files, and summarizes the APIs for working with namespaces.
55 .\"
56 .\" ==================== The namespaces API ====================
57 .\"
58 .SS The namespaces API
59 As well as various
60 .I /proc
61 files described below,
62 the namespaces API includes the following system calls:
63 .TP
64 .BR clone (2)
65 The
66 .BR clone (2)
67 system call creates a new process.
68 If the
69 .I flags
70 argument of the call specifies one or more of the
71 .B CLONE_NEW*
72 flags listed below, then new namespaces are created for each flag,
73 and the child process is made a member of those namespaces.
74 (This system call also implements a number of features
75 unrelated to namespaces.)
76 .TP
77 .BR setns (2)
78 The
79 .BR setns (2)
80 system call allows the calling process to join an existing namespace.
81 The namespace to join is specified via a file descriptor that refers to
82 one of the
83 .IR /proc/[pid]/ns
84 files described below.
85 .TP
86 .BR unshare (2)
87 The
88 .BR unshare (2)
89 system call moves the calling process to a new namespace.
90 If the
91 .I flags
92 argument of the call specifies one or more of the
93 .B CLONE_NEW*
94 flags listed below, then new namespaces are created for each flag,
95 and the calling process is made a member of those namespaces.
96 (This system call also implements a number of features
97 unrelated to namespaces.)
98 .PP
99 Creation of new namespaces using
100 .BR clone (2)
101 and
102 .BR unshare (2)
103 in most cases requires the
104 .BR CAP_SYS_ADMIN
105 capability.
106 User namespaces are the exception: since Linux 3.8,
107 no privilege is required to create a user namespace.
108 .\"
109 .\" ==================== The /proc/[pid]/ns/ directory ====================
110 .\"
111 .SS The /proc/[pid]/ns/ directory
112 Each process has a
113 .IR /proc/[pid]/ns/
114 .\" See commit 6b4e306aa3dc94a0545eb9279475b1ab6209a31f
115 subdirectory containing one entry for each namespace that
116 supports being manipulated by
117 .BR setns (2):
118
119 .in +4n
120 .nf
121 $ \fBls -l /proc/$$/ns\fP
122 total 0
123 lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 cgroup -> cgroup:[4026531835]
124 lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 ipc -> ipc:[4026531839]
125 lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 mnt -> mnt:[4026531840]
126 lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 net -> net:[4026531969]
127 lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 pid -> pid:[4026531836]
128 lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 user -> user:[4026531837]
129 lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 uts -> uts:[4026531838]
130 .fi
131 .in
132
133 Bind mounting (see
134 .BR mount (2))
135 one of the files in this directory
136 to somewhere else in the filesystem keeps
137 the corresponding namespace of the process specified by
138 .I pid
139 alive even if all processes currently in the namespace terminate.
140
141 Opening one of the files in this directory
142 (or a file that is bind mounted to one of these files)
143 returns a file handle for
144 the corresponding namespace of the process specified by
145 .IR pid .
146 As long as this file descriptor remains open,
147 the namespace will remain alive,
148 even if all processes in the namespace terminate.
149 The file descriptor can be passed to
150 .BR setns (2).
151
152 In Linux 3.7 and earlier, these files were visible as hard links.
153 Since Linux 3.8, they appear as symbolic links.
154 If two processes are in the same namespace, then the inode numbers of their
155 .IR /proc/[pid]/ns/xxx
156 symbolic links will be the same; an application can check this using the
157 .I stat.st_ino
158 field returned by
159 .BR stat (2).
160 The content of this symbolic link is a string containing
161 the namespace type and inode number as in the following example:
162
163 .in +4n
164 .nf
165 $ \fBreadlink /proc/$$/ns/uts\fP
166 uts:[4026531838]
167 .fi
168 .in
169
170 The files in this subdirectory are as follows:
171 .TP
172 .IR /proc/[pid]/ns/cgroup " (since Linux 4.6)"
173 This file is a handle for the cgroup namespace of the process.
174 .TP
175 .IR /proc/[pid]/ns/ipc " (since Linux 3.0)"
176 This file is a handle for the IPC namespace of the process.
177 .TP
178 .IR /proc/[pid]/ns/mnt " (since Linux 3.8)"
179 This file is a handle for the mount namespace of the process.
180 .TP
181 .IR /proc/[pid]/ns/net " (since Linux 3.0)"
182 This file is a handle for the network namespace of the process.
183 .TP
184 .IR /proc/[pid]/ns/pid " (since Linux 3.8)"
185 This file is a handle for the PID namespace of the process.
186 .TP
187 .IR /proc/[pid]/ns/user " (since Linux 3.8)"
188 This file is a handle for the user namespace of the process.
189 .TP
190 .IR /proc/[pid]/ns/uts " (since Linux 3.0)"
191 This file is a handle for the UTS namespace of the process.
192 .\"
193 .\" ==================== Cgroup namespaces ====================
194 .\"
195 .SS Cgroup namespaces (CLONE_NEWCGROUP)
196 See
197 .BR cgroup_namespaces (7).
198 .\"
199 .\" ==================== IPC namespaces ====================
200 .\"
201 .SS IPC namespaces (CLONE_NEWIPC)
202 IPC namespaces isolate certain IPC resources,
203 namely, System V IPC objects (see
204 .BR svipc (7))
205 and (since Linux 2.6.30)
206 .\" commit 7eafd7c74c3f2e67c27621b987b28397110d643f
207 .\" https://lwn.net/Articles/312232/
208 POSIX message queues (see
209 .BR mq_overview (7)).
210 The common characteristic of these IPC mechanisms is that IPC
211 objects are identified by mechanisms other than filesystem
212 pathnames.
213
214 Each IPC namespace has its own set of System V IPC identifiers and
215 its own POSIX message queue filesystem.
216 Objects created in an IPC namespace are visible to all other processes
217 that are members of that namespace,
218 but are not visible to processes in other IPC namespaces.
219
220 The following
221 .I /proc
222 interfaces are distinct in each IPC namespace:
223 .IP * 3
224 The POSIX message queue interfaces in
225 .IR /proc/sys/fs/mqueue .
226 .IP *
227 The System V IPC interfaces in
228 .IR /proc/sys/kernel ,
229 namely:
230 .IR msgmax ,
231 .IR msgmnb ,
232 .IR msgmni ,
233 .IR sem ,
234 .IR shmall ,
235 .IR shmmax ,
236 .IR shmmni ,
237 and
238 .IR shm_rmid_forced .
239 .IP *
240 The System V IPC interfaces in
241 .IR /proc/sysvipc .
242 .PP
243 When an IPC namespace is destroyed
244 (i.e., when the last process that is a member of the namespace terminates),
245 all IPC objects in the namespace are automatically destroyed.
246
247 Use of IPC namespaces requires a kernel that is configured with the
248 .B CONFIG_IPC_NS
249 option.
250 .\"
251 .\" ==================== Network namespaces ====================
252 .\"
253 .SS Network namespaces (CLONE_NEWNET)
254 Network namespaces provide isolation of the system resources associated
255 with networking: network devices, IPv4 and IPv6 protocol stacks,
256 IP routing tables, firewalls, the
257 .I /proc/net
258 directory, the
259 .I /sys/class/net
260 directory, port numbers (sockets), and so on.
261 A physical network device can live in exactly one
262 network namespace.
263 A virtual network device ("veth") pair provides a pipe-like abstraction
264 .\" FIXME Add pointer to veth(4) page when it is eventually completed
265 that can be used to create tunnels between network namespaces,
266 and can be used to create a bridge to a physical network device
267 in another namespace.
268
269 When a network namespace is freed
270 (i.e., when the last process in the namespace terminates),
271 its physical network devices are moved back to the
272 initial network namespace (not to the parent of the process).
273
274 Use of network namespaces requires a kernel that is configured with the
275 .B CONFIG_NET_NS
276 option.
277 .\"
278 .\" ==================== Mount namespaces ====================
279 .\"
280 .SS Mount namespaces (CLONE_NEWNS)
281 Mount namespaces isolate the set of filesystem mount points,
282 meaning that processes in different mount namespaces can
283 have different views of the filesystem hierarchy.
284 The set of mounts in a mount namespace is modified using
285 .BR mount (2)
286 and
287 .BR umount (2).
288
289 The
290 .IR /proc/[pid]/mounts
291 file (present since Linux 2.4.19)
292 lists all the filesystems currently mounted in the
293 process's mount namespace.
294 The format of this file is documented in
295 .BR fstab (5).
296 Since kernel version 2.6.15, this file is pollable:
297 after opening the file for reading, a change in this file
298 (i.e., a filesystem mount or unmount) causes
299 .BR select (2)
300 to mark the file descriptor as having an exceptional condition, and
301 .BR poll (2)
302 and
303 .BR epoll_wait (2)
304 mark the file as having a priority event
305 .RB ( POLLPRI ).
306 (Before Linux 2.6.30,
307 a change in this file was indicated by the file descriptor
308 being marked as readable for
309 .BR select (2),
310 and being marked as having an error condition for
311 .BR poll (2)
312 and
313 .BR epoll_wait (2).)
314 .RE
315 .\"
316 .\" ==================== PID namespaces ====================
317 .\"
318 .SS PID namespaces (CLONE_NEWPID)
319 See
320 .BR pid_namespaces (7).
321 .\"
322 .\" ==================== User namespaces ====================
323 .\"
324 .SS User namespaces (CLONE_NEWUSER)
325 See
326 .BR user_namespaces (7).
327 .\"
328 .\" ==================== UTS namespaces ====================
329 .\"
330 .SS UTS namespaces (CLONE_NEWUTS)
331 UTS namespaces provide isolation of two system identifiers:
332 the hostname and the NIS domain name.
333 These identifiers are set using
334 .BR sethostname (2)
335 and
336 .BR setdomainname (2),
337 and can be retrieved using
338 .BR uname (2),
339 .BR gethostname (2),
340 and
341 .BR getdomainname (2).
342
343 Use of UTS namespaces requires a kernel that is configured with the
344 .B CONFIG_UTS_NS
345 option.
346 .SH CONFORMING TO
347 Namespaces are a Linux-specific feature.
348 .SH EXAMPLE
349 See
350 .BR user_namespaces (7).
351 .SH SEE ALSO
352 .BR lsns (1),
353 .BR nsenter (1),
354 .BR readlink (1),
355 .BR unshare (1),
356 .BR clone (2),
357 .BR setns (2),
358 .BR unshare (2),
359 .BR proc (5),
360 .BR capabilities (7),
361 .BR cgroup_namespaces (7),
362 .BR cgroups (7),
363 .BR credentials (7),
364 .BR pid_namespaces (7),
365 .BR user_namespaces (7),
366 .BR switch_root (8)