
Learn how Linux device drivers work and how to use them.
For someone familiar with Windows or MacOS, switching to Linux presents a daunting challenge in installing and configuring device drivers. This is understandable, as both Windows and MacOS have mechanisms that make this process very user-friendly. For example, when you plug in a new hardware device, Windows can automatically detect it and pop up a window asking if you want to continue with the driver installation. You can also download drivers from the internet with just a double-click to extract them or import them via the device manager.
However, this is not so straightforward on Linux. The first reason is that Linux is an open-source operating system, resulting in hundreds of variants of Linux distributions[1]. This means it’s impossible to create a guide that fits all Linux distributions, as the process of installing drivers varies between them.
Secondly, most default Linux drivers are also open-source and integrated into the system, making the installation of some drivers not included very complex, even though most hardware devices can be detected. Thirdly, the licenses of different distributions also vary. For example, Fedora prohibits the inclusion[2] of proprietary, legally protected, or drivers that violate U.S. law, while Ubuntu allows users to avoid using legally protected or closed-source hardware[3].
To better understand how Linux drivers work, I recommend reading the Introduction to Device Drivers[4] in the book “Linux Device Drivers”.
Two ways to find drivers
1. User Interface
If you are a newcomer to Linux coming from Windows or MacOS, you will be pleased to know that Linux also provides a wizard-like program to check if drivers are available. Ubuntu offers an Additional Drivers[5] option. Other Linux distributions also provide helper programs, like GNOME’s package manager[6], which you can use to check for available drivers.
2. Command Line
If you can’t find drivers through a nice user interface, what should you do? Perhaps you can only use a shell without any graphical interface? You can even use the console to showcase your skills. You have two options:
Through a Repository
This is similar to the homebrew[7] command line in MacOS. By using yum
, dnf
, apt-get
, etc., you can essentially add repositories and update package caches.
Download, Compile, and Build Yourself
This usually involves downloading source packages directly from the internet or via the wget
command, then running configuration and compilation to install. This goes beyond the scope of this article, but you can find many online guides if you choose this route.
Check if the driver is already installed
Before learning to install Linux drivers, let’s learn some commands to detect if drivers are available on your system.
The lspci[8] command displays detailed information about all PCI buses and device drivers on the system.
$ lspci
Or use grep
:
$ lspci | grep SOME_DRIVER_KEYWORD
For example, you can use the lspci | grep SAMSUNG
command if you want to check if the Samsung driver is installed.
The dmesg[9] command shows all drivers recognized by the kernel.
$ dmesg
Or use it with grep
:
$ dmesg | grep SOME_DRIVER_KEYWORD
Any recognized drivers will be displayed in the results.
If no drivers are recognized through the dmesg
or lspci
commands, try these two commands to see if the driver is at least loaded on the disk.
$ /sbin/lsmod
And
$ find /lib/modules
Tip: Like lspci
or dmesg
, you can filter results by adding | grep
after the above commands.
If a driver has been recognized but not found via lspci
or dmesg
, it means the driver exists on the disk but has not been loaded into the kernel. In this case, you can load this module using the modprobe
command.
$ sudo modprobe MODULE_NAME
Use sudo
to run this command, as this module requires root permissions to install.
Add Repository and Install
You can add a repository using yum
, dnf
, and apt-get
in several different ways; explaining each one is beyond the scope of this article. To keep it simple, this example will use apt-get
, but this command is quite similar to others.
1. Remove existing repositories if they exist
$ sudo apt-get purge NAME_OF_DRIVER*
Where NAME_OF_DRIVER
is the possible name of your driver. You can also add pattern matching to the regex to further filter.
2. Add the repository to the repository table, which should be specified in the driver guide
$ sudo add-apt-repository REPOLIST_OF_DRIVER
Where REPOLIST_OF_DRIVER
should be specified from the driver documentation (e.g., epel-list
).
3. Update the repository list
$ sudo apt-get update
4. Install the driver
$ sudo apt-get install NAME_OF_DRIVER
5. Check the installation status
As mentioned above, use the lspci
command to check if the driver has been successfully installed.
via: https://opensource.com/article/18/11/how-install-device-driver-linux
Author: Bryant Son[11] Topic: lujun9972 Translator: Jamskr Proofreader: wxy
This article is originally compiled by LCTT and proudly presented by Linux China