]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/pivot_root.2
Removed HISTORY section, or moved it as a subsection or paragraphs
[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 /* Using \fBsyscall\fP(2) may be preferable; see \fBintro\fP(2) */
17 .sp
18 .BI "int pivot_root(const char *" new_root ", const char *" put_old );
19 .SH DESCRIPTION
20 .BR pivot_root ()
21 moves the root file system of the current process to the
22 directory \fIput_old\fP and makes \fInew_root\fP the new root file system
23 of the current process.
24 .\"
25 .\" The
26 .\" .B CAP_SYS_ADMIN
27 .\" capability is required.
28
29 The typical use of
30 .BR pivot_root ()
31 is during system startup, when the
32 system mounts a temporary root file system (e.g. an \fBinitrd\fP), then
33 mounts the real root file system, and eventually turns the latter into
34 the current root of all relevant processes or threads.
35
36 .BR pivot_root ()
37 may or may not change the current root and the current
38 working directory (cwd) of any processes or threads which use the old
39 root directory.
40 The caller of
41 .BR pivot_root ()
42 must ensure that processes with root or cwd at the old root operate
43 correctly in either case.
44 An easy way to ensure this is to change their
45 root and cwd to \fInew_root\fP before invoking
46 .BR pivot_root ().
47
48 The paragraph above is intentionally vague because the implementation
49 of
50 .BR pivot_root ()
51 may change in the future.
52 At the time of writing,
53 .BR pivot_root ()
54 changes root and cwd of each process or
55 thread to \fInew_root\fP if they point to the old root directory.
56 This
57 is necessary in order to prevent kernel threads from keeping the old
58 root directory busy with their root and cwd, even if they never access
59 the file system in any way.
60 In the future, there may be a mechanism for
61 kernel threads to explicitly relinquish any access to the file system,
62 such that this fairly intrusive mechanism can be removed from
63 .BR pivot_root ().
64
65 Note that this also applies to the current process:
66 .BR pivot_root ()
67 may
68 or may not affect its cwd.
69 It is therefore recommended to call
70 \fBchdir("/")\fP immediately after
71 .BR pivot_root ().
72
73 The following restrictions apply to \fInew_root\fP and \fIput_old\fP:
74 .IP \- 3
75 They must be directories.
76 .IP \- 3
77 \fInew_root\fP and \fIput_old\fP must not be on the same file system as
78 the current root.
79 .IP \- 3
80 \fIput_old\fP must be underneath \fInew_root\fP, i.e. adding a non-zero
81 number of \fI/..\fP to the string pointed to by \fIput_old\fP must yield
82 the same directory as \fInew_root\fP.
83 .IP \- 3
84 No other file system may be mounted on \fIput_old\fP.
85 .PP
86 See also
87 .BR pivot_root (8)
88 for additional usage examples.
89
90 If the current root is not a mount point (e.g. after
91 .BR chroot (2)
92 or
93 .BR pivot_root (),
94 see also below), not the old root directory, but the
95 mount point of that file system is mounted on \fIput_old\fP.
96 .SH NOTES
97 \fInew_root\fP does not have to be a mount point.
98 In this case,
99 \fI/proc/mounts\fP will show the mount point of the file system containing
100 \fInew_root\fP as root (\fI/\fP).
101 .SH "RETURN VALUE"
102 On success, zero is returned.
103 On error, \-1 is returned, and
104 \fIerrno\fP is set appropriately.
105 .SH ERRORS
106 .BR pivot_root ()
107 may return (in \fIerrno\fP) any of the errors returned by
108 .BR stat (2).
109 Additionally, it may return:
110 .TP
111 .B EBUSY
112 \fInew_root\fP or \fIput_old\fP are on the current root file system,
113 or a file system is already mounted on \fIput_old\fP.
114 .TP
115 .B EINVAL
116 \fIput_old\fP is not underneath \fInew_root\fP.
117 .TP
118 .B ENOTDIR
119 \fInew_root\fP or \fIput_old\fP is not a directory.
120 .TP
121 .B EPERM
122 The current process does not have the
123 .B CAP_SYS_ADMIN
124 capability.
125 .SH BUGS
126 .BR pivot_root ()
127 should not have to change root and cwd of all other
128 processes in the system.
129
130 Some of the more obscure uses of
131 .BR pivot_root ()
132 may quickly lead to
133 insanity.
134 .SH "CONFORMING TO"
135 .BR pivot_root ()
136 is Linux specific and hence is not portable.
137 .SH VERSIONS
138 .BR pivot_root ()
139 was introduced in Linux 2.3.41.
140 .SH "SEE ALSO"
141 .BR chdir (2),
142 .BR chroot (2),
143 .BR stat (2),
144 .BR initrd (4),
145 .BR pivot_root (8)