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       #include <linux/unistd.h>
10       #include <errno.h>
11
12       _syscall2(int,pivot_root,const char *,new_root,const char *,put_old)
13                 /* Using syscall(2) may be preferable; see intro(2) */
14
15       int pivot_root(const char *new_root, const char *put_old);
16

DESCRIPTION

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

NOTES

68       new_root does not have to be a mount point. In this case,  /proc/mounts
69       will  show  the  mount  point of the file system containing new_root as
70       root (/).
71

RETURN VALUE

73       On success, zero is returned.  On error, -1 is returned, and  errno  is
74       set appropriately.
75

ERRORS

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

BUGS

92       pivot_root()  should  not have to change root and cwd of all other pro‐
93       cesses in the system.
94
95       Some of the more obscure uses  of  pivot_root()  may  quickly  lead  to
96       insanity.
97

CONFORMING TO

99       pivot_root() is Linux specific and hence is not portable.
100

HISTORY

102       pivot_root() was introduced in Linux 2.3.41.
103

SEE ALSO

105       chdir(2), chroot(2), stat(2), initrd(4), pivot_root(8)
106
107
108
109Linux 2.6.7                       2004-06-17                     PIVOT_ROOT(2)
Impressum