As far as I know, protected mode will be activated in kernel and in grub stages it still real mode. My misunderstanding is: In real mode, total memory available for use is less than 1MB but how grub can load the kernel and even root file system (usualy bigger than 1MB) to memory?


GRUB does not have to load the whole kernel into memory. The kernel image is split into two pieces:

  • The real-mode kernel code, which is small and can be loaded within the 640kB threshold of available memory;
  • The rest of the kernel, which runs in protected mode and is loaded after the first megabyte of memory.

The bootloader only loads the real-mode kernel code, which in turn bootstraps the rest (take a look at go_to_protected_mode() in arch/x86/boot/pm.c). This is how the process can stay within the memory limitations of running in real mode.

A small note: GRUB may run in both real mode and protected mode, depending on what it is doing. It may switch into protected mode for some things (some hardware detection, and menu display). You are right, however, in thinking that it is in real mode when it hits the kernel.

  • Thanks for your quick answer! In Grub spec, it loads both kernel (may be only one piece :D) and root filesystem (mine is 32MiB). So, how about root filesystem? May 14 '13 at 5:15
  • 1
    @BìnhNguyên The kernel is the one dealing with the root filesystem, not GRUB.
    – Chris Down
    May 14 '13 at 5:24
  • I had that confused because this article: blog.adminnote.com/2010/10/linux-boot-process-step-by-step.html Thanks for corrected me ;) May 14 '13 at 6:16
  • From what I read here (mjmwired.net/kernel/Documentation/x86/boot.txt) this is wrong. Of course, Grub can access the memory above 1 MiB and start the kernel in real mode nonetheless. Assuming that Grub does not have to load the complete kernel image and initrd makes little sense to me. That would mean that the kernel has to understand the /boot file system before it loads the initrd (and even most of itself!). You are familiar with the kernel unable to access the root device. Ever heard of a kernel unable to load the initrd? Please think about that again. May 14 '13 at 10:26
  • 1
    @HaukeLaging I can't quite understand what you're saying, but you will want to read section 16 here. GRUB can start the kernel in whatever mode it likes, that doesn't mean it should. The kernel does not have to understand /boot before it loads the initrd -- the initrd is provided to the kernel by the bootloader (and the bootloader handles the filesystem). Whether you find it makes "little sense" or not is irrelevant to its veracity. If you expect me to comment on some specific part of boot.txt, please provide the section.
    – Chris Down
    May 14 '13 at 10:48

It can be done in real mode by means of BIOS int 0x15, 0x87 function. GDT must be filled appropriately for source and destination. cx - number of bytes to move.

    push edx
    push es
    xor  ax, ax
    mov  es, ax
    mov  ah, 0x87
    mov  si, gdt
    int  0x15
    jc   error
    pop  es
    pop  edx

    times   16  db  0
    dw  0xffff              ; segment limit
    dw  0
    db  2
    db  0x93                ; data access rights
    dw  0
    dw  0xffff              ; segment limit
    dw  0
    db  0x10                ; load protected-mode kernel to 100000h
    db  0x93                ; data access rights
    dw  0
    times   16  db  0

  • what is the question?
    – Jakuje
    Aug 12 '15 at 13:00
  • @Jakuje The question is at the top of the page, this is an answer.
    – Anthon
    Aug 12 '15 at 13:23
  • sorry. I looked wrong into the review queue.
    – Jakuje
    Aug 12 '15 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.