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