xref: /aosp_15_r20/external/toybox/toys/other/pivot_root.c (revision cf5a6c84e2b8763fc1a7db14496fd4742913b199)
1 /* pivot_root.c - edit system mount tree
2  *
3  * Copyright 2012 Rob Landley <[email protected]>
4 
5 USE_PIVOT_ROOT(NEWTOY(pivot_root, "<2>2", TOYFLAG_SBIN))
6 
7 config PIVOT_ROOT
8   bool "pivot_root"
9   default y
10   help
11     usage: pivot_root OLD NEW
12 
13     Swap OLD and NEW filesystems (as if by simultaneous mount --move), and
14     move all processes with chdir or chroot under OLD into NEW (including
15     kernel threads) so OLD may be unmounted.
16 
17     The directory NEW must exist under OLD. This doesn't work on initramfs,
18     which can't be moved (about the same way PID 1 can't be killed; see
19     switch_root instead).
20 */
21 
22 #define FOR_pivot_root
23 #include "toys.h"
24 
pivot_root_main(void)25 void pivot_root_main(void)
26 {
27   if (syscall(__NR_pivot_root, toys.optargs[0], toys.optargs[1]))
28     perror_exit("'%s' -> '%s'", toys.optargs[0], toys.optargs[1]);
29 }
30