OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man2 / pivot_root.2
1 .\" Copyright (C) 2000 by Werner Almesberger
2 .\"
3 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
4 .\" May be distributed under GPL
5 .\" %%%LICENSE_END
6 .\"
7 .\" Written 2000-02-23 by Werner Almesberger
8 .\" Modified 2004-06-17 Michael Kerrisk <mtk.manpages@gmail.com>
9 .\"
10 .TH PIVOT_ROOT 2 2012-07-13 "Linux" "Linux Programmer's Manual"
11 .SH NAME
12 pivot_root \- change the root filesystem
13 .SH SYNOPSIS
14 .BI "int pivot_root(const char *" new_root ", const char *" put_old );
15
16 .IR Note :
17 There is no glibc wrapper for this system call; see NOTES.
18 .SH DESCRIPTION
19 .BR pivot_root ()
20 moves the root filesystem of the calling process to the
21 directory \fIput_old\fP and makes \fInew_root\fP the new root filesystem
22 of the calling process.
23 .\"
24 .\" The
25 .\" .B CAP_SYS_ADMIN
26 .\" capability is required.
27
28 The typical use of
29 .BR pivot_root ()
30 is during system startup, when the
31 system mounts a temporary root filesystem (e.g., an \fBinitrd\fP), then
32 mounts the real root filesystem, and eventually turns the latter into
33 the current root of all relevant processes or threads.
34
35 .BR pivot_root ()
36 may or may not change the current root and the current
37 working directory of any processes or threads which use the old
38 root directory.
39 The caller of
40 .BR pivot_root ()
41 must ensure that processes with root or current working directory
42 at the old root operate correctly in either case.
43 An easy way to ensure this is to change their
44 root and current working directory to \fInew_root\fP before invoking
45 .BR pivot_root ().
46
47 The paragraph above is intentionally vague because the implementation
48 of
49 .BR pivot_root ()
50 may change in the future.
51 At the time of writing,
52 .BR pivot_root ()
53 changes root and current working directory of each process or
54 thread to \fInew_root\fP if they point to the old root directory.
55 This
56 is necessary in order to prevent kernel threads from keeping the old
57 root directory busy with their root and current working directory,
58 even if they never access
59 the filesystem in any way.
60 In the future, there may be a mechanism for
61 kernel threads to explicitly relinquish any access to the filesystem,
62 such that this fairly intrusive mechanism can be removed from
63 .BR pivot_root ().
64
65 Note that this also applies to the calling process:
66 .BR pivot_root ()
67 may
68 or may not affect its current working directory.
69 It is therefore recommended to call
70 \fBchdir("/")\fP immediately after
71 .BR pivot_root ().
72
73 The following restrictions apply to \fInew_root\fP and \fIput_old\fP:
74 .IP \- 3
75 They must be directories.
76 .IP \- 3
77 \fInew_root\fP and \fIput_old\fP must not be on the same filesystem as
78 the current root.
79 .IP \- 3
80 \fIput_old\fP must be underneath \fInew_root\fP, that is, adding a nonzero
81 number of \fI/..\fP to the string pointed to by \fIput_old\fP must yield
82 the same directory as \fInew_root\fP.
83 .IP \- 3
84 No other filesystem may be mounted on \fIput_old\fP.
85 .PP
86 See also
87 .BR pivot_root (8)
88 for additional usage examples.
89
90 If the current root is not a mount point (e.g., after
91 .BR chroot (2)
92 or
93 .BR pivot_root (),
94 see also below), not the old root directory, but the
95 mount point of that filesystem is mounted on \fIput_old\fP.
96
97 \fInew_root\fP does not have to be a mount point.
98 In this case,
99 \fI/proc/mounts\fP will show the mount point of the filesystem containing
100 \fInew_root\fP as root (\fI/\fP).
101 .SH RETURN VALUE
102 On success, zero is returned.
103 On error, \-1 is returned, and
104 \fIerrno\fP is set appropriately.
105 .SH ERRORS
106 .BR pivot_root ()
107 may return (in \fIerrno\fP) any of the errors returned by
108 .BR stat (2).
109 Additionally, it may return:
110 .TP
111 .B EBUSY
112 \fInew_root\fP or \fIput_old\fP are on the current root filesystem,
113 or a filesystem is already mounted on \fIput_old\fP.
114 .TP
115 .B EINVAL
116 \fIput_old\fP is not underneath \fInew_root\fP.
117 .TP
118 .B ENOTDIR
119 \fInew_root\fP or \fIput_old\fP is not a directory.
120 .TP
121 .B EPERM
122 The calling process does not have the
123 .B CAP_SYS_ADMIN
124 capability.
125 .SH VERSIONS
126 .BR pivot_root ()
127 was introduced in Linux 2.3.41.
128 .SH CONFORMING TO
129 .BR pivot_root ()
130 is Linux-specific and hence is not portable.
131 .SH NOTES
132 Glibc does not provide a wrapper for this system call; call it using
133 .BR syscall (2).
134 .SH BUGS
135 .BR pivot_root ()
136 should not have to change root and current working directory of all other
137 processes in the system.
138
139 Some of the more obscure uses of
140 .BR pivot_root ()
141 may quickly lead to
142 insanity.
143 .SH SEE ALSO
144 .BR chdir (2),
145 .BR chroot (2),
146 .BR stat (2),
147 .BR initrd (4),
148 .BR pivot_root (8)
149 .SH COLOPHON
150 This page is part of release 3.79 of the Linux
151 .I man-pages
152 project.
153 A description of the project,
154 information about reporting bugs,
155 and the latest version of this page,
156 can be found at
157 \%http://www.kernel.org/doc/man\-pages/.