]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/pivot_root.2
Automated addition of parentheses by add_parens_for_own_funcs.sh
[thirdparty/man-pages.git] / man2 / pivot_root.2
1 .\" Copyright (C) 2000 by Werner Almesberger
2 .\" May be distributed under GPL
3 .\"
4 .\" Written 2000-02-23 by Werner Almesberger
5 .\" Modified 2004-06-17 Michael Kerrisk <mtk-manpages@gmx.net>
6 .\"
7 .TH PIVOT_ROOT 2 2004-06-17 "Linux 2.6.7" "Linux Programmer's Manual"
8 .SH NAME
9 pivot_root \- change the root file system
10 .SH SYNOPSIS
11 .B #include <linux/unistd.h>
12 .br
13 .B #include <errno.h>
14 .sp
15 .B _syscall2(int,pivot_root,const char *,new_root,const char *,put_old)
16 .sp
17 .BI "int pivot_root(const char *" new_root ", const char *" put_old );
18 .SH DESCRIPTION
19 \fBpivot_root\fP() moves the root file system of the current process to the
20 directory \fIput_old\fP and makes \fInew_root\fP the new root file system
21 of the current process.
22 .\"
23 .\" The
24 .\" .B CAP_SYS_ADMIN
25 .\" capability is required.
26
27 The typical use of \fBpivot_root\fP() is during system startup, when the
28 system mounts a temporary root file system (e.g. an \fBinitrd\fP), then
29 mounts the real root file system, and eventually turns the latter into
30 the current root of all relevant processes or threads.
31
32 \fBpivot_root\fP() may or may not change the current root and the current
33 working directory (cwd) of any processes or threads which use the old
34 root directory. The caller of \fBpivot_root\fP()
35 must ensure that processes with root or cwd at the old root operate
36 correctly in either case. An easy way to ensure this is to change their
37 root and cwd to \fInew_root\fP before invoking \fBpivot_root\fP().
38
39 The paragraph above is intentionally vague because the implementation
40 of \fBpivot_root\fP() may change in the future. At the time of writing,
41 \fBpivot_root\fP() changes root and cwd of each process or
42 thread to \fInew_root\fP if they point to the old root directory. This
43 is necessary in order to prevent kernel threads from keeping the old
44 root directory busy with their root and cwd, even if they never access
45 the file system in any way. In the future, there may be a mechanism for
46 kernel threads to explicitly relinquish any access to the file system,
47 such that this fairly intrusive mechanism can be removed from
48 \fBpivot_root\fP().
49
50 Note that this also applies to the current process: \fBpivot_root\fP() may
51 or may not affect its cwd. It is therefore recommended to call
52 \fBchdir("/")\fP immediately after \fBpivot_root\fP().
53
54 The following restrictions apply to \fInew_root\fP and \fIput_old\fP:
55 .IP \- 3
56 They must be directories.
57 .IP \- 3
58 \fInew_root\fP and \fIput_old\fP must not be on the same file system as
59 the current root.
60 .IP \- 3
61 \fIput_old\fP must be underneath \fInew_root\fP, i.e. adding a non-zero
62 number of \fB/..\fP to the string pointed to by \fIput_old\fP must yield
63 the same directory as \fInew_root\fP.
64 .IP \- 3
65 No other file system may be mounted on \fIput_old\fP.
66 .PP
67 See also \fBpivot_root(8)\fP for additional usage examples.
68
69 If the current root is not a mount point (e.g. after \fBchroot(2)\fP or
70 \fBpivot_root\fP(), see also below), not the old root directory, but the
71 mount point of that file system is mounted on \fIput_old\fP.
72 .SH NOTES
73 \fInew_root\fP does not have to be a mount point. In this case,
74 \fB/proc/mounts\fP will show the mount point of the file system containing
75 \fInew_root\fP as root (\fB/\fP).
76 .SH "RETURN VALUE"
77 On success, zero is returned. On error, \-1 is returned, and
78 \fIerrno\fP is set appropriately.
79 .SH ERRORS
80 \fBpivot_root\fP() may return (in \fIerrno\fP) any of the errors returned by
81 \fBstat(2)\fP. Additionally, it may return:
82
83 .TP
84 .B EBUSY
85 \fInew_root\fP or \fIput_old\fP are on the current root file system,
86 or a file system is already mounted on \fIput_old\fP.
87 .TP
88 .B EINVAL
89 \fIput_old\fP is not underneath \fInew_root\fP.
90 .TP
91 .B ENOTDIR
92 \fInew_root\fP or \fIput_old\fP is not a directory.
93 .TP
94 .B EPERM
95 The current process does not have the
96 .B CAP_SYS_ADMIN
97 capability.
98 .SH BUGS
99 \fBpivot_root\fP() should not have to change root and cwd of all other
100 processes in the system.
101
102 Some of the more obscure uses of \fBpivot_root\fP() may quickly lead to
103 insanity.
104 .SH "CONFORMING TO"
105 \fBpivot_root\fP() is Linux-specific and hence is not portable.
106 .SH HISTORY
107 \fBpivot_root\fP() was introduced in Linux 2.3.41.
108 .SH "SEE ALSO"
109 .BR chdir (2),
110 .BR chroot (2),
111 .BR stat (2),
112 .BR initrd (4),
113 .BR pivot_root (8)