92

Is there a way to reboot a Linux system (Debian in particular) without rebooting the hardware?

I have a RAID controller that takes a bit to get itself running before the OS starts up, and I would like it if there was a way to quickly reboot the Linux OS without having to go through the whole reboot process of restarting the RAID controller, etc.

Peter Mortensen
  • 2,319
  • 5
  • 23
  • 24
lacrosse1991
  • 1,407
  • 5
  • 19
  • 24
  • 6
    All UEFI based systems are able to switch OS whtout rebooting. You also have[`kexec()`](http://en.wikipedia.org/wiki/Kexec)which is like`exec()`, but for Unix kernels. – user2284570 Mar 25 '15 at 03:08

3 Answers3

104

I use kexec-reboot on nearly all of my production systems.

It works incredibly well, allowing me to bypass the long POST time on HP ProLiant servers and reduce the boot cycle from 5 minutes to ~45 seconds.

See: https://github.com/error10/kexec-reboot

The only caveat is that it doesn't seem to work on RHEL/CentOS 6.x systems booting UEFI. But most sane OS/hardware combinations work.

ewwhite
  • 194,921
  • 91
  • 434
  • 799
  • 65
    I wrote that! But it still works pretty well... – Michael Hampton Mar 25 '15 at 00:27
  • Are there any caveats to this thing? Without resetting the devices, they may not be in a known state when the machine is rebooted, isn't that the case? I wonder if this is production-safe. ...Well I just read the wiki entry on kexec, and it brings up the same points. I guess my question boils down to: In the Real World, how much of an issue is this? Does anyone have experience in using kexec-reboot on a regular basis? What is your comfort level after doing so; are you confident your systems are running sanely? – Mike S Mar 25 '15 at 13:35
  • I use it when I need an OS reset or a kernel update. If I'm upgrading server firmware or making BIOS or hardware changes, I perform a normal reboot. – ewwhite Mar 25 '15 at 13:41
  • 1
    Fascinating. So how does the actual process look? According to an article by Hariprasad Nellitheertha (linked to from the kexec wikipedia page), "Unlike the normal reboot process, kexec does not perform a clean shutdown of the system before rebooting. It is left to you to kill all applications and unmount file systems before attempting a kexec reboot." I notice some questionable things, for example, Wim Coekaerts says that "sync; umount -a; kexec -e" will do a very fast reboot. But you can't umount a busy filesystem. Perusing the web, it seems that many ignore the 'kill all applications' part. – Mike S Mar 25 '15 at 14:12
  • 2
    @MikeS This isn't `kexec`. It's the [`kexec-reboot`](https://github.com/error10/kexec-reboot) utility. The Github description outlines the difference and what the utility adds to the process. – ewwhite Mar 25 '15 at 16:42
  • 4
    @MikeS After staging kexec, you simply do a `shutdown -r`. Your system scripts will notice that kexec has been staged and do the right thing. How does it look? Three or four or fifteen minutes shorter. I have a very horrible quality video I took off the iDRAC console, but you really don't want to suffer through that... The `kexec-reboot` script is meant to automate the process of getting the right command line arguments to kexec, which can be tricky. – Michael Hampton Mar 25 '15 at 16:46
  • 1
    @MichaelHampton - cool. I see that on CentOS 6.5 near the end of /etc/rc3d/rc6.d/S01reboot there is: `[ -n "$kexec_command" ] && $kexec_command -e -x >& /dev/null` . So, iff a kernel is loaded by kexec -l, the system will reboot into it without a complete /sbin/reboot... kexec is baked in! I didn't know that, thanks. I suppose more modern distributions have it covered as well. BTW, if kexec wasn't previously run with -l, the reboot script will say "Nothing has been loaded!" which is why the output is sent to /dev/null, and why I was never aware of this facility. – Mike S Mar 25 '15 at 18:01
  • @MikeS Yes, on EL7 / systemd there is a kexec target that gets called as well. – Michael Hampton Mar 25 '15 at 18:03
  • Interesting. Does this kexec works also in ARM architecture? – Mr_LinDowsMac Mar 26 '15 at 23:10
  • 1
    @Mr_LinDowsMac Yes, kexec does work on ARM. In fact, the method used to "root" some Android phones relies on kexec to replace the mobile carrier's kernel with the user's kernel. Though this script won't work on such phones, as most ARM architectures don't boot with grub. – Michael Hampton Mar 26 '15 at 23:43
  • Doesn't it force new kernel with out stoping services and umounting devices? How did you deal with that? – Alexander Klimenko Sep 22 '15 at 06:24
17

Yes, it is possible. kexec will allow a Linux kernel to be booted directly from Linux without going through the BIOS boot process.

kasperd
  • 29,894
  • 16
  • 72
  • 122
16

Yes. You must use kexec-tools. To make the life easier, I use kexec-reboot.

$sudo apt-get install kexec-tools
$wget https://raw.githubusercontent.com/vadmium/kexec-reboot/master/kexec-reboot
$chmod +x kexec-reboot
$sudo mv kexec-reboot /usr/local/sbin/kexec-reboot
$sudo /usr/local/sbin/kexec-reboot