3 ms·
You can also go in reverse, and escape the running distribution's mounted / by pivoting to a tmpfs /, kill all processes and unmount the old root. Figuring out
by megous 7y ago
You can also go in reverse, and escape the running distribution's mounted / by pivoting to a tmpfs /, kill all processes and unmount the old root. Figuring out how to do this was quite fun. Systemd makes it actually fairly easy, because you can easily hijack the PID 1 if it's systemd, which is necessary to be able to umount the old /.
- Hello71 7y agosystemd makes it the most easy. all you need is systemctl switch-root ROOT. on other inits, you usually need to replace /sbin/init, then use some non-portable (sysvinit is not the only competitor) method of telling init to re-exec itself. sometimes that method doesn't even stop the running services, so you need to either manually stop them, or kill them.
- CameronNemo 7y agoIn what situations would you expect a re-exec to stop the services? The normal case is that the reexec preserves state.
- Hello71 7y agoIIRC, some init implementations have this capability. I'm not saying that it's good in general, but just that it facilitates this particular case.
- megous 7y agoYou can do it non-destructively by bind mounting a binary from ramfs over /bin/init When it reexecs, the new binary can kill and umount everything and switch roots. If it fails somehow, you just reboot and everything is back to normal.