1 .\" Copyright (C) 2000 by Werner Almesberger
2 .\" May be distributed under GPL
4 .\" Written 2000-02-23 by Werner Almesberger
5 .\" Modified 2004-06-17 Michael Kerrisk <mtk.manpages@gmail.com>
7 .TH PIVOT_ROOT 2 2007-06-01 "Linux" "Linux Programmer's Manual"
9 pivot_root \- change the root file system
11 .BI "int pivot_root(const char *" new_root ", const char *" put_old );
14 moves the root file system of the calling process to the
15 directory \fIput_old\fP and makes \fInew_root\fP the new root file system
16 of the calling process.
20 .\" capability is required.
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.
30 may or may not change the current root and the current
31 working directory of any processes or threads which use the old
35 must ensure that processes with root or current working directory
36 at the old root operate correctly in either case.
37 An easy way to ensure this is to change their
38 root and current working directory to \fInew_root\fP before invoking
41 The paragraph above is intentionally vague because the implementation
44 may change in the future.
45 At the time of writing,
47 changes root and current working directory of each process or
48 thread to \fInew_root\fP if they point to the old root directory.
50 is necessary in order to prevent kernel threads from keeping the old
51 root directory busy with their root and current working directory,
52 even if they never access
53 the file system in any way.
54 In the future, there may be a mechanism for
55 kernel threads to explicitly relinquish any access to the file system,
56 such that this fairly intrusive mechanism can be removed from
59 Note that this also applies to the calling process:
62 or may not affect its current working directory.
63 It is therefore recommended to call
64 \fBchdir("/")\fP immediately after
67 The following restrictions apply to \fInew_root\fP and \fIput_old\fP:
69 They must be directories.
71 \fInew_root\fP and \fIput_old\fP must not be on the same file system as
74 \fIput_old\fP must be underneath \fInew_root\fP, that is, adding a nonzero
75 number of \fI/..\fP to the string pointed to by \fIput_old\fP must yield
76 the same directory as \fInew_root\fP.
78 No other file system may be mounted on \fIput_old\fP.
82 for additional usage examples.
84 If the current root is not a mount point (e.g., after
88 see also below), not the old root directory, but the
89 mount point of that file system is mounted on \fIput_old\fP.
91 \fInew_root\fP does not have to be a mount point.
93 \fI/proc/mounts\fP will show the mount point of the file system containing
94 \fInew_root\fP as root (\fI/\fP).
96 On success, zero is returned.
97 On error, \-1 is returned, and
98 \fIerrno\fP is set appropriately.
101 may return (in \fIerrno\fP) any of the errors returned by
103 Additionally, it may return:
106 \fInew_root\fP or \fIput_old\fP are on the current root file system,
107 or a file system is already mounted on \fIput_old\fP.
110 \fIput_old\fP is not underneath \fInew_root\fP.
113 \fInew_root\fP or \fIput_old\fP is not a directory.
116 The calling process does not have the
121 was introduced in Linux 2.3.41.
124 is Linux-specific and hence is not portable.
126 Glibc does not provide a wrapper for this system call; call it using
130 should not have to change root and current working directory of all other
131 processes in the system.
133 Some of the more obscure uses of