top of page
Search
eliseloukota885j61

Managing devices in Linux: Learn from real-world examples and case studies



In this webinar we investigate the why and how of managing peripheral devices in an Arm-based embedded Linux system. Although this is a huge and complex subject area, we can still introduce some of the key concepts and start to appreciate the steps involved in writing a device driver.


If you're a newly aspiring Linux practitioner, you may be looking to gain some deeper knowledge of how Linux devices are managed within the larger Linux ecosystem. In particular, you may be looking to add or manage Linux devices and have found the process to be quite different from other operating systems such as Windows. The reason for this difference, and a major foundational aspect of Linux, comes down to the fact that everything in Linux is a file.




Managing devices in Linux



As mentioned above, one of the major differences between a Linux-based operating system and a Windows-based operating system is the fact that everything in a Linux operating system is constructed of files. Yes, when we say everything, we mean everything. From the Master Boot Record to Linux devices, everything in a Linux operating system is a file.


In the following sections, we'll investigate how Linux devices are managed within a Linux environment, dig into some of the foundational differences between a Linux-based file system and a Windows-based environment and provide a bit of a pros-and-cons list to becoming acquainted with Linux. Let's jump in.


Without digging into the weeds and addressing all of the various device file types in Linux (because there are a lot of them) let's focus on the more common Linux device files that you may come across. In particular, you'll find two common Linux device files in the /dev folder: Character devices and block devices. These device file types are defined by how data is transmitted. Let's take a look at character devices and block devices to better understand the differences and understand what types of devices utilize each device file type.


As noted, character devices are defined by how the device in question transmits data. Specifically, in this case, character devices transmit data character by character or in series. Common character devices include the mouse, keyboards, serial ports, and sound cards.


A Block device, on the other hand, is a device that transmits information by sending blocks of data rather than sending single characters in a serial fashion. Common block devices include hard drives and USB devices.


Another common device file is the sd'x' file. Sd files represent mass storage devices such as hard drives and USB drives. In short, the sd file simply denotes devices that have been detected by the computer. However, it's important to note that the following alphanumeric character that follows the sd file represents how the mass storage device was identified. In particular, sda represents a mass storage device that was detected by the Linux system before sdb and so on. So next time you see a variety of device files starting with sd, you'll know that these are simply mass storage devices detected by your Linux machine.


In comparison to SATA-based mass storage devices, PATA-based drives are going to follow a similar convention, however, in the device directory, you'll see hd'x' where x indicates the order of how the Linux system identified PATA-based drives were connected to the machine.


Another important attribute of the Linux /dev directory is how storage devices are partitioned. If you see a device file defined as dev/sda1 or dev/sda2 this simply indicates the different partitions that are available on that SATA storage device. In this scenario, dev/sd1 would denote a primary partition, whereas, dev/sda2 would denote a secondary partition on the drive. Likewise, with PATA-based storage, dev/hda1 and dev/hda2 denote partitions on the


Let's conclude with a few commands to steer away from. It's our guess that if you're looking to get more familiarized with Linux devices, you also want to keep your Linux environment in safe, good working order. So as you explore the /dev directory remember that some commands can pose some serious problems, like overwriting the hard drive with junk. This one's obviously important.


As you move forward to gain a deeper understanding of Linux devices, be sure to leverage all of the resources available at CBT Nuggets to ensure you are honing those skills as a top-notch Linux practitioner. And hopefully, by simply scraping the surface of what's available in the world of Linux, you'll have a new founded appreciation for how Linux environments are configured and the importance of Linux device files.


Device files are also known as device special files. Device files are employed to provide the operating system and users an interface to the devices that they represent. All Linux device files are located in the /dev directory, which is an integral part of the root (/) filesystem because these device files must be available to the operating system during the boot process.


Device files can be classified in at least two ways. The first and most commonly used classification is that of the data stream commonly associated with the device. For example, tty (teletype) and serial devices are considered to be character based because the data stream is transferred and handled one character or byte at a time. Block type devices such as hard drives transfer data in blocks, typically a multiple of 256 bytes.


