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

NAME

6       pivot_root - change the root file system
7

SYNOPSIS

9       int pivot_root(const char *new_root, const char *put_old);
10

DESCRIPTION

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

RETURN VALUE

67       On  success,  zero is returned.  On error, -1 is returned, and errno is
68       set appropriately.
69

ERRORS

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

VERSIONS

85       pivot_root() was introduced in Linux 2.3.41.
86

CONFORMING TO

88       pivot_root() is Linux-specific and hence is not portable.
89

NOTES

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

BUGS

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

SEE ALSO

102       chdir(2), chroot(2), stat(2), initrd(4), pivot_root(8)
103

COLOPHON

105       This  page  is  part of release 3.22 of the Linux man-pages project.  A
106       description of the project, and information about reporting  bugs,  can
107       be found at http://www.kernel.org/doc/man-pages/.
108
109
110
111Linux                             2007-06-01                     PIVOT_ROOT(2)
Impressum