1PIVOT_ROOT(2)              Linux Programmer's Manual             PIVOT_ROOT(2)
2
3
4

NAME

6       pivot_root - change the root filesystem
7

SYNOPSIS

9       int pivot_root(const char *new_root, const char *put_old);
10
11       Note: There is no glibc wrapper for this system call; see NOTES.
12

DESCRIPTION

14       pivot_root()  moves  the  root filesystem of the calling process to the
15       directory put_old and makes new_root the new  root  filesystem  of  the
16       calling process.
17
18       The typical use of pivot_root() is during system startup, when the sys‐
19       tem mounts a temporary root filesystem (e.g., an initrd),  then  mounts
20       the real root filesystem, and eventually turns the latter into the cur‐
21       rent root of all relevant processes or threads.
22
23       pivot_root() may or may not change the current  root  and  the  current
24       working  directory  of  any processes or threads which use the old root
25       directory.  The caller of pivot_root() must ensure that processes  with
26       root  or current working directory at the old root operate correctly in
27       either case.  An easy way to ensure this is to change  their  root  and
28       current working directory to new_root before invoking pivot_root().
29
30       The  paragraph  above is intentionally vague because the implementation
31       of pivot_root() may change in the future.   At  the  time  of  writing,
32       pivot_root() changes root and current working directory of each process
33       or thread to new_root if they point to the old root directory.  This is
34       necessary  in order to prevent kernel threads from keeping the old root
35       directory busy with their root and current working directory,  even  if
36       they  never access the filesystem in any way.  In the future, there may
37       be a mechanism for kernel threads to explicitly relinquish  any  access
38       to  the  filesystem,  such  that this fairly intrusive mechanism can be
39       removed from pivot_root().
40
41       Note that this also applies to the calling process: pivot_root() may or
42       may  not  affect its current working directory.  It is therefore recom‐
43       mended to call chdir("/") immediately after pivot_root().
44
45       The following restrictions apply to new_root and put_old:
46
47       -  They must be directories.
48
49       -  new_root and put_old must not be on the same filesystem as the  cur‐
50          rent root.
51
52       -  put_old  must be underneath new_root, that is, adding a nonzero num‐
53          ber of /.. to the string pointed to by put_old must yield  the  same
54          directory as new_root.
55
56       -  No other filesystem may be mounted on put_old.
57
58       See also pivot_root(8) for additional usage examples.
59
60       If  the  current  root  is  not a mount point (e.g., after chroot(2) or
61       pivot_root(), see also below), not the  old  root  directory,  but  the
62       mount point of that filesystem is mounted on put_old.
63
64       new_root does not have to be a mount point.  In this case, /proc/mounts
65       will show the mount point of the filesystem containing new_root as root
66       (/).
67

RETURN VALUE

69       On  success,  zero is returned.  On error, -1 is returned, and errno is
70       set appropriately.
71

ERRORS

73       pivot_root() may return (in  errno)  any  of  the  errors  returned  by
74       stat(2).  Additionally, it may return:
75
76       EBUSY  new_root  or  put_old  are  on the current root filesystem, or a
77              filesystem is already mounted on put_old.
78
79       EINVAL put_old is not underneath new_root.
80
81       ENOTDIR
82              new_root or put_old is not a directory.
83
84       EPERM  The calling process does not have the CAP_SYS_ADMIN capability.
85

VERSIONS

87       pivot_root() was introduced in Linux 2.3.41.
88

CONFORMING TO

90       pivot_root() is Linux-specific and hence is not portable.
91

NOTES

93       Glibc does not provide a wrapper for this system call;  call  it  using
94       syscall(2).
95

BUGS

97       pivot_root()  should not have to change root and current working direc‐
98       tory of all other processes in the system.
99
100       Some of the more obscure uses  of  pivot_root()  may  quickly  lead  to
101       insanity.
102

SEE ALSO

104       chdir(2), chroot(2), stat(2), initrd(4), pivot_root(8), switch_root(8)
105

COLOPHON

107       This  page  is  part of release 4.15 of the Linux man-pages project.  A
108       description of the project, information about reporting bugs,  and  the
109       latest     version     of     this    page,    can    be    found    at
110       https://www.kernel.org/doc/man-pages/.
111
112
113
114Linux                             2017-09-15                     PIVOT_ROOT(2)
Impressum