man-pages/man8/pivot_root.8.html
2021-03-31 01:06:50 +01:00

128 lines
3.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of PIVOT_ROOT</TITLE>
</HEAD><BODY>
<H1>PIVOT_ROOT</H1>
Section: System Administration (8)<BR>Updated: August 2011<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
pivot_root - change the root filesystem
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>pivot_root</B>
<I>new_root put_old</I>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>pivot_root</B> moves the root file system of the current process to the
directory <I>put_old</I> and makes <I>new_root</I> the new root file system.
Since <B><A HREF="/cgi-bin/man/man2html?8+pivot_root">pivot_root</A></B>(8) simply calls <B><A HREF="/cgi-bin/man/man2html?2+pivot_root">pivot_root</A></B>(2), we refer to
the man page of the latter for further details.
<P>
Note that, depending on the implementation of <B>pivot_root</B>, root and
cwd of the caller may or may not change. The following is a sequence for
invoking <B>pivot_root</B> that works in either case, assuming that
<B>pivot_root</B> and <B>chroot</B> are in the current <B>PATH</B>:
<P>
cd <I>new_root</I>
<BR>
pivot_root . <I>put_old</I>
<BR>
exec chroot . <I>command</I>
<P>
Note that <B>chroot</B> must be available under the old root and under the new
root, because <B>pivot_root</B> may or may not have implicitly changed the
root directory of the shell.
<P>
Note that <B>exec chroot</B> changes the running executable, which is
necessary if the old root directory should be unmounted afterwards.
Also note that standard input, output, and error may still point to a
device on the old root file system, keeping it busy. They can easily be
changed when invoking <B>chroot</B> (see below; note the absence of
leading slashes to make it work whether <B>pivot_root</B> has changed the
shell's root or not).
<A NAME="lbAE">&nbsp;</A>
<H2>OPTIONS</H2>
<DL COMPACT>
<DT id="1"><B>-V</B>, <B>--version</B><DD>
Display version information and exit.
<DT id="2"><B>-h</B>, <B>--help</B><DD>
Display help text and exit.
</DL>
<A NAME="lbAF">&nbsp;</A>
<H2>EXAMPLES</H2>
Change the root file system to /dev/hda1 from an interactive shell:
<P>
<PRE>
mount /dev/hda1 /new-root
cd /new-root
pivot_root . old-root
exec chroot . sh &lt;dev/console &gt;dev/console 2&gt;&amp;1
umount /old-root
</PRE>
<P>
Mount the new root file system over NFS from 10.0.0.1:/my_root and run
<B>init</B>:
<P>
<PRE>
ifconfig lo 127.0.0.1 up # for portmap
# configure Ethernet or such
portmap # for lockd (implicitly started by mount)
mount -o ro 10.0.0.1:/my_root /mnt
killall portmap # portmap keeps old root busy
cd /mnt
pivot_root . old_root
exec chroot . sh -c 'umount /old_root; exec /sbin/init' \
&lt;dev/console &gt;dev/console 2&gt;&amp;1
</PRE>
<A NAME="lbAG">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+chroot">chroot</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?2+pivot_root">pivot_root</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?8+mount">mount</A></B>(8),
<B><A HREF="/cgi-bin/man/man2html?8+switch_root">switch_root</A></B>(8),
<B><A HREF="/cgi-bin/man/man2html?8+umount">umount</A></B>(8)
<A NAME="lbAH">&nbsp;</A>
<H2>AVAILABILITY</H2>
The pivot_root command is part of the util-linux package and is available from
<A HREF="https://www.kernel.org/pub/linux/utils/util-linux/.">https://www.kernel.org/pub/linux/utils/util-linux/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="3"><A HREF="#lbAB">NAME</A><DD>
<DT id="4"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="5"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="6"><A HREF="#lbAE">OPTIONS</A><DD>
<DT id="7"><A HREF="#lbAF">EXAMPLES</A><DD>
<DT id="8"><A HREF="#lbAG">SEE ALSO</A><DD>
<DT id="9"><A HREF="#lbAH">AVAILABILITY</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:06:15 GMT, March 31, 2021
</BODY>
</HTML>