1PIVOT_ROOT(8) System Administration PIVOT_ROOT(8)
2
3
4
6 pivot_root - change the root filesystem
7
9 pivot_root new_root put_old
10
12 pivot_root moves the root file system of the current process to the
13 directory put_old and makes new_root the new root file system. Since
14 pivot_root(8) simply calls pivot_root(2), we refer to the man page of
15 the latter for further details.
16
17 Note that, depending on the implementation of pivot_root, root and
18 current working directory of the caller may or may not change. The
19 following is a sequence for invoking pivot_root that works in either
20 case, assuming that pivot_root and chroot are in the current PATH:
21
22 cd new_root
23 pivot_root . put_old
24 exec chroot . command
25
26 Note that chroot must be available under the old root and under the new
27 root, because pivot_root may or may not have implicitly changed the
28 root directory of the shell.
29
30 Note that exec chroot changes the running executable, which is
31 necessary if the old root directory should be unmounted afterwards.
32 Also note that standard input, output, and error may still point to a
33 device on the old root file system, keeping it busy. They can easily be
34 changed when invoking chroot (see below; note the absence of leading
35 slashes to make it work whether pivot_root has changed the shell’s root
36 or not).
37
39 -h, --help
40 Display help text and exit.
41
42 -V, --version
43 Print version and exit.
44
46 Change the root file system to /dev/hda1 from an interactive shell:
47
48 mount /dev/hda1 /new-root
49 cd /new-root
50 pivot_root . old-root
51 exec chroot . sh <dev/console >dev/console 2>&1
52 umount /old-root
53
54 Mount the new root file system over NFS from 10.0.0.1:/my_root and run
55 init:
56
57 ifconfig lo 127.0.0.1 up # for portmap
58 # configure Ethernet or such
59 portmap # for lockd (implicitly started by mount)
60 mount -o ro 10.0.0.1:/my_root /mnt
61 killall portmap # portmap keeps old root busy
62 cd /mnt
63 pivot_root . old_root
64 exec chroot . sh -c 'umount /old_root; exec /sbin/init' \
65 <dev/console >dev/console 2>&1
66
68 chroot(1), pivot_root(2), mount(8), switch_root(8), umount(8)
69
71 For bug reports, use the issue tracker at
72 https://github.com/util-linux/util-linux/issues.
73
75 The pivot_root command is part of the util-linux package which can be
76 downloaded from Linux Kernel Archive
77 <https://www.kernel.org/pub/linux/utils/util-linux/>.
78
79
80
81util-linux 2.38 2022-02-17 PIVOT_ROOT(8)