您需要先加载内核错误
You need to load your kernel first Error
现在,当我 select 自定义 OS 时,当我从 GRUB 的菜单中执行 OS 时,我得到一个紫色背景:
error: secure boot forbids loading module from (hdo, gpt7)/boot/grub/x86_64-efi/multiboot.mod
error: You need to load your kernel first
Press any key to continue . . .
..我不一定明白为什么会这样。让我给你看我的文件:
loader.S:
#Global MultiBoot Kernel Recongnzation
.set MAGIC, 0x1BADB002
.set FLAGS , (1<<0 | 1<<1)
.set CHECKSUM, -(MAGIC + FLAGS)
#Putting in object file
.section .multiboot
.long MAGIC
.long FLAGS
.long CHECKSUM
.section .text
.extern kernelMain
.globl loader
loader:
mov $kernel_stack , %esp
push %eax
push %ebx
call kernelMain
_eof:
cli
hlt
jmp _eof
.section .bss
.space 2*1024*1024 #2 MiB
kernel_stack:
生成文件:
GPPARAMS = -m32 -Iinclude -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings
ASPARAMS = --32
LDPARAMS = -melf_i386
objects = kernel.o loader.o
all:
g++ -m32 -Iinclude -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings -o kernel.o -c kernel.cc
as $(ASPARAMS) -o loader.o loader.S
mykernel.bin : linker.ld $(objects)
ld $(LDPARAMS) -T $< -o $@ $(objects)
install: mykernel.bin
sudo cp $< /boot/mykernel.bin
clean:
rm $(objects)
kernel.cc:
int strlen(char* str)
{
int l=0;
while(str[l]!='[=13=]')l++;
return l;
}
void printf(char *str)
{
unsigned short* ViedoMemory = (unsigned short*)0xb8000;
for(int i=0; str[i]!='[=13=]'; ++i)
ViedoMemory[i]= (ViedoMemory[i] & 0xFF00)|str[i];
}
extern "C" void kernelMain(void* multiboot_structure, unsigned int magicnumber)
{
printf("Hello World");
while(1);
}
linker.ld:
ENTRY(loader)
OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386:i386)
SECTIONS
{
. = 0x0100000;
.text :
{
*(.multiboot)
*(.text*)
*(.rodata)
}
.data :
{
start_ctors = .;
KEEP(*( .init_array ));
KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* )));
end_ctors = .;
*(.data)
}
.bss :
{
*(.bss)
}
/DISCARD/ :
{
*(.fini_array*)
*(.comment)
}
}
现在我加载它的方式是首先通过 makefile
:
make
make mykernel.bin
make install
然后当然在 /boot/grub/grub.cfg
我添加了这个:
### BEGIN MYKERNEL
menuentry 'Operating System Tut'{
multiboot /boot/mykernel.bin
boot
}
### END MYKERNEL ###
然后,当我从下拉列表中执行 sudo reboot
和 select Operating System Tut
时,它会给我之前描述的错误:
error: secure boot forbids loading module from (hdo, gpt7)/boot/grub/x86_64-efi/multiboot.mod
error: You need to load your kernel first
Press any key to continue . . .
同样,我不明白为什么内核没有首先加载...将不胜感激。
尝试关闭 BIOS 中的 Secure Boot
选项,看看是否会产生不同的结果。启用此选项后,固件会检查您的引导加载程序是否已签名,如果未签名,或者其签名与存储在 NVRAM 中的密钥不对应,或者是否在 NVRAM 中列入黑名单,则阻止其执行。
见Managing EFI Boot Loaders for Linux: Dealing with Secure Boot。
现在,当我 select 自定义 OS 时,当我从 GRUB 的菜单中执行 OS 时,我得到一个紫色背景:
error: secure boot forbids loading module from (hdo, gpt7)/boot/grub/x86_64-efi/multiboot.mod
error: You need to load your kernel first
Press any key to continue . . .
..我不一定明白为什么会这样。让我给你看我的文件:
loader.S:
#Global MultiBoot Kernel Recongnzation
.set MAGIC, 0x1BADB002
.set FLAGS , (1<<0 | 1<<1)
.set CHECKSUM, -(MAGIC + FLAGS)
#Putting in object file
.section .multiboot
.long MAGIC
.long FLAGS
.long CHECKSUM
.section .text
.extern kernelMain
.globl loader
loader:
mov $kernel_stack , %esp
push %eax
push %ebx
call kernelMain
_eof:
cli
hlt
jmp _eof
.section .bss
.space 2*1024*1024 #2 MiB
kernel_stack:
生成文件:
GPPARAMS = -m32 -Iinclude -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings
ASPARAMS = --32
LDPARAMS = -melf_i386
objects = kernel.o loader.o
all:
g++ -m32 -Iinclude -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings -o kernel.o -c kernel.cc
as $(ASPARAMS) -o loader.o loader.S
mykernel.bin : linker.ld $(objects)
ld $(LDPARAMS) -T $< -o $@ $(objects)
install: mykernel.bin
sudo cp $< /boot/mykernel.bin
clean:
rm $(objects)
kernel.cc:
int strlen(char* str)
{
int l=0;
while(str[l]!='[=13=]')l++;
return l;
}
void printf(char *str)
{
unsigned short* ViedoMemory = (unsigned short*)0xb8000;
for(int i=0; str[i]!='[=13=]'; ++i)
ViedoMemory[i]= (ViedoMemory[i] & 0xFF00)|str[i];
}
extern "C" void kernelMain(void* multiboot_structure, unsigned int magicnumber)
{
printf("Hello World");
while(1);
}
linker.ld:
ENTRY(loader)
OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386:i386)
SECTIONS
{
. = 0x0100000;
.text :
{
*(.multiboot)
*(.text*)
*(.rodata)
}
.data :
{
start_ctors = .;
KEEP(*( .init_array ));
KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* )));
end_ctors = .;
*(.data)
}
.bss :
{
*(.bss)
}
/DISCARD/ :
{
*(.fini_array*)
*(.comment)
}
}
现在我加载它的方式是首先通过 makefile
:
make
make mykernel.bin
make install
然后当然在 /boot/grub/grub.cfg
我添加了这个:
### BEGIN MYKERNEL
menuentry 'Operating System Tut'{
multiboot /boot/mykernel.bin
boot
}
### END MYKERNEL ###
然后,当我从下拉列表中执行 sudo reboot
和 select Operating System Tut
时,它会给我之前描述的错误:
error: secure boot forbids loading module from (hdo, gpt7)/boot/grub/x86_64-efi/multiboot.mod
error: You need to load your kernel first
Press any key to continue . . .
同样,我不明白为什么内核没有首先加载...将不胜感激。
尝试关闭 BIOS 中的 Secure Boot
选项,看看是否会产生不同的结果。启用此选项后,固件会检查您的引导加载程序是否已签名,如果未签名,或者其签名与存储在 NVRAM 中的密钥不对应,或者是否在 NVRAM 中列入黑名单,则阻止其执行。
见Managing EFI Boot Loaders for Linux: Dealing with Secure Boot。