Linux: How the Kernel Interacts with Hardware
Linux provides various tools for reporting and examining the operations of the CPU, RAM, storage and networking. This article demonstrates how many of these utilities work.
May 1st, 2024 2:00pm by
AI-generated image by Sunny Daye from Pixabay.
This is the third part in a ten-part series on understanding the Linux operating environment, by Damon Garn. See also “Linux: Understand the Linux Command Line.”
When understanding the structure of a computer system, it helps to think of it as containing four major subsystems. These subsystems are interrelated and impact each other, but begin by thinking of them as separate components.
The four subsystems are:
- Central Processing Unit (CPU): The processor is responsible for running code.
- Random Access Memory (RAM): The memory temporarily stores data and allows for quick retrieval. It is closely associated with the CPU.
- Storage: Solid-state and hard disk drives store data even when the system is off. Storage capacity impacts system performance and capabilities.
- Network: Provides network connectivity, allowing the exchange of files or other communications.
Display CPU and Memory Information
The CPU and memory are described above as separate subsystems, but they are closely related. This section covers displaying information about both. Linux inventories the available hardware during the boot process. Some hardware information is stored in the /proc directory, which is dynamically populated each time the system starts. This directory contains two files related to the processor and memory.- /proc/cpuinfo : Provides information the system detected about the processor during the startup procedure.
- /proc/meminfo : Provides information the system detected about the memory during the startup procedure.
$ cat /proc/cpuinfo
Output from the cat /proc/cpuinfo command.
$ cat /proc/meminfo
Partial output from the cat /proc/meminfo command.
Memory Utilities
Two standard information-gathering tools for memory utilization are free and vmstat. These tools provide basic information on how much system memory is recognized and how it is being used. The free command displays how much RAM is currently unused on the system and therefore available for additional applications or services.
The free command displays memory totals and utilization information.
The vmstat command displays virtual memory use.
Use the uname Command
A quick command that displays basic CPU information is uname. It has several options that modify its output. Use the -a option to show all processor and operating system details.
The uname command displays some hardware and Linux kernel information.
Display Storage Information
Hard disk drives (HDDs) or solid-state drives (SSDs) usually provide computer storage. These devices enable long-term file storage. Reviewing storage information on the system allows you to anticipate capacity problems and possibly increase performance. Most people think of capacity as the primary storage attribute. Today’s storage disks tend to be very large, often larger than end-users need. Data should be stored on network servers in most business environments. However, it’s worthwhile to check storage capacity to ensure the system has plenty of space to work with, especially for servers. Storage disks impact system performance. System, service, and user files are stored on the drives. The longer it takes to read and write these files, the slower the system becomes.Understand Partitions
Storage disks are divided into partitions. Partitions are logical storage units often assigned for specific types of data. Display partition information by using the same cat command you used above for CPU and memory data. The argument is /proc/partitions . $ cat /proc/partitions
Note the sda details in the screenshot.
The lsblk command reports information on storage disk sda, showing two partitions.
Display Capacity Information
The /proc/partitions file and lsblk output show the storage structure, but you typically use the df and du commands to learn more about capacity and utilization. The disk utilization (du ) command is useful for understanding how much space specific directories or files consume. For example, if you have a folder full of pictures, you might use the du command to determine how much of your storage drive the folder uses. The du command estimates this consumption by adding the sizes of all selected directories and files. You’ll almost always use the -h option to display sizes in human-readable formats, such as KB, MB, GB, etc. Try using du to check how much capacity log files consume on your Linux device. Linux stores log files in the /var/log directory.
$ du -h /var/log
The du command displays per-directory and per-file disk utilization.
Use the -s option with the du command to display a summary of the storage information.
Display capacity information for the sda device.
Display Network Information
Network connectivity is critical to most Linux devices. Wired and wireless network interface cards (NICs) attach the system to other network nodes, enabling email, web browsing, printing, file sharing, and more. One of the most common network information-gathering and troubleshooting tools is the ip command. This command includes numerous subcommands that modify its function. For example, use the ip addr command to display basic network settings:
$ ip addr show enp0s5
Partial output from the ip addr command showing information for the enp0s5 interface.
Use the ethtool Utility
The basic ethtool command displays the current hardware settings for the specified network card (enp0s5 ).
$ ethtool enp0s5
The ethtool command displays network interface card information.
$ ethtool -i enp0s5
The ethtool -i command displays network card device driver details.
$ ethtool --identify enp0s5 5
Use Monitoring Tools
The tools above display specific information about individual system components. However, tools like top, htop, and Glances provide a broader view of hardware. The utilities in this section show performance information in real-time and help you analyze how the hardware is used.Use the top Utility
The standard Linux hardware monitoring tool is top. It displays basic hardware information in the upper frame, with a dynamic table of system processes and their CPU and memory consumption in the lower portion.
The upper portion of the top command displays hardware details and utilization, such as free memory and processor time.
The section beneath the hardware summary shows running processes with their CPU and memory consumption (partial screenshot).
Use the htop Utility
A more dynamic utilization tool is htop. Not all Linux distributions install it by default, so you may need to add it to your system. The htop tool is a real-time monitor with a more robust dashboard that includes color coding and dynamic elements. This is more of a monitoring tool than a way of gathering system hardware information, but it provides insights into how the hardware behaves and whether the system has sufficient resources for its workload.Use the Glances Utility
The Glances hardware monitor is not installed on all Linux distributions by default, but it’s easy enough to add to the system. Glances offers real-time monitoring of system resources using an easy-to-read dashboard. Glances is great for Linux users with more than one system because it includes a web mode that allows remote connectivity to monitor multiple devices. Glances is open source and written in Python so it can be run on Linux, macOS, and Windows systems, making it an even more compelling information-gathering tool.Wrap Up
Recall that a computer system consists of several subsystems. These include processing capabilities, storage, and networking. System administration includes displaying hardware information and using it to manage services, processes, applications, and more. Linux users will want to see hardware information to help select system upgrades, monitor performance, and troubleshoot issues. Many resources, like /proc/cpuinfo and /proc/meminfo , provide static information. Others, such as top and Glances, offer a dynamic view of real-time processor, memory, storage, and network hardware resources. You’ll often find yourself using multiple tools to ensure you understand the system specifications.
YOUTUBE.COM/THENEWSTACK
Tech moves fast, don't miss an episode. Subscribe to our YouTube
channel to stream all our podcasts, interviews, demos, and more.