1

My understanding is that the kernel understands how to communicate with the different hardware in a system via specific device trees.

How is it that I can download one version of Ubuntu and I am able to install this on any system where the hardware may vary?

The same goes for the BeagleBone embedded boards. There is a default Debian image which can flash to any of the different type of BeagleBone boards which have different peripherals. How does it know which device tree / device tree overlay to use when the same image works for all?

Engineer999
  • 1,151

2 Answers2

2

The Linux Kernel Map shows in some detail the device control. It contains something called "drivers" and "modules" that can be extended by "Loadable Kernel Modules".

E.G.: USB devices generally have a module that gets loaded when the device gets attached whereas the USB root hub is statically linked into the kernel and an nVidia card need a driver downloaded from nVidia.

That's why most distributions run on a wide variety of hardware, but not necessarily all very new hardware, which might need a separate module or a driver.

For more information on the difference between a driver and a module have a look here

How the kernel knows which modules to load digs deeper into the hardware layer and it does it by enumerating:

  • the PCI bus
  • the SCSI bus
  • the USB hub
  • the DSPs ...
Fabby
  • 5,384
2

The device drivers (i.e. the part of the kernel that interact directly with the hardware) can be compiled as kernel modules. These are separate files, which can be loaded or unloaded by the kernel, as necessary, depending on the hardware present in the system.

The generic kernels that are shipped with mainstream Linux distributions tend to be supplied with all of the drivers for every conceivable piece of hardware compiled as modules. So, when the kernel boots up on a given system, it probes out and detects what hardware is on the system and then directs the userspace program, udev, to load whatever kernel modules are needed for the specific hardware.

Time4Tea
  • 2,366
  • Urgh! I forgot to mention udev! +1 – Fabby Jan 17 '19 at 22:03
  • Thanks. I notice with Windows, when we install it, different hardware gets detected and then then the specific drivers for different hardware gets installed for use with Windows. Therefore if for example we swap the hard disk from a HP computer to a Dell computer, it probably won't work due to the wrong drivers installed. With Linux however I guess this is different?? The hardware gets detected and the device drivers get loaded on boot-up every time? – Engineer999 Jan 17 '19 at 22:04
  • 1
    @Engineer999 yup unless you have very old or very new hardware that the kernel knows nothing about and then you might have to build a custom kernel. – Fabby Jan 17 '19 at 22:06
  • @Engineer999 I believe it should do. By default, all of the drivers/modules are provided, for as much hardware as possible. Except very new hardware, as Fabby mentioned. – Time4Tea Jan 17 '19 at 22:07
  • 1
    Or old obsolete hardware @Time4Tea modules do get removed too. – Fabby Jan 17 '19 at 22:07
  • @Fabby What about device trees? Or are these just used in the embedded world? – Engineer999 Jan 17 '19 at 22:16
  • @Engineer999 on Linux, the /sys directory contains the entire 'device tree' that is present in the system, exported to userspace by the kernel. Is that what you are referring to? – Time4Tea Jan 17 '19 at 22:20
  • @Time4Tea Ah yes that's it. What's the relationship between device tree and the divers/modules ? – Engineer999 Jan 17 '19 at 22:38
  • @Engineer999 basically, when the kernel boots up, it detects what hardware is on the system; populates the /sys directory for it; and sends out 'uevents' for each device. udevd (userspace daemon) receives those uevents and loads the required kernel modules, depending on what information is in /sys for the hardware. This page provides some more details. – Time4Tea Jan 17 '19 at 22:42