]>
Commit | Line | Data |
---|---|---|
22853e4a KZ |
1 | .TH PIVOT_ROOT 8 "Feb 23, 2000" "Linux" "Maintenance Commands" |
2 | .SH NAME | |
3 | pivot_root \- change the root file system | |
4 | .SH SYNOPSIS | |
5 | .B pivot_root | |
48962512 | 6 | .I new_root put_old |
22853e4a KZ |
7 | .SH DESCRIPTION |
8 | \fBpivot_root\fP moves the root file system of the current process to the | |
9 | directory \fIput_old\fP and makes \fInew_root\fP the new root file system. | |
48962512 | 10 | Since \fBpivot_root\fP(8) simply calls \fBpivot_root\fP(2), we refer to |
22853e4a KZ |
11 | the man page of the latter for further details. |
12 | ||
13 | Note that, depending on the implementation of \fBpivot_root\fP, root and | |
14 | cwd of the caller may or may not change. The following is a sequence for | |
15 | invoking \fBpivot_root\fP that works in either case, assuming that | |
16 | \fBpivot_root\fP and \fBchroot\fP are in the current \fBPATH\fP: | |
17 | .sp | |
18 | cd \fInew_root\fP | |
19 | .br | |
20 | pivot_root . \fIput_old\fP | |
21 | .br | |
22 | exec chroot . \fIcommand\fP | |
23 | .sp | |
24 | Note that \fBchroot\fP must be available under the old root and under the new | |
25 | root, because \fBpivot_root\fP may or may not have implicitly changed the | |
26 | root directory of the shell. | |
27 | ||
28 | Note that \fBexec chroot\fP changes the running executable, which is | |
29 | necessary if the old root directory should be unmounted afterwards. | |
30 | Also note that standard input, output, and error may still point to a | |
31 | device on the old root file system, keeping it busy. They can easily be | |
32 | changed when invoking \fBchroot\fP (see below; note the absence of | |
33 | leading slashes to make it work whether \fBpivot_root\fP has changed the | |
34 | shell's root or not). | |
35 | .SH EXAMPLES | |
36 | Change the root file system to /dev/hda1 from an interactive shell: | |
37 | .sp | |
38 | .nf | |
39 | mount /dev/hda1 /new-root | |
40 | cd /new-root | |
41 | pivot_root . old-root | |
42 | exec chroot . sh <dev/console >dev/console 2>&1 | |
43 | umount /old-root | |
44 | .fi | |
45 | .sp | |
46 | Mount the new root file system over NFS from 10.0.0.1:/my_root and run | |
47 | \fBinit\fP: | |
48 | .sp | |
49 | .nf | |
50 | ifconfig lo 127.0.0.1 up # for portmap | |
51 | # configure Ethernet or such | |
52 | portmap # for lockd (implicitly started by mount) | |
53 | mount -o ro 10.0.0.1:/my_root /mnt | |
54 | killall portmap # portmap keeps old root busy | |
55 | cd /mnt | |
56 | pivot_root . old_root | |
57 | exec chroot . sh -c 'umount /old_root; exec /sbin/init' \\ | |
58 | <dev/console >dev/console 2>&1 | |
59 | .fi | |
60 | .SH "SEE ALSO" | |
48962512 PB |
61 | .BR chroot (1), |
62 | .BR mount (8), | |
63 | .BR pivot_root (2), | |
64 | .BR umount (8) | |
86d62711 KZ |
65 | .SH AVAILABILITY |
66 | The pivot_root command is part of the util-linux-ng package and is available from | |
67 | ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/. |