version 1, including all changes.
.
| Rev |
Author |
# |
Line |
| 1 |
perry |
1 |
PIVOT_ROOT |
| |
|
2 |
!!!PIVOT_ROOT |
| |
|
3 |
NAME |
| |
|
4 |
SYNOPSIS |
| |
|
5 |
DESCRIPTION |
| |
|
6 |
EXAMPLES |
| |
|
7 |
SEE ALSO |
| |
|
8 |
---- |
| |
|
9 |
!!NAME |
| |
|
10 |
|
| |
|
11 |
|
| |
|
12 |
pivot_root - change the root file system |
| |
|
13 |
!!SYNOPSIS |
| |
|
14 |
|
| |
|
15 |
|
| |
|
16 |
__pivot_root__ ''new_root put_old'' |
| |
|
17 |
!!DESCRIPTION |
| |
|
18 |
|
| |
|
19 |
|
| |
|
20 |
__pivot_root__ moves the root file system of the current |
| |
|
21 |
process to the directory ''put_old'' and makes |
| |
|
22 |
''new_root'' the new root file system. Since |
| |
|
23 |
__pivot_root(8)__ simply calls __pivot_root(2)__, we |
| |
|
24 |
refer to the man page of the latter for further |
| |
|
25 |
details. |
| |
|
26 |
|
| |
|
27 |
|
| |
|
28 |
Note that, depending on the implementation of |
| |
|
29 |
__pivot_root__, root and cwd of the caller may or may not |
| |
|
30 |
change. The following is a sequence for invoking |
| |
|
31 |
__pivot_root__ that works in either case, assuming that |
| |
|
32 |
__pivot_root__ and __chroot__ are in the current |
| |
|
33 |
__PATH__: |
| |
|
34 |
|
| |
|
35 |
|
| |
|
36 |
cd ''new_root'' |
| |
|
37 |
pivot_root . ''put_old'' |
| |
|
38 |
exec chroot . ''command'' |
| |
|
39 |
|
| |
|
40 |
|
| |
|
41 |
Note that __chroot__ must be available under the old root |
| |
|
42 |
and under the new root, because __pivot_root__ may or may |
| |
|
43 |
not have implicitly changed the root directory of the |
| |
|
44 |
shell. |
| |
|
45 |
|
| |
|
46 |
|
| |
|
47 |
Note that __exec chroot__ changes the running executable, |
| |
|
48 |
which is necessary if the old root directory should be |
| |
|
49 |
unmounted afterwards. Also note that standard input, output, |
| |
|
50 |
and error may still point to a device on the old root file |
| |
|
51 |
system, keeping it busy. They can easily be changed when |
| |
|
52 |
invoking __chroot__ (see below; note the absence of |
| |
|
53 |
leading slashes to make it work whether __pivot_root__ |
| |
|
54 |
has changed the shell's root or not). |
| |
|
55 |
!!EXAMPLES |
| |
|
56 |
|
| |
|
57 |
|
| |
|
58 |
Change the root file system to /dev/hda1 from an interactive |
| |
|
59 |
shell: |
| |
|
60 |
|
| |
|
61 |
|
| |
|
62 |
mount /dev/hda1 /new-root |
| |
|
63 |
cd /new-root |
| |
|
64 |
pivot_root . old-root |
| |
|
65 |
exec chroot . sh |
| |
|
66 |
Mount the new root file system over NFS from 10.0.0.1:/my_root and run __init__: |
| |
|
67 |
|
| |
|
68 |
|
| |
|
69 |
ifconfig lo 127.0.0.1 up # for portmap |
| |
|
70 |
# configure Ethernet or such |
| |
|
71 |
portmap # for lockd (implicitly started by mount) |
| |
|
72 |
mount -o ro 10.0.0.1:/my_root /mnt |
| |
|
73 |
killall portmap # portmap keeps old root busy |
| |
|
74 |
cd /mnt |
| |
|
75 |
pivot_root . old_root |
| |
|
76 |
exec chroot . sh -c 'umount /old_root; exec /sbin/init' \ |
| |
|
77 |
!!SEE ALSO |
| |
|
78 |
|
| |
|
79 |
|
| |
|
80 |
__chroot(1), mount(8), pivot_root(2), |
| |
|
81 |
umount(8)__ |
| |
|
82 |
---- |