]> git.ipfire.org Git - thirdparty/util-linux.git/blame - sys-utils/pivot_root.8
lscpu: check scols_line_set_data() return value [coverity scan]
[thirdparty/util-linux.git] / sys-utils / pivot_root.8
CommitLineData
8d3abdc0 1.TH PIVOT_ROOT 8 "August 2011" "util-linux" "System Administration"
22853e4a 2.SH NAME
232dc924 3pivot_root \- change the root filesystem
22853e4a
KZ
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
9directory \fIput_old\fP and makes \fInew_root\fP the new root file system.
48962512 10Since \fBpivot_root\fP(8) simply calls \fBpivot_root\fP(2), we refer to
22853e4a
KZ
11the man page of the latter for further details.
12
13Note that, depending on the implementation of \fBpivot_root\fP, root and
14cwd of the caller may or may not change. The following is a sequence for
15invoking \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
18cd \fInew_root\fP
19.br
20pivot_root . \fIput_old\fP
21.br
22exec chroot . \fIcommand\fP
23.sp
24Note that \fBchroot\fP must be available under the old root and under the new
25root, because \fBpivot_root\fP may or may not have implicitly changed the
26root directory of the shell.
27
28Note that \fBexec chroot\fP changes the running executable, which is
29necessary if the old root directory should be unmounted afterwards.
30Also note that standard input, output, and error may still point to a
31device on the old root file system, keeping it busy. They can easily be
32changed when invoking \fBchroot\fP (see below; note the absence of
33leading slashes to make it work whether \fBpivot_root\fP has changed the
34shell's root or not).
8d3abdc0
SK
35.SH OPTIONS
36.TP
37\fB\-V\fR, \fB\-\-version\fR
b4362b6f 38Display version information and exit.
8d3abdc0
SK
39.TP
40\fB\-h\fR, \fB\-\-help\fR
b4362b6f 41Display help text and exit.
22853e4a
KZ
42.SH EXAMPLES
43Change the root file system to /dev/hda1 from an interactive shell:
44.sp
45.nf
46mount /dev/hda1 /new-root
47cd /new-root
48pivot_root . old-root
49exec chroot . sh <dev/console >dev/console 2>&1
50umount /old-root
51.fi
52.sp
53Mount the new root file system over NFS from 10.0.0.1:/my_root and run
54\fBinit\fP:
55.sp
56.nf
57ifconfig lo 127.0.0.1 up # for portmap
58# configure Ethernet or such
59portmap # for lockd (implicitly started by mount)
60mount -o ro 10.0.0.1:/my_root /mnt
61killall portmap # portmap keeps old root busy
62cd /mnt
63pivot_root . old_root
64exec chroot . sh -c 'umount /old_root; exec /sbin/init' \\
65 <dev/console >dev/console 2>&1
66.fi
67.SH "SEE ALSO"
48962512 68.BR chroot (1),
48962512 69.BR pivot_root (2),
f053ff1e 70.BR mount (8),
922eafb2 71.BR switch_root (8),
48962512 72.BR umount (8)
86d62711 73.SH AVAILABILITY
601d12fb 74The pivot_root command is part of the util-linux package and is available from
d673b74e 75https://www.kernel.org/pub/linux/utils/util-linux/.