Is it possible to shutdown linux kernel and resume in Real Mode?

╄→尐↘猪︶ㄣ 提交于 2019-12-22 07:55:15

问题


Let's say I'd like to start a small linux distro before my ordinary operating system start.

  1. BIOS load MBR and execute MBR.
  2. MBR locates the active partition which is my linux partition.
  3. Linux start and I perform what I need to do.
  4. Linux shut down and I switch to Real Mode again.
  5. The original partition boot sector is loaded and my ordinary OS start.

AFAIK, step 4 will be the difficult task, restore the state on all devices prior to linux, will INT13h be functional? Do I need to restore the Interrupt Vector Table? To mention a few.

Has this been done in any existing project perhaps?


回答1:


Linux does not normally support this, particularly since it reinitializes hardware in a way that the BIOS and DOS programs may not expect. However, there is some infrastructure to switch back to real mode in specific cases - particularly, for a reboot (see machine_real_restart in arch/x86/kernel/reboot.c) - and has code to reinitialize hardware for kexec or suspend. I suspect you might be able to do something with a combination of these - but I don't know if the result will truly match what DOS or Windows would expect to see on reboot.

A much easier plan would be to use a chainloading bootloader that can be set to boot in a particular configuration once, like GRUB. You could invoke grub-set-default, then reboot. When GRUB comes up, it would then pass control off to Windows. By then setting the fallback OS to the Linux partition, control would return to Linux on the next boot.

Yet another option may be to use Coreboot, but I'm not sure if this is production-ready for booting windows yet.




回答2:


i haven't tried this so I don't know if it would work, but here goes:

There is an option in the header of a bzImage format kernel file that specifies the address of real mode code to execute before the protected mode code starts. You could create a minimal bzImage-compliant file which has no actual kernel, but which has real mode code to load your MBR using INT 0x13 to 0x7c00 and jmp into it like the BIOS does.

If you use kexec to load the bzImage using the "-t bzImage-x86 --real-mode" options, it should reset the PE bit in CR0 to drop to realmode (as bdonlan above mentioned) and execute the code pointed to by the bzImage header option.

The bzImage header option is called realmode_swtch and is documented in /usr/src/linux/Documentation/x86/boot.txt , the header format code is in /usr/src/linux/arch/x86/boot/header.S




回答3:


Have you looked into kexec?



来源:https://stackoverflow.com/questions/855150/is-it-possible-to-shutdown-linux-kernel-and-resume-in-real-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!