Seth Woolley's Man Viewer

Manual for pivot_root - man 2 pivot_root

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

PIVOT_ROOT(2)                    System Calls                    PIVOT_ROOT(2)

       pivot_root(2,8) - change the root file(1,n) system

       #include <linux/unistd.h>

       _syscall2(int,pivot_root(2,8),const char *,new_root,const char *,put_old)

       int pivot_root(2,8)(const char *new_root, const char *put_old);

       pivot_root(2,8)  moves  the  root  file(1,n) system of the current process to the
       directory put_old and makes new_root the new root file(1,n)  system  of  the
       current process.

       The typical use of pivot_root(2,8) is during system startup, when the system
       mounts a temporary root file(1,n) system (e.g. an initrd), then  mounts  the
       real root file(1,n) system, and eventually turns the latter into the current
       root of all relevant processes or threads.

       pivot_root(2,8) may or may not change the current root and the current work-
       ing  directory (cwd) of any processes or threads which use the old root
       directory. The caller of pivot_root(2,8) must  ensure  that  processes  with
       root  or  cwd at the old root operate correctly in(1,8) either case. An easy
       way to ensure this is to change their root and cwd to  new_root  before
       invoking pivot_root(2,8).

       The  paragraph  above is intentionally vague because the implementation
       of pivot_root(2,8) may change  in(1,8)  the  future.  At  the  time(1,2,n)  of  writing,
       pivot_root(2,8)  changes  root and cwd of each process or thread to new_root
       if(3,n) they point to the old root directory. This is necessary in(1,8) order  to
       prevent  kernel  threads  from keeping the old root directory busy with
       their root and cwd, even if(3,n) they never access(2,5) the file(1,n)  system  in(1,8)  any
       way.  In  the  future,  there  may be a mechanism for kernel threads to
       explicitly relinquish any access(2,5) to the file(1,n)  system,  such  that  this
       fairly intrusive mechanism can be removed from pivot_root(2,8).

       Note  that  this also applies to the current process: pivot_root(2,8) may or
       may not affect its cwd. It is therefore recommended to call  chdir("/")
       immediately after pivot_root(2,8).

       The following restrictions apply to new_root and put_old:

       -  They must be directories.

       -  new_root and put_old must not be on the same file(1,n) system as the cur-
          rent root.

       -  put_old must be underneath new_root, i.e. adding a  non-zero  number
          of  /..  to  the  string(3,n)  pointed  to by put_old must yield the same
          directory as new_root.

       -  No other file(1,n) system may be mounted on put_old.

       See also pivot_root(2,8)(8) for additional usage examples.

       If the current root is not a  mount(2,8)  point  (e.g.  after  chroot(1,2)(2)  or
       pivot_root(2,8),  see also below), not the old root directory, but the mount(2,8)
       point of that file(1,n) system is mounted on put_old.

       new_root does not have to be a mount(2,8) point. In this case,  /proc(5,n)/mounts
       will  show  the  mount(2,8)  point of the file(1,n) system containing new_root as
       root (/).

       On success, zero is returned.  On error(8,n), -1 is returned, and  errno  is
       set(7,n,1 builtins) appropriately.

       pivot_root(2,8) may return (in(1,8) errno) any of the errors returned by stat(1,2)(2).
       Additionally, it may return:

       EBUSY  new_root or put_old are on the current root file(1,n)  system,  or  a
              file(1,n) system is already mounted on put_old.

       EINVAL put_old is not underneath new_root.

              new_root or put_old is not a directory.

       EPERM  The  current process does not have the administrator capability.

       pivot_root(2,8) should not have to change root and cwd  of  all  other  pro-
       cesses in(1,8) the system.

       Some  of the more obscure uses of pivot_root(2,8) may quickly lead to insan-

       pivot_root(2,8) was introduced in(1,8) Linux 2.3.41.

       chdir(2), chroot(1,2)(2), initrd(4), pivot_root(2,8)(8), stat(1,2)(2)

Linux                            Feb 23, 2000                    PIVOT_ROOT(2)

References for this manual (incoming links)