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