How does linux driver update work?

As far as I know no update on a linux machine requires a restart. Windows however needs to restart several times for a update to complete which is understandable because the hardware might be in use at the moment and a restart ensures that no software uses the driver.

But how can an OS (or linux as an example) handle such a situation where you want to update a driver but it is currently in use?

Asked By: henje


Updates on Linux require a restart if they affect the kernel. Drivers are part of the kernel. It’s sometimes possible to upgrade a driver on Linux without rebooting, but that doesn’t happen often: the peripheral controller by the driver can’t be in use during the update, and the new driver version has to be compatible with the running kernel.

Upgrading a driver to a running system where the peripheral controlled by the driver is in use requires that the old driver leaves the peripheral in a state that the new driver is able to start with. The old and new driver must manage the handover of connections from clients as well. This is doable but difficult; how difficult depends on what the driver is driving. For example, a filesystem update without unmounting the filesystem requires the handover of some very complex data structures but is easy to cope with on the hardware side (just flush the buffers before the update, and start over with an empty cache). Conversely, an input driver only has to transmit a list of open descriptors or the like on the client side, but the hardware side requires that the new driver know what state the peripheral is in and must be managed carefully not to lose events.

Updating a driver on a live system is a common practice during development on operating systems where drivers can be dynamically loaded and unloaded, but usually not while the peripheral is in use. Updating a driver in production is not commonly done on OSes like Linux and Windows; I suppose it does get done on high-availability systems that I’m not familiar with.

Some drivers are not in the kernel (for example FUSE filesystems). This makes it easy to update them without updating the rest of the system, but it still requires that the driver not be in use (e.g. instances of the FUSE filesystem have to be unmounted and mounted again to make use of the new driver version).

Linux does have mechanisms to upgrade the kernel without restarting: Ksplice, Kpatch, KGraft. This is technically difficult as the updated version has to be compatible with the old version to a large extent; in particular, its data structures have to have exactly the same binary layout. A few distributions offer this service for security updates. These features are not (yet?) available in the mainline Linux kernel. On a mainline Linux kernel, a driver can be updated only if it’s loaded as a module and if the module can be unloaded and the new module is compatible with the running kernel.

I’d like to add to Gilles’ answer in stating that unlike in Windows where the drivers are unloaded and loaded upon installation in most cases, in Linux installation of drivers mainly consists of adding the binaries and configuration to the filesystem and setting them as the latest version.

This means that unlike in Windows that tells you to reboot since you’re system is in an unstable/unknown state, in Linux most often you’re just in the same state you were before installing the driver.

In addition, adding “new” drivers in Linux consists of loading the kernel modules, so when adding a new driver there’s no need for reboots usually. In Windows most devices are handled by a generic driver, so a driver is unloaded when adding new devices as well.

Lastly, the kernel has no “reboot needed” flag, so the suggestion to reboot is dependent on the developer of the driver helper utility, which means that there may well be cases when you should have rebooted, you just didn’t get an indication that you should.

Answered By: Didi Kohen
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.