man-pages/man2/pivot_root.2

146 lines
4.3 KiB
Groff
Raw Normal View History

2004-11-03 13:51:07 +00:00
.\" Copyright (C) 2000 by Werner Almesberger
.\" May be distributed under GPL
.\"
.\" Written 2000-02-23 by Werner Almesberger
2007-09-20 06:52:22 +00:00
.\" Modified 2004-06-17 Michael Kerrisk <mtk.manpages@gmail.com>
2004-11-03 13:51:07 +00:00
.\"
.TH PIVOT_ROOT 2 2012-07-13 "Linux" "Linux Programmer's Manual"
2004-11-03 13:51:07 +00:00
.SH NAME
pivot_root \- change the root file system
.SH SYNOPSIS
.BI "int pivot_root(const char *" new_root ", const char *" put_old );
.IR Note :
There is no glibc wrapper for this system call; see NOTES.
2004-11-03 13:51:07 +00:00
.SH DESCRIPTION
.BR pivot_root ()
2007-12-27 16:01:37 +00:00
moves the root file system of the calling process to the
2004-11-03 13:51:07 +00:00
directory \fIput_old\fP and makes \fInew_root\fP the new root file system
2007-12-27 16:01:37 +00:00
of the calling process.
2004-11-03 13:51:07 +00:00
.\"
.\" The
.\" .B CAP_SYS_ADMIN
.\" capability is required.
The typical use of
.BR pivot_root ()
is during system startup, when the
system mounts a temporary root file system (e.g., an \fBinitrd\fP), then
2004-11-03 13:51:07 +00:00
mounts the real root file system, and eventually turns the latter into
the current root of all relevant processes or threads.
.BR pivot_root ()
may or may not change the current root and the current
2007-12-27 16:01:37 +00:00
working directory of any processes or threads which use the old
root directory.
The caller of
.BR pivot_root ()
2007-12-27 16:01:37 +00:00
must ensure that processes with root or current working directory
at the old root operate correctly in either case.
An easy way to ensure this is to change their
2007-12-27 16:01:37 +00:00
root and current working directory to \fInew_root\fP before invoking
.BR pivot_root ().
2004-11-03 13:51:07 +00:00
The paragraph above is intentionally vague because the implementation
of
.BR pivot_root ()
may change in the future.
At the time of writing,
.BR pivot_root ()
2007-12-27 16:01:37 +00:00
changes root and current working directory of each process or
thread to \fInew_root\fP if they point to the old root directory.
This
2004-11-03 13:51:07 +00:00
is necessary in order to prevent kernel threads from keeping the old
2007-12-27 16:01:37 +00:00
root directory busy with their root and current working directory,
even if they never access
the file system in any way.
In the future, there may be a mechanism for
2004-11-03 13:51:07 +00:00
kernel threads to explicitly relinquish any access to the file system,
such that this fairly intrusive mechanism can be removed from
.BR pivot_root ().
2004-11-03 13:51:07 +00:00
2007-12-27 16:01:37 +00:00
Note that this also applies to the calling process:
.BR pivot_root ()
may
2007-12-27 16:01:37 +00:00
or may not affect its current working directory.
It is therefore recommended to call
\fBchdir("/")\fP immediately after
.BR pivot_root ().
2004-11-03 13:51:07 +00:00
The following restrictions apply to \fInew_root\fP and \fIput_old\fP:
.IP \- 3
They must be directories.
.IP \- 3
\fInew_root\fP and \fIput_old\fP must not be on the same file system as
the current root.
.IP \- 3
intro.1, time.1, adjtimex.2, capget.2, eventfd.2, fcntl.2, getrlimit.2, getsockopt.2, gettimeofday.2, intro.2, ioctl_list.2, ioperm.2, mlock.2, pivot_root.2, poll.2, prctl.2, ptrace.2, sched_setscheduler.2, select_tut.2, semget.2, sigaltstack.2, signalfd.2, sysctl.2, timer_settime.2, timerfd_create.2, wait.2, CPU_SET.3, argz_add.3, assert_perror.3, atexit.3, backtrace.3, bcmp.3, clearenv.3, ctime.3, dl_iterate_phdr.3, dlopen.3, ecvt.3, errno.3, error.3, ether_aton.3, exit.3, fenv.3, ferror.3, finite.3, flockfile.3, fnmatch.3, fpathconf.3, fpclassify.3, ftime.3, ftok.3, ftw.3, fwide.3, getaddrinfo.3, gethostbyname.3, getlogin.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getrpcent.3, getservent.3, glob.3, hsearch.3, inet.3, isalpha.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, longjmp.3, lsearch.3, malloc.3, matherr.3, mblen.3, mbsinit.3, mbtowc.3, on_exit.3, printf.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_equal.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, ptsname.3, putenv.3, putgrent.3, raise.3, rcmd.3, regex.3, rexec.3, rpc.3, rpmatch.3, rtnetlink.3, scandir.3, sem_init.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, signbit.3, stdio_ext.3, strtod.3, strtol.3, strtoul.3, system.3, termios.3, timeradd.3, tzset.3, ualarm.3, wctomb.3, xdr.3, st.4, tty_ioctl.4, core.5, elf.5, proc.5, bootparam.7, capabilities.7, icmp.7, ip.7, ipv6.7, math_error.7, mdoc.samples.7, mq_overview.7, pthreads.7, raw.7, regex.7, socket.7, tcp.7, tzselect.8: Global fix: s/non-zero/nonzero/ The tendency in English, as prescribed in style guides like Chicago MoS, is towards removing hyphens after prefixes like "non-" etc. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:40:55 +00:00
\fIput_old\fP must be underneath \fInew_root\fP, that is, adding a nonzero
2005-11-02 13:55:25 +00:00
number of \fI/..\fP to the string pointed to by \fIput_old\fP must yield
2004-11-03 13:51:07 +00:00
the same directory as \fInew_root\fP.
.IP \- 3
No other file system may be mounted on \fIput_old\fP.
.PP
2007-06-21 22:55:04 +00:00
See also
.BR pivot_root (8)
for additional usage examples.
2004-11-03 13:51:07 +00:00
If the current root is not a mount point (e.g., after
.BR chroot (2)
or
.BR pivot_root (),
see also below), not the old root directory, but the
2004-11-03 13:51:07 +00:00
mount point of that file system is mounted on \fIput_old\fP.
\fInew_root\fP does not have to be a mount point.
In this case,
2005-11-02 13:55:25 +00:00
\fI/proc/mounts\fP will show the mount point of the file system containing
\fInew_root\fP as root (\fI/\fP).
2004-11-03 13:51:07 +00:00
.SH "RETURN VALUE"
On success, zero is returned.
On error, \-1 is returned, and
2004-11-03 13:51:07 +00:00
\fIerrno\fP is set appropriately.
.SH ERRORS
.BR pivot_root ()
may return (in \fIerrno\fP) any of the errors returned by
.BR stat (2).
Additionally, it may return:
2004-11-03 13:51:07 +00:00
.TP
.B EBUSY
\fInew_root\fP or \fIput_old\fP are on the current root file system,
or a file system is already mounted on \fIput_old\fP.
.TP
.B EINVAL
\fIput_old\fP is not underneath \fInew_root\fP.
.TP
.B ENOTDIR
\fInew_root\fP or \fIput_old\fP is not a directory.
.TP
.B EPERM
2007-12-27 16:01:37 +00:00
The calling process does not have the
2004-11-03 13:51:07 +00:00
.B CAP_SYS_ADMIN
capability.
.SH VERSIONS
.BR pivot_root ()
was introduced in Linux 2.3.41.
.SH "CONFORMING TO"
.BR pivot_root ()
2007-12-25 21:28:09 +00:00
is Linux-specific and hence is not portable.
2007-06-14 06:31:39 +00:00
.SH NOTES
Glibc does not provide a wrapper for this system call; call it using
.BR syscall (2).
2004-11-03 13:51:07 +00:00
.SH BUGS
.BR pivot_root ()
2007-12-27 16:01:37 +00:00
should not have to change root and current working directory of all other
2004-11-03 13:51:07 +00:00
processes in the system.
Some of the more obscure uses of
.BR pivot_root ()
may quickly lead to
2004-11-03 13:51:07 +00:00
insanity.
.SH "SEE ALSO"
.BR chdir (2),
.BR chroot (2),
.BR stat (2),
.BR initrd (4),
.BR pivot_root (8)