1 .\" Copyright (C) 2000 by Werner Almesberger
3 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
4 .\" May be distributed under GPL
7 .\" Written 2000-02-23 by Werner Almesberger
8 .\" Modified 2004-06-17 Michael Kerrisk <mtk.manpages@gmail.com>
10 .TH PIVOT_ROOT 2 2012-07-13 "Linux" "Linux Programmer's Manual"
12 pivot_root \- change the root filesystem
14 .BI "int pivot_root(const char *" new_root ", const char *" put_old );
17 There is no glibc wrapper for this system call; see NOTES.
20 moves the root filesystem of the calling process to the
21 directory \fIput_old\fP and makes \fInew_root\fP the new root filesystem
22 of the calling process.
26 .\" capability is required.
30 is during system startup, when the
31 system mounts a temporary root filesystem (e.g., an \fBinitrd\fP), then
32 mounts the real root filesystem, and eventually turns the latter into
33 the current root of all relevant processes or threads.
36 may or may not change the current root and the current
37 working directory of any processes or threads which use the old
41 must ensure that processes with root or current working directory
42 at the old root operate correctly in either case.
43 An easy way to ensure this is to change their
44 root and current working directory to \fInew_root\fP before invoking
47 The paragraph above is intentionally vague because the implementation of
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.
54 This is necessary in order to prevent kernel threads from keeping the old
55 root directory busy with their root and current working directory,
56 even if they never access
57 the filesystem in any way.
58 In the future, there may be a mechanism for
59 kernel threads to explicitly relinquish any access to the filesystem,
60 such that this fairly intrusive mechanism can be removed from
63 Note that this also applies to the calling process:
65 may or may not affect its current working directory.
66 It is therefore recommended to call
67 \fBchdir("/")\fP immediately after
70 The following restrictions apply to \fInew_root\fP and \fIput_old\fP:
72 They must be directories.
74 \fInew_root\fP and \fIput_old\fP must not be on the same filesystem as
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.
81 No other filesystem may be mounted on \fIput_old\fP.
85 for additional usage examples.
87 If the current root is not a mount point (e.g., after
91 see also below), not the old root directory, but the
92 mount point of that filesystem is mounted on \fIput_old\fP.
94 \fInew_root\fP does not have to be a mount point.
96 \fI/proc/mounts\fP will show the mount point of the filesystem containing
97 \fInew_root\fP as root (\fI/\fP).
99 On success, zero is returned.
100 On error, \-1 is returned, and
101 \fIerrno\fP is set appropriately.
104 may return (in \fIerrno\fP) any of the errors returned by
106 Additionally, it may return:
109 \fInew_root\fP or \fIput_old\fP are on the current root filesystem,
110 or a filesystem is already mounted on \fIput_old\fP.
113 \fIput_old\fP is not underneath \fInew_root\fP.
116 \fInew_root\fP or \fIput_old\fP is not a directory.
119 The calling process does not have the
124 was introduced in Linux 2.3.41.
127 is Linux-specific and hence is not portable.
129 Glibc does not provide a wrapper for this system call; call it using
133 should not have to change root and current working directory of all other
134 processes in the system.
136 Some of the more obscure uses of