If you have not already, go ahead and as a non-root user in a terminal session, change the present working directory (PWD) to /dev and display a long listing. This shows a list of device files with their file permissions and their major and minor identification numbers. For example, the following device files are just a few of the ones in the /dev/directory on my Fedora 24 workstation. They represent disk and tty type devices. Notice the leftmost character of each line in the output. The ones that have a "b" are block type devices and the ones that begin with "c" are character devices.


The more detailed and explicit way to identify device files is using the device major and minor numbers. The disk devices have a major number of 8 which designates them as SCSI block devices. Note that all PATA and SATA hard drives have been managed by the SCSI subsystem because the old ATA subsystem was many years ago deemed as not maintainable due to the poor quality of its code. As a result, hard drives that would previously have been designated as "hd[a-z]" are now referred to as "sd[a-z]".


The Linux Allocated Devices file at Kernel.org is the official registry of device types and major and minor number allocations. It can help you understand the major/minor numbers for all currently defined devices.


There will be a large number of tty devices defined but we do not care about most of them, just the tty2 and tty3 devices. As device files, there is nothing special about them; they are simply character type devices. We will use these devices for this experiment. The tty2 device is attached to virtual console 2 and the tty3 device is attached to virtual console 3.


This experiment can also be performed with terminal emulators on the GUI desktop. Terminal sessions on the desktop use pseudo terminal devices in the /dev tree, such as /dev/pts/1. Open two terminal sessions using Konsole or Xterm. Determine which pseudo-terminals they are connected to and use one to send a message to the other.


CentOS and RHEL 6 and 7, as well as all versions of Fedora going back to at least as far Fedora 15, use the newer method of creating the device files. All device files are created at boot time. This functionality is possible because the udev device manager detects addition and removal of devices as they occur. This allows for true dynamic plug-n-play functionality while the host is up and running. It also performs the same task at boot time by detecting all devices installed on the system very early in the boot process. Linux.com has a good description of udev.


Now that you have covered files and devices, I would welcome a discussion of the "device dance" that happens when one connect a storage device -- eg. thumb drive, external drive, media card, etc -- to a workstation. I presume that there is a similar "device dance" when other devices get connected -- eg. pointing devices, cameras, audio players, network adapters, etc.


"Device dance" is a good way to put it. I have Kubuntu 15.10 and while flash/thumb drives attach reasonably well, Android devices/phones and cameras use MTP protocol that can take several plug/unplug tries before I can r/w files.


You can control which laptops, desktops, and other endpoints can access your organization's data and get details about those devices. You can block devices, sign out users remotely, and use Context Aware Access.


Udev depends on the sysfs file system which was introduced in the 2.5 kernel. It is sysfs which makes devices visible in user space. When a device is added or removed, kernel events are produced which will notify Udev in user space.


In the older kernels, the /dev directory contained statics device files. But with dynamic device creation, device nodes for only those devices which are actually present in the system are created. Let us see the disadvantages of the static /dev directory, which led to the development of Udev.


In the static model of device node creation, no method was available to identify the hardware devices actually present in the system. So, device nodes were created for all the devices that Linux was known to support at the time. The huge mess of device nodes in /dev made it difficult to identify the devices actually present in the system.


The number of static device nodes to be included increased a lot in recent times and the 8-bit scheme, that was used, proved to be insufficient for handling all the devices. As a result the major/minor number pairs started running out.


This might seem like a joke, but for a long time, doing nothing was thedominant strategy for Linux device management. IT teams basically trustedthat Linux users were technically sophisticated enough to protect their owndevices, and allowed them to work without oversight or observation. 2ff7e9595c


0 views0 comments

Recent Posts

See All

Comments

Couldn’t Load Comments
It looks like there was a technical problem. Try reconnecting or refreshing the page.
bottom of page