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