The reason you can't do this in a shell script is after the "rm -rf" step, the shell script hasn't got a "mount" command to run anymore...
That's my point: switch_root is ugly. The way it's implemented in C isn't any less ugly: it's duplicating the relevant part of the rm -rf code in the switch_root utility itself. What Rob is forgetting is that you have access to another filesystem under newroot/ and that filesystem may - and should - have utilities that allow you to complete the task, if you know the path to call them. And if it does not, then you can do what I did: create a tmpfs under newroot/, dump all the static binaries you need into it, and call them from here. There's really nothing serious preventing you from implementing switch_root as a script. -- Laurent
