Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arguments to kernel

Is there anything that the kernel need to get from the boot loader.Usually the kernel is capable of bringing up a system from scratch, so why does it require anything from boot-loader? I have seen boot messages from kernel like this.

"Fetching vars from bootloader... OK"

So what exactly are the variables being passed? Also how are the variables being passed from the boot-loader? Is it through stack?

like image 865
AIB Avatar asked Jun 19 '09 06:06

AIB


4 Answers

The kernel accept so called command-line options, that are text based. This is very useful, because you can do a lot of thing without having to recompile your kernel. As for the argument passing, it is architecture dependent. On ARM it is done through a pointer to a location in memory, or a fixed location in memory.

Here is how it is done on ARM. Usually a kernel is not capable of booting the machine from scratch. May be from the bios, but then it is not from scratch. It needs some initialisation, this is the job of the bootloader.

like image 120
shodanex Avatar answered Sep 19 '22 02:09

shodanex


There are some parametres that the Linux kernel accepts from the bootloader, of which what I can remember now is the vga parametre. For example:

kernel /vmlinuz-2.6.30 root=/dev/disk/by-uuid/3999cb7d-8e1e-4daf-9cce-3f49a02b00f2 ro vga=0x318

Have a look at 10 boot time parameters you should know about the Linux kernel which explains some of the common parametres.

like image 25
Alan Haggai Alavi Avatar answered Sep 19 '22 02:09

Alan Haggai Alavi


For the Linux kernel, there are several things the bootloader has to tell the kernel. It includes things like the kernel command line (as several other people already mentioned), where in the memory the initrd has been loaded and its size, if an initrd is being used (the kernel cannot load it by itself; often when using an initrd, the modules needed to acess storage devices are within the initrd, and it can also have to do some quite complex setup before being able to access the storage), and several assorted odds and ends.

See Documentation/x86/boot.txt (link to 2.6.30's version) for more detail for the traditional x86 architecture (both 32-bit and 64-bit), including how these variables are passed to the kernel setup code.

like image 44
CesarB Avatar answered Sep 21 '22 02:09

CesarB


The bootloader doesn't use a stack to pass arguments to the kernel. At least in the case of Linux, there is a rather complex memory structure that the bootloader fills in that the kernel knows how to parse. This is how the bootloader points the kernel to its command line. See Documentaion/x86/boot.txt for more info.

like image 24
Andy Grover Avatar answered Sep 19 '22 02:09

Andy Grover