1 .\" Copyright (C) 2000 by Werner Almesberger
2 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
3 .\" May be distributed under GPL
6 .\" Written 2000-02-23 by Werner Almesberger
7 .\" Modified 2004-06-17 Michael Kerrisk <mtk.manpages@gmail.com>
9 .TH PIVOT_ROOT 2 2012-07-13 "Linux" "Linux Programmer's Manual"
11 pivot_root \- change the root file system
13 .BI "int pivot_root(const char *" new_root ", const char *" put_old );
16 There is no glibc wrapper for this system call; see NOTES.
19 moves the root file system of the calling process to the
20 directory \fIput_old\fP and makes \fInew_root\fP the new root file system
21 of the calling process.
25 .\" capability is required.
29 is during system startup, when the
30 system mounts a temporary root file system (e.g., an \fBinitrd\fP), then
31 mounts the real root file system, and eventually turns the latter into
32 the current root of all relevant processes or threads.
35 may or may not change the current root and the current
36 working directory of any processes or threads which use the old
40 must ensure that processes with root or current working directory
41 at the old root operate correctly in either case.
42 An easy way to ensure this is to change their
43 root and current working directory to \fInew_root\fP before invoking
46 The paragraph above is intentionally vague because the implementation
49 may change in the future.
50 At the time of writing,
52 changes root and current working directory of each process or
53 thread to \fInew_root\fP if they point to the old root directory.
55 is necessary in order to prevent kernel threads from keeping the old
56 root directory busy with their root and current working directory,
57 even if they never access
58 the file system in any way.
59 In the future, there may be a mechanism for
60 kernel threads to explicitly relinquish any access to the file system,
61 such that this fairly intrusive mechanism can be removed from
64 Note that this also applies to the calling process:
67 or may not affect its current working directory.
68 It is therefore recommended to call
69 \fBchdir("/")\fP immediately after
72 The following restrictions apply to \fInew_root\fP and \fIput_old\fP:
74 They must be directories.
76 \fInew_root\fP and \fIput_old\fP must not be on the same file system as
79 \fIput_old\fP must be underneath \fInew_root\fP, that is, adding a nonzero
80 number of \fI/..\fP to the string pointed to by \fIput_old\fP must yield
81 the same directory as \fInew_root\fP.
83 No other file system may be mounted on \fIput_old\fP.
87 for additional usage examples.
89 If the current root is not a mount point (e.g., after
93 see also below), not the old root directory, but the
94 mount point of that file system is mounted on \fIput_old\fP.
96 \fInew_root\fP does not have to be a mount point.
98 \fI/proc/mounts\fP will show the mount point of the file system containing
99 \fInew_root\fP as root (\fI/\fP).
101 On success, zero is returned.
102 On error, \-1 is returned, and
103 \fIerrno\fP is set appropriately.
106 may return (in \fIerrno\fP) any of the errors returned by
108 Additionally, it may return:
111 \fInew_root\fP or \fIput_old\fP are on the current root file system,
112 or a file system is already mounted on \fIput_old\fP.
115 \fIput_old\fP is not underneath \fInew_root\fP.
118 \fInew_root\fP or \fIput_old\fP is not a directory.
121 The calling process does not have the
126 was introduced in Linux 2.3.41.
129 is Linux-specific and hence is not portable.
131 Glibc does not provide a wrapper for this system call; call it using
135 should not have to change root and current working directory of all other
136 processes in the system.
138 Some of the more obscure uses of