1 .TH PIVOT_ROOT 8 "August 2011" "util-linux" "System Administration"
3 pivot_root \- change the root filesystem
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.
10 Since \fBpivot_root\fP(8) simply calls \fBpivot_root\fP(2), we refer to
11 the man page of the latter for further details.
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:
20 pivot_root . \fIput_old\fP
22 exec chroot . \fIcommand\fP
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.
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
37 \fB\-V\fR, \fB\-\-version\fR
38 Display version information and exit.
40 \fB\-h\fR, \fB\-\-help\fR
41 Display help text and exit.
43 Change the root file system to /dev/hda1 from an interactive shell:
46 mount /dev/hda1 /new-root
49 exec chroot . sh <dev/console >dev/console 2>&1
53 Mount the new root file system over NFS from 10.0.0.1:/my_root and run
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
64 exec chroot . sh -c 'umount /old_root; exec /sbin/init' \\
65 <dev/console >dev/console 2>&1
74 The pivot_root command is part of the util-linux package and is available from
75 https://www.kernel.org/pub/linux/utils/util-linux/.