If you execute
Runtime.getRuntime().exec("su");
this will just launch su
and then exit. The next exec won't be executed with elevated privileges. Likewise after executing bt
the next command isn't executed within the chroot environment.
I presume bt
is a script? You could change it to pass arguments to chroot
, so you can pass it the command to execute, something like:
...
chroot new_root /etc/init.d/ssh start
...
To run this, you need to pass the command to su
directly using the -c
option. And you need to pass the commands as String array (or use a ProcessBuilder
):
Runtime.getRuntime().exec(new String[] {"su", "-c", "startbt; bt"});
Another option would be to make bt
pass arguments from the command line to chroot:
chroot new_root "$@"
and then pass them on the command line:
Runtime.getRuntime().exec(new String[] {"su", "-c", "startbt; bt /etc/init.d/ssh start"});