I have an application where I need to boot to Linux, execute automated scripts and then automatically boot to Windows. Can I use Kexec to run grub?
Another use case would be to boot a Linux kernel to update the processor microcode, and then kexec
to GRUB or Syslinux to boot Windows — because the microcode won't survive a full reboot.
I've heard of grub4dos
(link (unavailable), archived version), but it seems to be discontinued, so is there a way to do it with GRUB2?
I would basically need a loadable image of GRUB for kexec
. I tried to load the images found in this explanation, but they don't seem to work. Thanks for any hints.
Note:
Found this post from back in 2014, which said that this was not yet implemented in kexec.
Best Answer
It seems to be possible to
kexec
Windows, but it seems to be experimental at best (and not well tested).GRUB
It's not possible to
kexec
the grubcore.img
by itself (as it doesn't seem to have a compatible binary format), also see this bug report on launchpad. The error mentioned is still reproducible:According to
kexec --help
, the following types are supported at the moment:If you want to load a different loader, it would need to be in one of these formats or the compatibility would have to be added. I'm not sure what format GRUB is using - a simple
file
command only produces this:Creating a bootable GRUB Image
Currently there seem to be these possibilities:
grub2-mkimage
core.img
(kernel.img
)lnxboot.img
andcore.img
together. See @Ardwena' answer.lnxboot.img
as kernel andcore.img
asinitrd
. Hint found on Arch Wiki and an old thread on the grub devel mailing list.lnxboot
lnxboot.img
would be aLinux kernel x86 boot executeable bzImage
. It seems to be intended to be loaded as a kernel:Kexec does load it, but crashes when executing:
There also seems to be an issue occuring while loading (first few lines of debug output):
Grub4Dos
A quick look at Grub4Dos:
This should mean that it is compatible. It wasn't an option for me as it's legacy software.
However, I managed to load
grub4dos
by downloading0.4.4
from sourceforge and then running:Unconfigured, it falls back to the grub shell after some time. If you want to use
gru4dos
, you should only need to tweak thecmdline
to fit your needs. This thread should still apply.Windows
Kexec
'ing Windows doesn't seem to be a one-liner, but it has been done before.Most of the work in this direction seems to be associated with the LinuxBoot project. Github
I found these slides as well as this github repo. This seems to be the project mentioned in the article that was making it work.
It seems to be possible, but a lot of work (and no "production-ready" solution available - At least I haven't found it yet). Unfortunately there doesn't seem to be a lot of documentation for LinuxBoot, so you may have to ask the developers. There may already be a more straightforward way to do this.