pivot_root.c 818 B

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