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 2019-08-02 "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 changes the root filesystem in the mount namespace of the calling process.
21 More precisely, it moves the root filesystem to the
22 directory \fIput_old\fP and makes \fInew_root\fP the new root filesystem.
23 The calling process must have the
25 capability in the user namespace that owns the caller's mount namespace.
29 is during system startup, when the
30 system mounts a temporary root filesystem (e.g., an \fBinitrd\fP), then
31 mounts the real root filesystem, 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 that
37 use the old root directory and which are in
38 the same mount namespace as the caller of
42 must ensure that processes with root or current working directory
43 at the old root operate correctly in either case.
44 An easy way to ensure this is to change their
45 root and current working directory to \fInew_root\fP before invoking
48 The paragraph above is intentionally vague because the implementation of
50 may change in the future.
53 changes the root directory and the current working directory
54 of each process or thread in the same mount namespace to
56 if they point to the old root directory.
57 This is necessary in order to prevent kernel threads from keeping the old
58 root directory busy with their root and current working directory,
59 even if they never access
60 the filesystem in any way.
61 In the future, there may be a mechanism for
62 kernel threads to explicitly relinquish any access to the filesystem,
63 such that this fairly intrusive mechanism can be removed from
66 Note that this also applies to the calling process:
68 may or may not affect its current working directory.
69 It is therefore recommended to call
70 \fBchdir("/")\fP immediately after
73 The following restrictions apply to \fInew_root\fP and \fIput_old\fP:
75 They must be directories.
77 \fInew_root\fP and \fIput_old\fP must not be on the same filesystem as
80 \fIput_old\fP must be underneath \fInew_root\fP, that is, adding a nonzero
81 number of \fI/..\fP to the string pointed to by \fIput_old\fP must yield
82 the same directory as \fInew_root\fP.
85 must be a mount point.
86 (If it is not otherwise a mount point, it suffices to bind mount
90 The propagation type of
92 and its parent mount must not be
96 is an existing mount point, its propagation type must not be
99 No other filesystem may be mounted on \fIput_old\fP.
103 for additional usage examples.
105 If the current root is not a mount point (e.g., after an earlier
109 then the mount point of the filesystem containing the current root directory
110 (i.e., not the directory itself) is mounted on \fIput_old\fP.
112 On success, zero is returned.
113 On error, \-1 is returned, and
114 \fIerrno\fP is set appropriately.
117 may fail with any of the same errors as
119 Additionally, it may fail with the following errors:
122 \fInew_root\fP or \fIput_old\fP are on the current root filesystem,
123 or a filesystem is already mounted on \fIput_old\fP.
127 is not a mount point.
130 \fIput_old\fP is not underneath \fInew_root\fP.
133 The current root is on the rootfs (initial ramfs) filesystem.
136 Either the mount point at
138 or the parent mount of that mount point,
144 is a mount point and has the propagation type
148 \fInew_root\fP or \fIput_old\fP is not a directory.
151 The calling process does not have the
156 was introduced in Linux 2.3.41.
159 is Linux-specific and hence is not portable.
161 Glibc does not provide a wrapper for this system call; call it using
164 The rootfs (initial ramfs) cannot be
166 The recommended method of changing the root filesystem in this case is
167 to delete everything in rootfs, overmount rootfs with the new root, attach
168 .IR stdin / stdout / stderr
173 Helper programs for this process exist; see
177 should not have to change root and current working directory of other
178 processes in the system.
180 Some of the more obscure uses of
190 .BR mount_namespaces (7),