• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* pivot_root.c - edit system mount tree
2  *
3  * Copyright 2012 Rob Landley <rob@landley.net>
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 
25 #include <sys/syscall.h>
26 #include <unistd.h>
27 
pivot_root_main(void)28 void pivot_root_main(void)
29 {
30   if (syscall(__NR_pivot_root, toys.optargs[0], toys.optargs[1]))
31     perror_exit("'%s' -> '%s'", toys.optargs[0], toys.optargs[1]);
32 }
33