LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 05-16-2017, 02:53 AM   #1
aimal
LQ Newbie
 
Registered: May 2017
Posts: 7

Rep: Reputation: Disabled
Question Linux-Device Drivers, BIOS, Bootloader, Initrd - initramfs


Hi,

I have few questions about Linux Kernel and Boot process.

1) BIOS:
Upon PowerON, the first code that is on Processor startup address i.e. BIOS, is executed. BIOS detects hardware and conducts POST. then it loads first stage boot loader (from MBR) handover the control to it. Now the question is, if BIOS conduct POST or read MBR it means it should contains drivers to communicate with RAM, Keyboard, Harddisk, USB. i.e. isn't it necessary to have Device driver to Detect/communicate with these Hardware.... So
i) does BIOS contains any driver??
ii) How it DETECTS hardware and conducts POST or communicate with Hard disk, RAM etc.??

2) initrd - initramfs : I have heard that device drivers are packed inside the kernel. The kernel loads them on boot time. after the kernel is loaded, kernel mounts a temporary RAMDISK file system called initrd or initramfs to load device drivers and mount actual root rile system. Now if device drivers are packed into kernel, so when bootloader loads kernel image into RAM, doesn't it means the drivers that ware packed inside kernel are too loaded into RAM, if so, then why does the kernel need a temporary root file system to load drivers??

3) bootloader: If boot loader is loading kernel image into RAM from Hard drive, then it means it should contain the device driver for hard drive. then why kernel needs to load RAID controllers and drivers?? should bootloader handover the driver to kernel???

4) Need of File system for loading drivers: Why do we need a file system like initrd etc. to load drivers, cant we just load drivers without filesystem??? what its purpose??

Regards,
 
Old 05-16-2017, 01:06 PM   #2
arre
Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Slackware 10.2 & Windows 98 & Windows XP Pro & ...
Posts: 30

Rep: Reputation: 4
Good questions.

The bios, bootloader and kernel all need code to 'talk' to the hardware, yes. But, these pieces of software are very unrelated to one another, and don't depend on each other. As a result, each piece of code has its own (different) driver to do the exact same thing.

The reason for initramfs existing is a longer story, but there are a couple of good reasons. You don't need to use initramfs btw, and can just compile your kernel with 'built-in' drivers, in which case they are automatically loaded, and don't need to be 'probed' in initramfs.

Lot's more to say, too small smartphone keypad to type Anyway google's your friend!

Kind regards,
Arnout
 
Old 05-16-2017, 06:02 PM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,691
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
The BIOS (firmware), the boot loader, and the kernel all have software that they use to communicate with the hardware – and yet, all three pieces of software are unrelated.

"initramfs" exists specifically to support a "device discovery and driver loading" process – to allow Linux distros to run on unpredictable hardware. The system performs minimal initialization, mounts an "initial RAMdisk" containing discovery scripts and device drivers, then runs the script. The script must identify the hardware (particularly, the disk drive) and load any driver modules needed to access it. Then, Linux dismounts the RAMdisk and proceeds with initialization.

"Device drivers" are layers of software that present an abstraction of the underlying device, and which provide the means to communicate with it "unbeknownst to the rest of Linux." Linux never talks to the device directly: it always talks through the driver. Therefore, an appropriate driver must either be compiled directly into the kernel or loaded as modules by "initramfs." (If the necessary driver is already compiled into the kernel, then of course it doesn't need to be loaded from anywhere.)

"File systems" are very much the same way: they manage the physical data-structures on the disk volume, "unbeknownst to the rest of Linux." They, too, must either be compiled into the kernel or loaded as modules by "initramfs."

"initramfs" is a RAM-disk (loaded along with the kernel) that itself must contain all of the logic and drivers that might be needed. Linux doesn't need a device-driver to load it and use it. (There would be an obvious "Catch-22" if it did.) It is the "temporary root" that you speak of.

If I'm building a custom Linux kernel for a box, I'll just compile the necessary drivers and filesystem support into the kernel, and omit the "initramfs" step entirely. You're free to do that.

Last edited by sundialsvcs; 05-16-2017 at 06:05 PM.
 
1 members found this post helpful.
Old 05-17-2017, 12:30 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
for example BIOS contains simplified drivers, cannot really handle ext4 and other filesystems. A bootloader probably can read ext4, but not necessarily write it. The RAM can be accessed without any driver I think
 
Old 05-17-2017, 02:26 AM   #5
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,682
Blog Entries: 19

Rep: Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492
You need to understand that the kernel is modular. There is a "core kernel", statically compiled, and modules that are linked in dynamically at run time like libraries. Which features go in the core and which are compiled as modules is entirely up to the person building the kernel. The kernel source and the build tools are designed to allow maximum freedom in this respect.

Some distros make you build your own kernel and then it makes sense to build the hardware drivers that you need right in. Anything that you don't need, you needn't build at all. You could, in theory, build an entirely monolithic kernel with no need to load any drivers separately. However, most people compile drivers that they only use occasionally as modules.

It's different when you are designing a kernel for a distribution. The distro devs have no idea what sort of hardware their kernel will be running on, so they have to build all possible drivers. To keep the kernel as small as possible, they build a minimum core and add everything else as a module. Then they create an initial root device (initrd) image to be loaded into ram by the bootloader, so that the kernel can load the correct modules to drive the hardware. The filesystem driver for this (initramfs) has to be built into the kernel of course.

Bios chips don't have much in the way of drivers. When I first started to use PCs, the bios couldn't even use the screen except in setup mode; if it couldn't boot, it had to communicate the error by beeps. And the only thing a traditional bios can do with a disk is read the first physical sector and determine if it contains executable code. Uefi chips have drivers for fat-based filesystems and they read their boot code off a fat32 EFI partition.

As for bootloaders, I started with LILO and that doesn't understand filesystems either. It reads what it needs from the hard drive using physical addresses. GRUB has filesystem readers, but that's because it runs a miniature version of the Linux kernel.
 
1 members found this post helpful.
Old 05-17-2017, 05:52 AM   #6
aimal
LQ Newbie
 
Registered: May 2017
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thank you so much sundialsvcs and hazel. Your reply are really helpful.
 
Old 07-07-2017, 03:45 PM   #7
cesarbergara
Member
 
Registered: Feb 2012
Location: Buenos Aires, Argentina
Distribution: Debian, Suse, Mandrake,
Posts: 92

Rep: Reputation: Disabled
Hi. Read kernel source docs, it explain all about the hardware and OS. You can learn a lot about linux and others systems and hardware.
Have a nice day.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
initrd vs. initramfs rrlangly Gentoo 1 05-24-2010 09:05 AM
Initramfs vs Initrd Potatos Linux - Kernel 1 05-03-2010 05:13 AM
Looking for bootloader to boot from BIOS-unrecognized device. Jonathanius Linux - Software 4 02-21-2009 06:12 AM
Confusion PLEASE HELP!!!! Initrd + initramfs aroche Linux - General 2 08-18-2006 01:59 PM
difference between initrd and initramfs shrndegruv Linux - General 1 02-14-2006 12:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 02:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration