使用GRUB2引导非多重引导内核 [英] Booting a non-multiboot kernel with GRUB2

查看:254
本文介绍了使用GRUB2引导非多重引导内核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用GRUB2引导自定义内核(非多重引导),我读到我需要这样的grub.cfg:

menuentry "custom kernel" {
    set root=(hd0,0)
    chainloader +1
}

所以,我有一些问题:

  1. grub如何检测内核? (对于多重引导规范,我使用了kernel /boot/kernel.bin)
  2. 我的内核看起来如何(对不起我的英语不好)?
  3. 必须全部为512字节(例如自定义引导程序,已加载到0x7c00中)吗?
  4. (hd0,0)是硬盘驱动器分区,如果使用CD,我必须放什么?也许(cdrom0,0)?
  5. 要启动Linux内核,我们可以使用linux命令,我可以使用它来启动我的自定义内核(进行一些更改)吗?
  6. Grub是否会输入Protected mode?

解决方案

请参见文档:

Multiboot(请参阅Multiboot规范)是GRUB支持的本机格式.为了方便起见,还支持Linux,FreeBSD,NetBSD和OpenBSD.如果要引导其他操作系统,则必须对其进行链式加载(请参阅链式加载).

因此,对于非多重启动内核,必须使用链加载程序功能.链式加载意味着GRUB将加载指定硬盘分区的第一个扇区(512字节)并进行引导,就像BIOS引导MBR一样.这意味着CPU处于实模式,并且引导扇区已加载到0x7C00.

是的,您可以使用linux命令引导内核,使其与Linux引导过程兼容,但这比简单地使内核兼容多引导要复杂得多.

I want to boot a custom kernel (non-multiboot) with GRUB2, I've read that I need grub.cfg like this:

menuentry "custom kernel" {
    set root=(hd0,0)
    chainloader +1
}

So, I have some questions:

  1. How grub detect kernel? (with multiboot spec I used kernel /boot/kernel.bin)
  2. How my kernel must look like (sorry for my bad english)? Must it be 512 bytes at all (like custom bootloader, which loaded into 0x7c00)?
  3. (hd0,0) is hard drive partition and what I must put if I use CD? Maybe (cdrom0,0)?
  4. To boot Linux kernel we can use linux command, can I use it to boot my custom kernel (with some changes)?
  5. Will Grub enter Protected mode or not?

解决方案

See the documentation:

Multiboot (see Multiboot Specification) is the native format supported by GRUB. For the sake of convenience, there is also support for Linux, FreeBSD, NetBSD and OpenBSD. If you want to boot other operating systems, you will have to chain-load them (see Chain-loading).

So for your non-multiboot kernel you'll have to use the chain-loader feature. Chain-loading means GRUB will load the first sector (512 bytes) of the specified harddisk partition and boots it like the BIOS would boot a MBR. This means the CPU is in real mode and your boot sector is loaded at 0x7C00.

And yes, you could boot your kernel using the linux command, by making it compatible with the Linux boot process, but that would be more complex than simply making your kernel multiboot-compliant.

这篇关于使用GRUB2引导非多重引导内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