I read through this very interesting q/a about how computers reboot, and although I do not know much at all about OS development, I was wondering if you could partially shut down the system, then boot back up from that point on.
For example, on Linux, if I read the output correctly during a shutdown, it goes a bit like this:
- Send Terminate / KILL to all processes.
- Shutdown services / daemons
- Power off.
And the startup sequence goes a bit like:
- BIOS, Bootloader
- Load kernel and modules
- Start services / daemons
- Start processes
So could we shutdown until after 2, then start back up from 3 onwards? Essentially I’m thinking this should reset the processes and daemons while keeping the kernel in memory, thus saving up on the kernel loading time on a normal (re)boot.
Focusing on Linux here:
"Rebooting" userspace (and some hardware parts)
You’re missing something from your boot sequence in terms of how those services, daemons and programs are started.
Enter
initon Linux. The purpose of/sbin/init, which could be system V init, upstart or systemd, is exactly launching all of these other processes. All of those init utilities have features to manage the services they run beneath them.Now, a linux system also has the concept of runlevels, namely:
The ? ones aren’t strictly defined. Anyway, if you su to root and type
init 3right now, assuming you’re on Linux, X and every x client will be terminated. Of course, if something is allowed on a given runlevel it won’t be killed off, but if you want a certain process rebooting only, then this achieves it quite nicely. The use case for restarting system daemons is in response to an update and most package managers these days will actually do this for you via your initscript tool of choice.So we can restart our entire GUI, we can restart any daemon. We could kill any other process too. Reloading hardware drivers? I can already do that on the fly via
modprobe, so if I fancy an update of my graphics drivers, I caninit 3, remove the old ones, insert the new ones and carry on.Your package manager knows how to restart system daemons and you can always follow its advice to log out and back in; thus Linux is already fairly efficient in terms of avoiding reboots on update.
"Rebooting" the kernel
So basically, I like to think most of Linux can be "rebooted" without actually rebooting. So now What’s left?
Now, the question is how do you reload the kernel? Well the kernel isn’t actually any special magic, it’s just another computer program copied into memory, so we can just write a program somewhere that writes over our kernel and passes execution to it…
This exists, believe it or not, and is called
kexec. I’ll leave the wikipedia page to summarise the problems with it:kexec does not, unlike a system shutdown, automatically stop filesystems or processes for you; you’re responsible for that.
So there you have it. Depending on which part you need to reload, on Linux, most of it is possible.