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
|
2004-11-03 14:43:40 +00:00
|
|
|
.\" Modified 2004-06-17 Michael Kerrisk <mtk-manpages@gmx.net>
|
2004-11-03 13:51:07 +00:00
|
|
|
.\"
|
|
|
|
.TH PIVOT_ROOT 2 2004-06-17 "Linux 2.6.7" "Linux Programmer's Manual"
|
|
|
|
.SH NAME
|
|
|
|
pivot_root \- change the root file system
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.B #include <linux/unistd.h>
|
2004-12-10 09:03:08 +00:00
|
|
|
.br
|
|
|
|
.B #include <errno.h>
|
2004-11-03 13:51:07 +00:00
|
|
|
.sp
|
|
|
|
.B _syscall2(int,pivot_root,const char *,new_root,const char *,put_old)
|
2006-03-16 00:50:08 +00:00
|
|
|
/* Using \fBsyscall\fP(2) may be preferable; see \fBintro\fP(2) */
|
2004-11-03 13:51:07 +00:00
|
|
|
.sp
|
|
|
|
.BI "int pivot_root(const char *" new_root ", const char *" put_old );
|
|
|
|
.SH DESCRIPTION
|
2005-10-19 06:54:38 +00:00
|
|
|
\fBpivot_root\fP() moves the root file system of the current 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
|
|
|
|
of the current process.
|
|
|
|
.\"
|
|
|
|
.\" The
|
|
|
|
.\" .B CAP_SYS_ADMIN
|
|
|
|
.\" capability is required.
|
|
|
|
|
2005-10-19 06:54:38 +00:00
|
|
|
The typical use of \fBpivot_root\fP() is during system startup, when the
|
2004-11-03 13:51:07 +00:00
|
|
|
system mounts a temporary root file system (e.g. an \fBinitrd\fP), then
|
|
|
|
mounts the real root file system, and eventually turns the latter into
|
|
|
|
the current root of all relevant processes or threads.
|
|
|
|
|
2005-10-19 06:54:38 +00:00
|
|
|
\fBpivot_root\fP() may or may not change the current root and the current
|
2004-11-03 13:51:07 +00:00
|
|
|
working directory (cwd) of any processes or threads which use the old
|
2005-10-19 06:54:38 +00:00
|
|
|
root directory. The caller of \fBpivot_root\fP()
|
2004-11-03 13:51:07 +00:00
|
|
|
must ensure that processes with root or cwd at the old root operate
|
|
|
|
correctly in either case. An easy way to ensure this is to change their
|
2005-10-19 06:54:38 +00:00
|
|
|
root and cwd to \fInew_root\fP before invoking \fBpivot_root\fP().
|
2004-11-03 13:51:07 +00:00
|
|
|
|
|
|
|
The paragraph above is intentionally vague because the implementation
|
2005-10-19 06:54:38 +00:00
|
|
|
of \fBpivot_root\fP() may change in the future. At the time of writing,
|
|
|
|
\fBpivot_root\fP() changes root and cwd of each process or
|
2004-11-03 13:51:07 +00:00
|
|
|
thread to \fInew_root\fP if they point to the old root directory. This
|
|
|
|
is necessary in order to prevent kernel threads from keeping the old
|
|
|
|
root directory busy with their root and cwd, even if they never access
|
|
|
|
the file system in any way. In the future, there may be a mechanism for
|
|
|
|
kernel threads to explicitly relinquish any access to the file system,
|
|
|
|
such that this fairly intrusive mechanism can be removed from
|
2005-10-19 06:54:38 +00:00
|
|
|
\fBpivot_root\fP().
|
2004-11-03 13:51:07 +00:00
|
|
|
|
2005-10-19 06:54:38 +00:00
|
|
|
Note that this also applies to the current process: \fBpivot_root\fP() may
|
2004-11-03 13:51:07 +00:00
|
|
|
or may not affect its cwd. It is therefore recommended to call
|
2005-10-19 06:54:38 +00:00
|
|
|
\fBchdir("/")\fP immediately after \fBpivot_root\fP().
|
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
|
|
|
|
\fIput_old\fP must be underneath \fInew_root\fP, i.e. adding a non-zero
|
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
|
|
|
|
See also \fBpivot_root(8)\fP for additional usage examples.
|
|
|
|
|
|
|
|
If the current root is not a mount point (e.g. after \fBchroot(2)\fP or
|
2005-10-19 06:54:38 +00:00
|
|
|
\fBpivot_root\fP(), 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.
|
|
|
|
.SH NOTES
|
|
|
|
\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
|
|
|
|
\fIerrno\fP is set appropriately.
|
|
|
|
.SH ERRORS
|
2005-10-19 06:54:38 +00:00
|
|
|
\fBpivot_root\fP() may return (in \fIerrno\fP) any of the errors returned by
|
2004-11-03 13:51:07 +00:00
|
|
|
\fBstat(2)\fP. Additionally, it may return:
|
|
|
|
|
|
|
|
.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
|
|
|
|
The current process does not have the
|
|
|
|
.B CAP_SYS_ADMIN
|
|
|
|
capability.
|
|
|
|
.SH BUGS
|
2005-10-19 06:54:38 +00:00
|
|
|
\fBpivot_root\fP() should not have to change root and cwd of all other
|
2004-11-03 13:51:07 +00:00
|
|
|
processes in the system.
|
|
|
|
|
2005-10-19 06:54:38 +00:00
|
|
|
Some of the more obscure uses of \fBpivot_root\fP() may quickly lead to
|
2004-11-03 13:51:07 +00:00
|
|
|
insanity.
|
|
|
|
.SH "CONFORMING TO"
|
2006-12-17 01:34:44 +00:00
|
|
|
\fBpivot_root\fP() is Linux specific and hence is not portable.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH HISTORY
|
2005-10-19 06:54:38 +00:00
|
|
|
\fBpivot_root\fP() was introduced in Linux 2.3.41.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR chdir (2),
|
|
|
|
.BR chroot (2),
|
|
|
|
.BR stat (2),
|
|
|
|
.BR initrd (4),
|
|
|
|
.BR pivot_root (8)
|