1 /* pivot_root.c - edit system mount tree
3 * Copyright 2012 Rob Landley <rob@landley.net>
5 USE_PIVOT_ROOT(NEWTOY(pivot_root, "<2>2", TOYFLAG_SBIN))
11 usage: pivot_root OLD NEW
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.
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
22 #define FOR_pivot_root
25 #include <sys/syscall.h>
28 void pivot_root_main(void)
30 if (syscall(__NR_pivot_root, toys.optargs[0], toys.optargs[1]))
31 perror_exit("'%s' -> '%s'", toys.optargs[0], toys.optargs[1]);