e9d.org

contact
whoami
blog/
dist/

wiki/
FAQ

résumé
donate

legal


GRUB2 is an operating system.
---
For those of you unfamiliar, GRUB2 (GRand Unified Bootloader) is a bootloader,
and a very good one at that. It's purpose is to, when your computer starts up,
load a kernel image into memory and jump to it.
GRUB2 has a few components:
 - a modular kernel
 - a virtual filesystem
 - support for a wide variety of filesystems, encryption, and storage media
 - pseudofilesystems, a-la /dev and /proc
 - a multistage boot - the bootloader has its own mini-bootloader
 - a networking stack
 - an interactive shell
 - the ability to launch programs
By my definition, that's most of an operating system. Let's compare MS-DOS:
 - a kernel that is extended through terminate-and-stay-resident programs
 - a primitive virtual filesystem
 - support for FAT and perhaps NTFS
 - a bootloader
 - an interactive shell
 - the ability to launch programs
Most people would agree that MS-DOS is certainly an operating system, and GRUB2
is in many ways more advanced that MS-DOS. MS-DOS lacks a networking stack out
of the box, lacks a truly modular kernel, and lacks pseudofilesystems.
---
GRUB2 is certainly not a traditional operating system. GRUB2 is not meant to be
used as an operating system. GRUB2 lacks many of the utilities that a decent
operating system will include, such as a text editor or a C compiler.
---
Let's look at how DOS launches programs.
The MBR loads KERNEL  .SYS, which reads and parses CONFIG  .SYS. The kernel
provides a very small set of services, mostly the VFS and facilities for TSR
programs KERNEL  .SYS loads COMMAND .COM into memory and jumps to it.
COMMAND .COM provides an interactive shell and a means of traversing the
virtual filesystem. COMMAND .COM loads programs into memory, and jumps to them.
At this point, it is expected that the loaded program returns execution back to
COMMAND .COM, but neither KERNEL nor COMMAND have any way of actually ensuring
this happens.
---
Let's look at how GRUB2 loads a kernel.
The MBR or GPT launches GRUB2 stage 1, which finds the bios_grub core image and
executes it. Stage 1.5 find, possibly decrypts, and loads stage 2, which is
typically found in your /boot partition. Stage 2 then loads the 'normal' kernel
module and executes 'normal'. normal parses grub.cfg, or drops the user to a
shell if not present.
Once GRUB2 is fully loaded, it loads OS kernels into memory as directed,and
jumps to them. From here an operating system is expected to take over, but that
doesn't have to happen. It's theoretically possible for a program to jump back
to the GRUB2 code once it's finished executing.
---
We can see now that the way DOS and GRUB2 load and execute programs is not so
different.


________________________________________________________________________________
(C)/AGPLv3